![]() |
|
Our First Java Program, Free online Core Java Programming Tutorial, Learn Java Programming Language online for free... |
| Lessons | Our First Java Program |
|
|
Java Program Files: Java program files are very similar to the .c or .cpp program files. In Java the source code is written in the .java file. Each .java source file can contain at most one public class. If there is a public class, then the class name and file name must match. Furthermore, every piece of java code must be the part of a class. The Java compiler creates Bytecode from the .java program file and stores the same in a .class file. This bytecode, contained in the .class file, generated by the Java compiler is ready to be executed by the Java Virtual Machine (JVM). For each class in a source file (both public and non-public classes), the compiler creates one ".class" file, where the file name is the same as the class name. Our First Java Program: class HelloWorld {
public static void main( String [ ] args ) {
System.out.println("Hello world!");
}
} You must be glad to see that the above code is very similar to the C or C++ code. When the above code is run after compilation, it simply prints “Hello world!” to the console. Important points to remember:
Compiling a Java Program File: When compiling a program, you type the full file name, including the ".java" extension and when running a program, you just type the name of the class whose main function you want to execute. Use javac command to compile your java program files.
Next >>> Lesson No. 3: Java Data Types
|