Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a query in which I cannot give a satisfactory answer. Java is notorious for its independence over machine architectures grace to JVM. I 've understood the following:
Different JVM implementations are sitting on different machines as to produce the appropriate output (different for any different architecture) from the same input(.class files).
Let's now consider C++. Why not to do the same with Java? Namely, implement different C++ compiler versions for different architectures, feed them with the same source and make every compiler produce the appropriate output; just make C++ compiler to mimic JVM!
This is my query since I cannot understand why Java is unique in that...
The C++ compiler already does that. The difference is that whereas class files are interpreted by the JVM, C++ applications aren't (usually) distributed as source files.
This of course also requires that you use standard libraries which are available for all the platforms. There's nothing very magical here. You have compiled languages such as C++, partially compiled like Java and interpreted such as Ruby.
As far as I know this is exactly what happens (as Kayaman said). You write one source, and compile it for different platforms, for example gcc/mingw or visual for Windows, gcc for Linux etc.
The difference between C/C++ and Java is that from C and C++ it is much easier to do direct system calls, to directly work with the filesystem, with sound devices etc. These system calls will differ for each system, which is what makes the code not portable. This means that portability for C++ code is the choice of the programmer.
Because if you do that you have Java. If C++ doesn't have a direct connection with the low level resources than lots of advantages of this language disappear. It's kind of the same thing with C++ and assembling language. Creating a more high-level language will have a negative effect on the control of the machine's resources.
Read this about Java: Java Architecture
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 months ago.
Improve this question
Java is often cited as being more portable than other, say compiled, languages as the executable can be run on any platform with a JVM. But code written in C can be run on any platform with a C compiler.
So, naively, there are two alternatives: make lots of different compilers for lots of different platforms and transfer source code over a network for say an applet, which is compiled client-side; or make lots of different virtual machines to run on lots of different platforms and transfer the same, executable program or applets over networks.
Why is the latter better? I can see how server-side compilation is desirable, but I feel there is more to it than this. I can appreciate that it was less work for Sun Microsystems to create JVMs for many platforms than compilers for many platforms, but this surely wasn't the major motivation.
But code written in C can be run on any platform with a C compiler.
Not in the same way. You either need to compile it on that machine with that specific compiler, or need a compiler that is capable of cross-compiling. Either way, you have a bigger workload.
Still, there is some C Code that is quite portable. A simple program that just calculates basic arithmetic is quite portable, even in C, if you are willing to compile it to different platforms.
The second big important difference is the platform. As soon as you do I/O or use syscalls, your code becomes platform-specific, just because you need to directly interface with the host system. An interpreted language offers a unified platform. If my programs runs on the JVM, it just runs on it, no matter which system is host to the JVM. If I use "native" calls to the host OS, I have to use the proper ones for each OS - but with Java, my "OS" is the JVM.
Btw, there is so called "portable" C/C++ code, but it also hinges on similar concepts as the JVM. If you use Qt and similar libraries that offer uniform APIs on multiple platforms, then you can create quite portable C/C++ programs.
The perhaps most authoritative answer to why Java was designed to be interpreted may be found in the whitepaper that announced the Java language back in 1995:
1.2.3 Architecture Neutral and Portable
Java technology is designed to support applications that will be deployed into heterogeneous network environments. In such environments, applications must be capable of executing on a variety of hardware architectures. Within this variety of hardware platforms, applications must execute atop a variety of operating systems and interoperate with multiple programming language interfaces. To accommodate the diversity of operating environments, the Java Compiler TM product generates bytecodes--an architecture neutral intermediate format designed to transport code efficiently to multiple hardware and software platforms. The interpreted nature of Java technology solves both the binary distribution problem and the version problem; the same Java programming language byte codes will run on any platform.
Architecture neutrality is just one part of a truly portable system. Java technology takes portability a stage further by being strict in its definition of the basic language. Java technology puts a stake in the ground and specifies the sizes of its basic data types and the behavior of its arithmetic operators. Your programs are the same on every platform--there are no data type incompatibilities across hardware and software architectures.
and
1.2.5 Interpreted, Threaded, and Dynamic
The Java interpreter can execute Java bytecodes directly on any machine to which the interpreter and run-time system have been ported. In an interpreted platform such as Java technology-based system, the link phase of a program is simple, incremental, and lightweight. You benefit from much faster development cycles--prototyping, experimentation, and rapid development are the normal case, versus the traditional heavyweight compile, link, and test cycles.
It is also worth mentioning that the Java API goes far beyond standard libraries for C or C++.
Note that this perspective is somewhat dated. While largely still accurate, a modern take on the trade-off between a priori and runtime compilation whould include the additional optimization oppurtunities afforded by execution time statistics, and probably avoid the use of the word "interpreted" altogether - at least if we are somewhat serious about performance.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
During 3 years of my working career, I have been working with databases, data, etc. It was only during the last year that I started working with Python for some data analysis. Now i got interested in all the Big Data ecosystem and Python gets me far enough, yet.
However, recently I chose to learn Scala as my second programming language. It appears that usually my program needs to have a class, a method, and then it needs to be built. It is all very confusing to be honest :)
So I read on and it appears that Scala comes from JVM environment, and I started reading on Java and it turns out that in Java you cannot just create a program consisting of a single command. You need to create a class, a method, etc. I understand that it is probably because it follows one of the principles of OOP, but could anyone please direct me to the source, which would explain why do we need to create classes and methods in java - as opposed to listing commands only?
So I read on and it appears that Scala comes from JVM environment, and I started reading on Java and it turns out that in Java you cannot just create a program consisting of a single command. You need to create a class, a method, etc. I understand that it is probably because it follows one of the principles of OOP
First, let me briefly explain why Python does not requires you to create a class or something similar in order to run it.
Python is designed as an interpreted language (or you can call it script). The instructions you wrote are series of operating system commands handled by the command interpreter. So what is a command interpreter?
Command interpreter is part of the OS which executes commands entered by you. In some OS, it is known as a shell.
Java on the other hand is a designed as a compiled language which needs to be compiled by a language compiler. The language compiler converts your source codes into machine language so that you processor can work on it.
In my opinion, it is not really about OOP in Java. It is what they are which made the difference - to be compiled vs to be interpreted.
If you are just wondering why Java codes need a class, it has been asked before in SO:
Why do C# and Java require everything to be in a class?
Scala is made because of this. It mixes functional and OOP language features, so you can create methods by themselves, without creating a class to contain them.
Java doesn't have this feature, methods can't be created outside a class. Java is very object oriented, everything (except the primitives) extends object.
Some people say, that this is like this, because java is garbage collected. Having functions inside objects makes it easier, to free space up.
It really depends on you, if you find this good or not. In my opinion, it's better to get as far from functional programming, as possible. Let's not get back to the C era.
Java is an object-oriented (OO) language. Classes are objects, one of the basic building blocks of this language. Inside the classes, you have methods, containing the "commands" you are speaking of.
I suggest you refer to literature on that topic - there is a vast amount of books outlining OO principles and the differences between different types of languages (OO, functional, procedural, etc.).
All in all, wikipedia might be a good starting point - see the list of main paradigm approaches here:
https://en.wikipedia.org/wiki/Comparison_of_programming_paradigms#Main_paradigm_approaches
P.S.: As I'm unsure what exactly your question is about, I have to add that of course, Python is an OO language too. That you can run Python code without creating a class first, is a design choice.
This question already has answers here:
What are advantages of bytecode over native code? [closed]
(8 answers)
Closed 7 years ago.
As I read is bytecode an intermediate language which is used by a virtual machine which has to be installed on the computer to run the program. Wikipedia says, that a VM either executes the bytecode directly or generates machine code for better performance. The article also says, that bytecode is a set of instructions. For me it sounds like normal machine code, except that only the VM can understand it (Am I right?).
So what is the purpose of bytecode? If a VM can also compile it to machine code why can't the compiler do it directly and we don't need the VM and have better performance?
This may not be the best place for this question, but it depends. In the case of Java, portability is king.
Windows applications have the advantage that you can rely on many of the system libraries not being compiled with the program. It also extends portability since the code will not depend on architecture (generally.)
More generally, you can generate byte code compilers that can generate code to the same byte code standard in many languages, providing easy interoperability between modules. (like in. NET a c# library can be referenced in a VB project)
There is certainly a much more in depth explanation, but generally these are the advantages.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 months ago.
Improve this question
I was invited to interview for Pure Java Developer
Please help me to understand what is Pure Java.
Can't find any information about it.
Pure Java code is code that "conforms to Java's ideal of universal portability"
It means code that does not rely on native features.
An aspect of Java is to be portable across different operating systems (write once, run anywhere). Writing code that can only be used on specific operating systems contradicts this.
Simply by googling "Pure Java", you can find resources on it, such as PDFs and other articles.
What does "pure Java" mean?
Well, you would need to ask the person who used the phrase1 to know what they meant. But when a seasoned Java professional hears the phrase, they are likely to think it refers to "100% Pure Java".
"100% Pure Java" was a pre-2000 Sun Microsystems initiative to promote the writing of portable Java code. There is even a "100% Pure Java Cookbook" that says how to do it.
What does the "100% pure" mean?
The Cookbook says it like this:
The 100% Pure Java™ Standard
The "100% Pure Java™ Standard" is part of Sun Microsystems initiative
to promote the development of portable applications, applets2, beans,
class libraries, and servlets written using the Java™ Programming
language. Compliance to the standard consists of code analysis and
testing the program on multiple Java Application Environments.
Basically, 100% pure Java is about portability. It means avoiding things like:
using native code libraries,
using external applications,
making platform and operating system specific assumptions; e.g. that "\n" is the line separator or "/" is the pathname separator,
and so on.
This does NOT mean "uses only Java SE or Java EE APIs", although:
using Java platform vendor's extensions to the standard APIs, or
using new platform features such as Java 8 streams, etc
both arguably work against Java platform independence. And Java has dropped certain features in more recent releases, which also affects portability and platform independence. (Try running an applet on a modern JVM ...)
1 - Lots of people are happy to borrow someone else's terminology and give a new meaning to it, then state their new meaning as the real meaning. In this case, my guess is that the person who invited you to the interview is a recruiter or manager who has minimal technical understanding. They may be saying "pure Java" because they think it will make the job more attractive to the right kind of prospects. Or maybe they are confusing "pure Java" with "core Java". Who knows ...
2- Ahem ... dead technology.
I would consider 'Pure Java' to be Core Java. The Classes, Interfaces and APIs that are referenced as part of the Javadoc for that particular JDK.
E.g. Oracle JDK 8 - https://docs.oracle.com/javase/8/docs/api/
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
What is the difference between Java and C++? Are both object-oriented?
This is far too general a question to be answered here.
Java is an explicitly object-oriented language, with the harder-to-use bits snipped off.
C++ is a multi-paradigm language with the safety off. You can do object-oriented programming in it, as well as procedural and generic.
If you had a more specific question, we could be of more help. Why did you ask? If you want recommendations for a particular platform, or project, or whatever, we could be more responsive.
A C++ programmer will tell you that Java is rubbish. A Java programmer will tell you that C++ is rubbish. Therefore I conclude that they are indeed the same thing.
Each language designed with different purposes in mind, so IMO it's not fair to compare the two from one perspective, and ignore the other.
Generally speaking, C++ is an open standard, designed for implementing high performance systems where speed and performance and critical, there are lots of impressing projects designed using this language like Phoenix Lander, Adobe Acrobat Reader and others. C++ gives the developer the ability to program using a very high level abstraction -using generics for example, and, when needed, go down deep to the bare metal of the machine -to handle an interrupt for instance.
Java was designed with other purposes in mind, when Sun was planning Oak (later called Java), it focused on web applications so it supported the language with a bunch of heavy libraries of easy-to-use interfaces considering that. and portability (Compile once, run anywhere) using JVM, which prevents the programmer from coding to specific machine, but instead coding to a sandbox which in turn runs the code on the hosting machine, and this has obviously negative reflections on performance/speed.
Comparison of those two language is a popular cause of debate between programmers, and this is due to their different working demands and nature, IMO every language has made mistakes in order to mature, for example, C++'s exported templates, and Java's lack of procedural programming (Big Mistake). plus, each one has its pros and cons regarding different aspects, hence the one that balance productivity/performance issue IS the right language.
For more information Wikipedia's comprehensive article on Comparison of Java and C++
It might be interesting to take a look at what languages are used (and being used) to create major systems (like Google) from here.
One of the most important differences hasn't been mentioned yet - one is compiled to machine code, the other is compiled to bytecode which is interpreted by a virtual machine.
Everything is Object in Java as everything is derived from java.lang.Object But this is not the case in C++
No pointers in Java whereas C++ has provide support for pointers
No destructors in java (Java has automatic garbage collection) but C++ has destructors to do that
Thread support is built in Java but not in C++
No scope resolution operator in Java
No Goto statement in Java
No Multiple Inheritance allowed in Java but C++ allows that
No operator overloading is allowed in Java but C++ allows that
Java is interpreted for most part and hence Platform independent
Both are object oriented but they are very different languages. This probably isn't the best forum to ask for the differences... I would suggest you look both up on Wikipedia and review the descriptions there. You will be able to see the differences very quickly for yourself.
I love c++ but unless you absolutely need to use c++ then use something else. When you need to use c++ then you will know the difference, Grasshopper.
(hint do not write device drivers, video decoders, encryption libraries, 3-d graphics engines or language run-time engines in java).
Yes, both are object oriented programming languages.
C++ is an evolution to C. Which was a system programming language. C++ Added many features to the language to make it object oriented. It became the mainstream programming language for that reason.
Java is an evolution of C++, with different goals ( cross platform for instance ). It remove some of the features that make C++ so hard to learn. Simplify others and remove others.
The main difference is C++ programs are compiled directly to machine code ( understood by the CPU ) while Java programs are compiled to be run in a "Virtual Machine" the JVM most of the cases. For these reasons java programs were interpreted by another program and at the beginning were veeeery slow programs. Nowadays the VM may optimize this code and make it run very very fast.
See this link.http://www.javacoffeebreak.com/articles/thinkinginjava/comparingc++andjava.html
Gross but accurate oversimplification: Java is easier. C++ is faster.
Just a quick addition to what David Thornley posted. C++ is a procedural language that supports Objects and OO design. Java is pure OO. Java does less but on more.