Monday, July 19, 2010

java first

Java is a popular and widely used programming language. It was originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems’ Java platform. The language’s syntax has much in common with C and C++, but its object model is simpler and has less low-level facilities. Undoubtedly, one of Java’s strong points is an automatic memory management. The developer determines when objects are created, but it’s a runtime task to free memory, when objects are no longer in use.

java Tutorials

>>downloads and installation(jdk and any IDE(netbeans or eclipse)
>>Hello World


download

First of all you have to download some stuff from the Internet:

1.Download the latest JDK from: http://java.sun.com/javase/downloads/index.jsp
2.Download Eclipse IDE for Java Developers from: http://www.eclipse.org/downloads/


hello world

HelloWorld.java

public class HelloWorld {
/**

* @param args

*/

public static void main(String[] args) {

System.out.println("Hello World! I am new to Java.");

}

}

First of all, Java is an object-oriented programming language. Thus, Java program necessarily consists of classes. There are no global variables and functions, as you may see in C++. We called the class HelloWorld

public class HelloWorld {


}


Draw attention to the fact, that filename of the file is .java. It is obligatory in Java.

Entry point

Each application in Java has an entry point to start from. It is a public static method called main. Arguments to application are passed through args parameter.

public static void main(String[] args) {


}

Print command
System.out.println("Hello World! I am new to Java.");

Comments
Above the main method declaration you see comments block:

/**

* @param args

*/

It is special comments, called Javadoc. Using this system, one may automatically generate documentation for properly commented source.

Build and run

Building
Enter the directory with your source file and run the following command:

javac HelloWorld.java
After it is executed you will see a new file HelloWorld.class. This file is a compiled HelloWorld class.

Running
Now you can run it using following command:

java HelloWorld

No comments:

Post a Comment