Java Basic Syntax
Hello world ProgramLets start with simple Hello World program.
- Open you notepad or any other text editor you like.
- Copy this code and save the file with name HelloWorld.java
- open your command propmpt (cmd). Change you directory where you have saved your file.
- Suppose you have saved your file in C:\
- Now type javac HelloWorld.java and press enter. This will compile the program. If there are no errors in the code the command prompt will take you to the next line.
- Now type java HelloWorld to run your program
- you will see output on command propmp as Hello World!!
This is a keyword which is used to declare a class in java.
This is a keyword, an access specifier used to represent that this function is visible to all.
It is a keyword used to make static method. Advantage is that we do not require an object to access this method. JVM call main() method without creating any object.
It is a return type. Means function is not returning any value.
Execution of the program starts from the main() method, therefore if it is missing, there will be a compilation error.
Used to print statement written inside it. Like cout in C++ and printf() in c.