New Delhi, India
minigranth@gmail.com

First Java Program

Created with Sketch.

Core Java Tutorial

[fblike]

First Java Program : Introduction

  • "First Java Program"! How many times you have heard of this phrase. Before learning any language, it's just like a tradition to write first program that is commonly called as the "Hello World" program. 
  • We will be covering the complete description including the whole syntax and the procedure to run the program.

 

Writing : First  Java Program

Let us write our first Java program to print “Hello World! This is my first Java program. Save as hello.java

 

This image describes the code for the first java program called as hello world.

First Java Program : Code

 

Output

 

This image describes the output of the above program.

First Java Program : Output

 

Explanation : First Java Program

  • public is an access modifier.
  • class is a keyword which is used in every Java program to declare a class before writing Java program.
  • FirstProgram” is the class name.
  • static is a keyword which means we can call a method without creating its object. Since the main function is a static method no object is created by JVM to call main.
  • main() is a function from where execution of a program starts.
  • String[] args are string parameters passed in main and are used as command line arguments. If no String parameters are passed then Java gives an error.
  • out.println() to print some text in output. Here System is a class , out is the object of System class and println() is a method.

 

Executing : First Java Program

  • Type the below commands in command prompt
    • javac hello.java
    • java FirstProgram
  • The other method which is more simple and easy to use is writing the programs on IDE's like,
  • But we recommend to write your program in a text editor like Notepad++ and compile the program using command prompt.

Note : IDE stands for "Integrated Development Environment". It is a platform over which programs can be written across various languages. IDE provides developers the luxury to write, compile, execute and test the programs without the use of any external command.