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
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