1.1 Evolution of Java

Thursday, August 20, 2009 Posted by Sudarsan
We can use Java to develop network-oriented programs because networking features are inbuilt in Java.

Java is considered ideal for network communication because it is a platform independent language. Java enables an application to be executed on any network. The built-in classes of Java support TCP/IP and UDP protocols used for network communication. Java supports the Client-Server model for network communication.

In 1991, a team of software developers at Sun Microsystems, USA, was designing a language for consumer electronic devices.

The development team headed by James Gosling wanted to design a portable language using which programs should be developed such that they can run on computers with different platform.

The team considered C++ as the model language for designing Java language. The team deprecated various ambiguous features from this new language.

Initially, this developed language was called Oak, but was later renamed to Java.

The following table lists the various developments that took place in the evolution of Java:




Significance of the Java Class File

• The Java class file contains the Java Bytecode.

• The class files are platform independent therefore you can run a Java program by loading the class file on any system with the Java Runtime Environment (JRE).

The following command shows how to view the contents of a class file:

• javap -c

• The javap command prints the instructions that comprise the Java Bytecode, for each of the methods in a class.

Setting the CLASSPATH

• The CLASSPATH environment variable instructs the JVM class loader to find the classes that are directly or indirectly invoked, including the system classes.

• The -classpath option is used when the SDK tools are called, such as java, javac and javadoc.

• The following syntax shows how to set the classpath with an SDK tool:
C:> sdktool -classpath ;...

• The following syntax shows how to set the classpath using the classpath environment variable:

C:> set CLASSPATH=;...

• CLASSPATH is an environment variable that enables the Java compiler javac.exe to locate class files to be imported.

• You can use the SET CLASSPATH= to set the CLASSPATH variable. The following syntax shows how to set CLASSPATH in Java:

SET CLASSPATH= C:\j2sdk1.4.1_02\bin .

Garbage Collection in JVM

Garbage collection is the process that is used to free the memory of the objects that are no longer in use. When a program stops referencing an object, it is not required anymore and can be deleted.

The space that is used by the object is released for use by another object. The garbage collection feature implies that the new objects are created and all the unreferenced objects are deallocated from the memory.

The different approaches used for detecting garbage objects are:

Reference-Counting Collectors: Store the references of the objects used within a program

Tracing Collectors: A set of roots is defined from the location where the objects are traced.

Compacting Collectors: Reduce the fragmentation of memory by moving all the free space to one side during garbage collection.

Best Practices

Declaring class variables as private and methods as public

• You should declare all the class variables as private because data should always remain hidden from the objects of other classes.

• Methods should be declared as public because the methods provide an interface to the objects of the other classes.

Declaring Class Variables

You can follow Hungarian notation to declare variables in Java.

The conventions followed in the Hungarian notation are:

The first letter of the variable should indicate the data type used. You can use the letters, i, f, and b to indicate an integer, float, or a boolean variable. For example, iAge, fPrice, and bResult.

The variable name should be meaningful. For example, iAge is an integer variable to store the age of a student.

In case the variable name consists of multiple words, the first letter of each word should be capitalized, for example iTotalMarks and fPriceOfCommodity.

Post a Comment