Java
From AIMSWiki
Java is a modern, object-oriented, compiled computer programming language.
Some resources are here :-
- Java home page (http://www.java.com/en/)
- Sun Java tutorials (http://java.sun.com/docs/books/tutorial/)
Java is 3 things :-
- A language (syntax, reserved words, etc.)
- A library (Input / output, many class libraries (http://java.sun.com/javase/6/docs/api/))
- A virtual machine (the runtime)
Hello world in Java looks like this :-
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output, followed by the numbers 1 to 10.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
for(int i=0; i<10; i++){
System.out.print(i + " ");
}
System.out.println("Finished!");
}
}
Note the docstring syntax, /**, that is used by other tools to generate documentation.
Java also accepts the C++ style comments, from // to the end of the line.
Then there is the class definition. This is the Java Object - Java is an Object Oriented language.
Like python, filenames in java are tied to objects in the language. This program, with its one class definition, expects to be in a file called HelloWorldApp.java. This class has one method - main. In the Java programming language, every application must contain a main method whose signature is:
public static void main(String[] args)
It is the entry point for the program.
Like C, this program must be compiled before it is run.
javac HelloWorldApp.java # compile java HelloWorldApp # run
Java includes a dissassembler program - javap. It dis-assembles java class files.
Try the following :-
javap HelloWorldApp javap -c HelloWorldApp

