16.Java Tips
Friday, January 22, 2010
Hello dear reader!
“Java Tips” is my collection of tricky questions and answers from my experience for last four years I have to my students in my classes.
Let me ask you a few questions.
1. Are you preparing for Java certification exam and want to be sure that you will pass it for first attempt? This section gives you real examples how to use Java.
2. Are you looking for a job as a java programmer and want to be prepared for the java interview questions?
3. Are you looking for a good design idea?
You have come to right place!
This section of the blog gives you more knowledge, better perspective to programming and computer science especially.It covers wide range of questions.
Okay, let’s get started!
1.Is JavaScript the same as Java?
Answer: NO! An Amazingly large number of people, including many web designers, don't understand the difference between Java and JavaScript. Briefly it can be summed up as follows:
Java was developed by Sun Microsystems. Java is a full-fledged object-oriented programming language. It can be used to create standalone applications and applet. Applets are downloaded as separate files to your browser alongside an HTML document, and provide an infinite variety of added functionality to the Web site you are visiting. The displayed results of applets can appear to be embedded in an HTML page (e.g., the scrolling banner message that is so common on Java enhanced sites), but the Java code arrives as a separate file.
JavaScript on the other hand was developed by Netscape, is a smaller and simpler scripting language that does not create applets or standalone applications. In its most common form today, JavaScript resides inside HTML documents, and can provide levels of interactivity far beyond typically flat HTML pages -- without the need for server-based CGI (Common Gateway Interface) programs.
2. Is Java open source as distributed by Sun, i.e., all the modules including JVMs? If not, is anyone else doing an open source implementation?
Answer: Java is not open source project. Though you can get the full source code under a Sun license.
http://kaffe.org does open source implementation.
I read there: "Kaffe is a cleanroom, open source implementation of a Java virtual machine and class libraries. It is also a fun project that was started by Tim Wilkinson and was made successful by the contributions of numerous people from all over the world.
But Kaffe is not finished yet! You can help by developing new and missing functionality, porting Kaffe to new platforms, and testing your Java applications under Kaffe.
Kaffe mostly complies with JDK 1.1, except for a few missing parts.Parts of it are already JDK 1.2 (Java 2) compatible."
http://gcc.gnu.org/java/ - The GNU Compiler for the Java Programming Language
3. Why JVM is called virtual machine?
Answer: JVM is called a virtual machine because there is no real hardware which interprets the byte code. If you have done any assembly programming for any microprocessor/micro controller you will able to understand this. A microprocessor has built-in instruction set to interpret the assembly code. Similarly the JVM is similar to a microprocessor in the sense it has its own instruction set but it implemented in software. That is why it is called a virtual machine!
4. Do anyone know the difference between java and C#.
C# byte codes can be compiled to native exe files just as Java byte codes can be. But C# is expected to be more closely tied to the Windows operating system and standard interfaces that are part and parcel of Windows. Writing a native compiler that collects all these interfaces and combines them into a unified whole that can run on ANY operating system may require compiling proprietary windows components which Microsoft will make sure is hard to do and against its licensing policies. So you can expect to see native compilers that compile for Windows platforms but not to other operating systems.
5. Why C++ is not platform independent?
Answer: C++ compiles to binary code (.obj, .exe, .dll, a.out etc.). Binary code (Machine code,
0's and 1's) are machine dependent. Java compiles to byte code which is independent of any machine. It need to be interpreted to binary code by JVM, and executed by the machine
6. Why people claim that java is a secure language...
Answer: The java programming language itself is just as secure or insecure as any other
programming language. A Java Applet (which are used on the web) is a different matter. They
are quite secure.
An applet does not have access to system resources outside of the directory that it is created
in. There are ways that you can give an applet access to this information, but they are pretty
explicit and you will most likely know that the applet is trying to do this.
I am not really familiar with the subject but did a little reading on the sun website. Check it out
for more info:http://developer.java.sun.com/developer/technicalArticles/Security/
You aren't supposed to be able to break the rules easily at run time. The elimination of pointer
arithmetic is supposed to improve type safety.
7. What is the difference between Java and Microsoft Visual J++? Is there any specific
difference?
Answer: VJ++ was designed as a "spoiler" product -- Microsoft created some deliberate subtle
incompatibilities so that when people wrote VJ++ code it would only run on Windows. This is
not my opinion. This came out in evidence in Microsoft’s trial for anti-competitive behavior.
In email they said things like they were going to "pollute" Java, and "piss on" the Swing
libraries.
Some of the incompatibilities were in removing some standard fields from the system libraries.
Others were adding some fields. They also added some differences to the language itself, in
the way event handlers were registered.
When Sun found out about Microsoft's attempt at sabotage, they cut-off all code deliveries to
Microsoft, and sued Microsoft. That lawsuit just ended with the payment of $20M by Microsoft
to Sun.
So Microsoft VJ++ is several releases out of date, and does not have many of the most
important libraries, such as RMI and beans.
Bottom line: even though it has a nice GUI IDE, if you want to program in Java, you are better
off avoiding VJ++, and using any of the free IDEs.
8. What is the difference between java and java2?
Answer: Java2 is really just another name for JRE/JDK1.5 and higher. Various things improved
dramatically between JDK1.1 and JDK1.5, mainly in the libraries - things like the collection
classes suddenly appeared.
The extensions mechanism was also introduced, and I suspect the security policy was firmed
up (I've never needed to investigate that, fortunately).
9.What are the differences between the SDK, JDK and IDE products?
Answer: IDE is an acronym for _I_ntegrated _D_evelopment _E_nvironment. These products are the one stop shops for coding, running and debugging your code. Often these will include
GUI based drag and drop form designers and "wizards" for the shells of common forms of code
(Application, Applet, etc.) JBuilder is an IDE.
The IDE may stand on its own, or it may act as a front end for a JDK.
JDK is _J_ava _D_esign _K_it. A JDK is a command line based interface to the JVM, plus the
classes. You are responsible for your own editors, creating code for GUI elements, and all
code. All of the IDE's I have reviewed personally come with JDK or their own vendor's
equivalent (JVM and class libraries). Some IDE's are capable of a
sort of "upgrading" by downloading the latest JDK from Sun (JBuilder for example).
10. == and equals ()... These two still make me confuse a lot of time.?
Answer: When you use == with a primitive -int, double, char, ... you are checking that the
values are identical. But if you use == with an object, you are checking that the 2 objects are
stored at the same address. In other words the references pointing to the same object...
Method equals () is different.
It is the same as ==, if it isn't overriden by the object class.
Many classes override the method equals (). In this case this method will check that content of
the object is the same or not, not addresses.
That's all for this time folks!!!, Next time I will be back with some more interesting topics.
“Java Tips” is my collection of tricky questions and answers from my experience for last four years I have to my students in my classes.
Let me ask you a few questions.
1. Are you preparing for Java certification exam and want to be sure that you will pass it for first attempt? This section gives you real examples how to use Java.
2. Are you looking for a job as a java programmer and want to be prepared for the java interview questions?
3. Are you looking for a good design idea?
You have come to right place!
This section of the blog gives you more knowledge, better perspective to programming and computer science especially.It covers wide range of questions.
Okay, let’s get started!
1.Is JavaScript the same as Java?
Answer: NO! An Amazingly large number of people, including many web designers, don't understand the difference between Java and JavaScript. Briefly it can be summed up as follows:
Java was developed by Sun Microsystems. Java is a full-fledged object-oriented programming language. It can be used to create standalone applications and applet. Applets are downloaded as separate files to your browser alongside an HTML document, and provide an infinite variety of added functionality to the Web site you are visiting. The displayed results of applets can appear to be embedded in an HTML page (e.g., the scrolling banner message that is so common on Java enhanced sites), but the Java code arrives as a separate file.
JavaScript on the other hand was developed by Netscape, is a smaller and simpler scripting language that does not create applets or standalone applications. In its most common form today, JavaScript resides inside HTML documents, and can provide levels of interactivity far beyond typically flat HTML pages -- without the need for server-based CGI (Common Gateway Interface) programs.
2. Is Java open source as distributed by Sun, i.e., all the modules including JVMs? If not, is anyone else doing an open source implementation?
Answer: Java is not open source project. Though you can get the full source code under a Sun license.
http://kaffe.org does open source implementation.
I read there: "Kaffe is a cleanroom, open source implementation of a Java virtual machine and class libraries. It is also a fun project that was started by Tim Wilkinson and was made successful by the contributions of numerous people from all over the world.
But Kaffe is not finished yet! You can help by developing new and missing functionality, porting Kaffe to new platforms, and testing your Java applications under Kaffe.
Kaffe mostly complies with JDK 1.1, except for a few missing parts.Parts of it are already JDK 1.2 (Java 2) compatible."
http://gcc.gnu.org/java/ - The GNU Compiler for the Java Programming Language
3. Why JVM is called virtual machine?
Answer: JVM is called a virtual machine because there is no real hardware which interprets the byte code. If you have done any assembly programming for any microprocessor/micro controller you will able to understand this. A microprocessor has built-in instruction set to interpret the assembly code. Similarly the JVM is similar to a microprocessor in the sense it has its own instruction set but it implemented in software. That is why it is called a virtual machine!
4. Do anyone know the difference between java and C#.
C# byte codes can be compiled to native exe files just as Java byte codes can be. But C# is expected to be more closely tied to the Windows operating system and standard interfaces that are part and parcel of Windows. Writing a native compiler that collects all these interfaces and combines them into a unified whole that can run on ANY operating system may require compiling proprietary windows components which Microsoft will make sure is hard to do and against its licensing policies. So you can expect to see native compilers that compile for Windows platforms but not to other operating systems.
5. Why C++ is not platform independent?
Answer: C++ compiles to binary code (.obj, .exe, .dll, a.out etc.). Binary code (Machine code,
0's and 1's) are machine dependent. Java compiles to byte code which is independent of any machine. It need to be interpreted to binary code by JVM, and executed by the machine
6. Why people claim that java is a secure language...
Answer: The java programming language itself is just as secure or insecure as any other
programming language. A Java Applet (which are used on the web) is a different matter. They
are quite secure.
An applet does not have access to system resources outside of the directory that it is created
in. There are ways that you can give an applet access to this information, but they are pretty
explicit and you will most likely know that the applet is trying to do this.
I am not really familiar with the subject but did a little reading on the sun website. Check it out
for more info:http://developer.java.sun.com/developer/technicalArticles/Security/
You aren't supposed to be able to break the rules easily at run time. The elimination of pointer
arithmetic is supposed to improve type safety.
7. What is the difference between Java and Microsoft Visual J++? Is there any specific
difference?
Answer: VJ++ was designed as a "spoiler" product -- Microsoft created some deliberate subtle
incompatibilities so that when people wrote VJ++ code it would only run on Windows. This is
not my opinion. This came out in evidence in Microsoft’s trial for anti-competitive behavior.
In email they said things like they were going to "pollute" Java, and "piss on" the Swing
libraries.
Some of the incompatibilities were in removing some standard fields from the system libraries.
Others were adding some fields. They also added some differences to the language itself, in
the way event handlers were registered.
When Sun found out about Microsoft's attempt at sabotage, they cut-off all code deliveries to
Microsoft, and sued Microsoft. That lawsuit just ended with the payment of $20M by Microsoft
to Sun.
So Microsoft VJ++ is several releases out of date, and does not have many of the most
important libraries, such as RMI and beans.
Bottom line: even though it has a nice GUI IDE, if you want to program in Java, you are better
off avoiding VJ++, and using any of the free IDEs.
8. What is the difference between java and java2?
Answer: Java2 is really just another name for JRE/JDK1.5 and higher. Various things improved
dramatically between JDK1.1 and JDK1.5, mainly in the libraries - things like the collection
classes suddenly appeared.
The extensions mechanism was also introduced, and I suspect the security policy was firmed
up (I've never needed to investigate that, fortunately).
9.What are the differences between the SDK, JDK and IDE products?
Answer: IDE is an acronym for _I_ntegrated _D_evelopment _E_nvironment. These products are the one stop shops for coding, running and debugging your code. Often these will include
GUI based drag and drop form designers and "wizards" for the shells of common forms of code
(Application, Applet, etc.) JBuilder is an IDE.
The IDE may stand on its own, or it may act as a front end for a JDK.
JDK is _J_ava _D_esign _K_it. A JDK is a command line based interface to the JVM, plus the
classes. You are responsible for your own editors, creating code for GUI elements, and all
code. All of the IDE's I have reviewed personally come with JDK or their own vendor's
equivalent (JVM and class libraries). Some IDE's are capable of a
sort of "upgrading" by downloading the latest JDK from Sun (JBuilder for example).
10. == and equals ()... These two still make me confuse a lot of time.?
Answer: When you use == with a primitive -int, double, char, ... you are checking that the
values are identical. But if you use == with an object, you are checking that the 2 objects are
stored at the same address. In other words the references pointing to the same object...
Method equals () is different.
It is the same as ==, if it isn't overriden by the object class.
Many classes override the method equals (). In this case this method will check that content of
the object is the same or not, not addresses.
That's all for this time folks!!!, Next time I will be back with some more interesting topics.
Labels:
Java Tips