Friday, October 12, 2007

Java Faqs - What is the difference between jre and java?

They are functionally equivalent, with minor differences in the handling of default classpath and options supported. To reduce confusion, the jre command was removed in JDK 1.2. Instead there is a "java" command in both bin and jre/bin.jre.exe is the java launcher that comes with the Java Runtime Environment. It ignores the CLASSPATH environment setting in favor of its own internally generated default and whatever is supplied on the cmd line using -cp or -classpath. It's intended to be a bit simpler for those who are only ever running Java programs, not developing them.java.exe is the java launcher that comes with the JDK. It uses the CLASSPATH environment setting as a starting point and then tacks on its own internally generated entries.They both serve the same purpose and that's to start a Java VM, have it run a Java application, then terminate. The source for jre.exe is provided in the JDK. The source to java.exe is provided only in the JDK Source distribution.
By
Shantan Nethikar

Java Faqs - How can I program linked lists if Java doesn't have pointers?

Of all the misconceptions about Java, this is the most egregious. Far from not having pointers, in Java, object-oriented programming is conducted exclusively with pointers. In other words, objects are only ever accessed through pointers, never directly. The pointers are termed "references" and they are automatically dereferenced for you.Java does not have pointer arithmetic or untyped casting. By removing the ability for programmers to create and modify pointers in arbitrary ways, Java makes memory management more reliable, while still allowing dynamic data structures. Also note that Java has NullPointerException, not NullReferenceException.A linked list class in Java might start like this:public class LinkedList {public LinkedList head;public LinkedList next;public Object data;public LinkedList advanceToNext(LinkedList current) { ...}Another choice for a linked list structure is to use the built-in class java.util.Vector which accepts and stores arbitrary amounts of Object data (as a linked list does), and retrieves it by index number on demand (as an array does). It grows automatically as needed to accommodate more elements. Insertion at the front of a Vector is a slow operation compared with insertion in a linked list, but retrieval is fast. Which is more important in the application you have!.
Note: java.util.Vector is thread safety.. so it is slow. If you are not worried about thead safety, it is better to user java.util.List.

By

Shantan Nethikar

99490401096

Java Faqs - Does Java have pointers?

No, no, a thousand times no. Java does not have pointers, no way. Java does have references. A reference is an abstract identifier for an object. It is not a pointer. A reference tags a particular object with a name in the Java virtual machine so that the programmer may refer to it. How exactly the virtual machine implements references at the level of machine code is VM-dependent and completely hidden from the programmer in any case. Most VMs including Sun's use handles, not pointers. A handle is a pointer to a pointer. At the level of machine code in the CPU a reference is an address in memory where the address of the object is stored. This way the objects can be moved around in memory and only the master pointer needs to be updated rather than all references to the object. This is completely hidden from the Java programmer, though. Only the implementer of the virtual machine needs to worry about it. Indeed, this is not the only way references can be implemented. Microsoft's VM actually does use pointers rather than handles. Other schemes are possible.
By
Shantan Nethikar
9949040106

Java Faqs - What is the latest version of JDK? Is Java "Year 2000"-compliant?

Latest version is J2SE™ v1.3, still u can find updated at http://www.javasoft.com/
Java is Y2K compliant in release JDK 1.1.6 and later. See, Prior to this release there were certain corner case bugs that had to be fixed. The Date class, as you can see from the discussion, contains more than enough resolution to represent dates in this century and the next and the last. The SimpleDateFormat when parsing a 2 digit year could cause problems.

By Shantan Nethikar
Java Faqs

Java Faqs - What are the ways to learn Java?

Following steps makes easy to learn java.

1. Start with a java tutorial provided by sun.

2. And get basic book that covers all language fundamental, U can get several java book online too.

3. You can also get a compile from sun site to write and test sample programs.

Thursday, October 11, 2007

Java Faqs - What is Externalizable Interface ?

Answer : Externalizable interface is a subclass of Serializable. Java provides Externalizable interface that gives you more control over what is being serialized and it can produce smaller object footprint. ( You can serialize whatever field values you want to serialize)This interface defines 2 methods: readExternal() and writeExternal() and you have to implement these methods in the class that will be serialized. In these methods you'll have to write code that reads/writes only the values of the attributes you are interested in. Programs that perform serialization and deserialization have to write and read these attributes in the same Reference:

http://www.geocities.com/srcsinc/java/Interview_Questions/

Java Faqs - How do I deserilaize an Object?

Answer : To deserialize an object, perform the following steps:
- Open an input stream -
- Chain it with the ObjectInputStream
- Call the method readObject() and cast the returned object to the class that is being deserialized.
- Close the streams
Java Code
try{
fIn= new FileInputStream("c:\\emp.ser");
in = new ObjectInputStream(fIn);
//de-serializing employee
Employee emp = (Employee) in.readObject();
System.out.println("Deserialized " + emp.fName + " " + emp.lName + " from emp.ser ");

}catch(IOException e){
e.printStackTrace();
}catch(ClassNotFoundException e){
e.printStackTrace(); }