First Java program
This is our first program in Java. In this program, we will print “hello world” message on the screen and see how the basic Java program is compiled and executed by Java. This has been a tradition to create the first program in any programming language which prints hello world on the screen so we will do the same and make the same program. Java is an object-oriented programming language, which is widely used all over the world by the majority of developers to develop large web and desktop applications. Java is also a pioneering technology in the industry that is used for mobile(Android) app development.
The "Hello World" program
Write the following code in your favorite editor and compile it.
Compile the program using the following command
javac HelloWorld.Java
And execute your program using the command
java HelloWorld
1. write a program and compile with the command
javac HelloWorld.Java
2. Execute your program using the command
java HelloWorld Java Python
Compile the program using the following command
javac HelloWorld.Java
And execute your program using the command
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } Output: Hello World
Structure of "Hello World" Program
![]() |
"Hello World" program in Java |
Java Keywords
A keyword is a reserved word or literal having some special meaning to perform or represent something in a programming language. The keywords can't be used as identifiers or variable names in a Java Program.
Following is the list of the Java keywords.
abstract | continue | for | new | switch |
assert*** | default | goto* | package | synchronized |
boolean | do | if | private | this |
break | double | implements | protected | throw |
byte | else | import | public | throws |
case | enum**** | instanceof | return | transient |
catch | extends | int | short | try |
char | final | interface | static | void |
class | finally | long | strictfp** | volatile |
const* | float | native | super | while |
* |
not used |
** | added in 1.2 |
*** | added in 1.4 |
**** | added in 5.0 |
Running a Java Program with command-line arguments
1. write a program and compile with the command
javac HelloWorld.Java
2. Execute your program using the command
java HelloWorld Java Python
/****Running with command-line arguments**********/ public class HelloWorld { public static void main(String[] args) { System.out.println("Hello "+args[0]); System.out.println("Hello "+args[1]); } } Output: Hello Java Hello Python