Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
First Program Of Java
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. Java Tutorials
  3. First Program Of Java

Java Tutorial

Basic JAVA Fundamentals

  • JAVA Tutorial Content
  • What Is Java
  • History Of Java
  • Java Environment
  • Features Of JAVA
  • C++ Vs Java
  • Java Basic Syntax
  • First Program Of Java
  • Java Identifiers
  • Java Modifiers
  • Java Variable Types
  • Java Basic Datatypes
  • Java Keywords

Control Statements

  • Control Statements
  • Java If Else Statement
  • Nested If Statement In Java
  • Java Switch Statement

JAVA Loops

  • Loop In Java
  • For Loop In JAVA
  • Foreach Loop In JAVA

First Program Of Java

we will learn how to write the simple / first program of java. We can write a simple hello java program easily after installing the JDK.

To create a simple / first java program, you need to create a class that contains main method. Lets understand the requirement first.

Requirement for Hello Java Example

For executing any java program, you need to

  • install the JDK if you dont have installed it, download the JDK and install it.
  • set path of the jdk/bin directory. 
  • create the java program
  • compile and run the java program

Creating hello java example

Lets create the hello java program: FirstProgram.java

class FirstProgram{
  public static void main(String args[]){ 
  System.out.println("Welcome To java First Program"); 
  }
} 

 

To compile:    javac FirstProgram.java
To execute:    java FirstProgram

Output : Welcome To java First Program

 

Understanding first java program

Lets see what is the meaning of class, public, static, void, main, String[], System.out.println().

  • class keyword is used to declare a class in java.
  • public keyword is an access modifier which represents visibility, it means it is visible to all.
  • static is a keyword, if we declare any method as static, it is known as static method. The core advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it doesnt require to create object to invoke the main method. So it saves memory.
  • void is the return type of the method, it means it doesnt return any value.
  • main represents startup of the program.
  • String[] args is used for command line argument. We will learn it later.
  • System.out.println() is used print statement. We will learn about the internal working of System.out.println statement later.

How many ways can we write a java program

There are many ways to write a java program. The modifications that can be done in a java program are given below:

1) By changing sequence of the modifiers, method prototype is not changed.

Lets see the simple code of main method.

static public void main(String args[]) 

 
2) subscript notation in java array can be used after type, before variable or after variable.

Lets see the different codes to write the main method.

public static void main(String[] args)
public static void main(String []args)
public static void main(String args[])


3) You can provide var-args support to main method by passing 3 ellipses (dots)

Lets see the simple code of using var-args in main method. We will learn about var-args later in Java New Features chapter.

public static void main(String... args)


4) Having semicolon at the end of class in java is optional.

Lets see the simple code.

class A{ 
static public void main(String... args){ 
System.out.println("hello World"); 
} 
};

 
Valid java main method signature

public static void main(String[] args) 
public static void main(String []args) 
public static void main(String args[]) 
public static void main(String... args) 
static public void main(String[] args) 
public static final void main(String[] args) 
final public static void main(String[] args) 
final strictfp public static void main(String[] args) 


Invalid java main method signature

public void main(String[] args) 
static void main(String[] args) 
public void static main(String[] args) 
abstract public static void main(String[] args) 


Resolving an error "javac is not recognized as an internal or external command"?

If there occurs a problem like displayed in the below figure, you need to set a path. Since DOS does not know javac or java, we need to set a path. Path is not required in such a case if you save your program inside the JDK/bin folder. But its a good approach to set path. Click here for How to set path in java.

Series: Java Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
First Program simple program of java hello java program hello world program in java using notepad simple java program examples for beginners java hello world tutorial hello world java code simple java program to add two numbers

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.