My First Java Program (Cont.)
Eevery Java program has a class name which normally matches the filename, and that every program must contain the main()
method, which is a standard method used by JVM (Java Virtual Machine) to start execution of any Java program.
The following list shows the steps of compiling the Java program and executing it in the command prompt of our Linux server undcemcs02
:
02 | What manual page do you want? |
05 | uname - print system information |
09 | Linux undcemcs02 3.10.0-957.1.3.el7.x86_64 No 1 SMP |
10 | Thu Nov 15 17:36:42 UTC 2018 x86_64 x86_64 x86_64 GNU /Linux |
12 | undcemcs02> which javac java |
16 | undcemcs02> emacs MyFirstClass.java |
21 | undcemcs02> cat MyFirstClass.java |
22 | public class MyFirstClass { |
23 | public static void main( String args[ ] ) { |
24 | System.out.println( "Hello World" ); |
28 | undcemcs02> javac MyFirstClass.java |
31 | MyFirstClass.java MyFirstClass.class |
33 | undcemcs02> java MyFirstClass |
|
The method
System.out.println()
is overloaded to accept all kinds of data types in Java.
It takes various kinds of input (such as
String
,
int
,
float
,
double
, or even
char
) and prints it out.
All of those methods are collectively referred as an
overloaded method in Java.