Getting Started with Java

Last Updated : July 24, 2025

Java is a versatile and widely-used programming language that enables developers to create applications for desktop, web, mobile, and embedded systems.

To begin programming in Java, you need to set up the required tools and understand the basic structure of a Java program.

Installing Java

Before writing Java programs, you need to install the Java Development Kit (JDK), which includes tools such as the compiler (javac) and the Java Runtime Environment (JRE).

Follow the steps below to install Java on your system:

1. Visit the Official Java Download Page

You can download Java Development Kit (JDK) from either of the following official sources:

  • Oracle JDK – Recommended for enterprise and commercial applications.
  • OpenJDK – Open-source implementation of the Java Platform.

2. Download the Latest JDK

On the respective page, select the latest Java version compatible with your operating system:

  • Windows: Choose the .exe installer
  • macOS: Choose the .dmg installer
  • Linux: Choose the appropriate .tar.gz or use a package manager like apt or yum

3. Install the JDK

Run the downloaded installer and follow the on-screen instructions. By default, Java will be installed in a directory like:

  • C:\Program Files\Java\jdk-version on Windows
  • /Library/Java/JavaVirtualMachines on macOS
  • /usr/lib/jvm on Linux

4. Set JAVA_HOME Environment Variable

Set the JAVA_HOME variable to point to your JDK installation directory.

  • Windows:
    JAVA_HOME=C:\Program Files\Java\jdk-XX
  • macOS/Linux:
    export JAVA_HOME=/usr/lib/jvm/jdk-XX

5. Add Java to System PATH

Include the bin directory of your JDK in your system's PATH variable:

  • Windows:
    PATH=%JAVA_HOME%\bin;%PATH%
  • macOS/Linux:
    export PATH=$JAVA_HOME/bin:$PATH

6. Verify Installation

Open a terminal or command prompt and run:

java -version
javac -version

If Java is correctly installed, you should see the version details.

Setting Up a Java Development Environment

You can write Java code using any text editor, but using an IDE makes development easier. Popular IDEs include:

  • Eclipse
  • IntelliJ IDEA
  • NetBeans
  • VS Code (with Java extensions)

Writing Your First Java Program

A Java program must contain a class with a main method. This is where the execution begins.

Example

The following is a simple Java program that prints a greeting message:

public class FirstProgram {
    public static void main(String[] args) {
        System.out.println("Welcome to Java Programming!");
    }
}

When you run the above code, the output will be:

Welcome to Java Programming!

Compiling and Running Java Programs

To compile and run a Java program from the command line:

  • Save the file with a .java extension (e.g., FirstProgram.java).
  • Open the terminal or command prompt and navigate to the file location.
  • Compile the code using:
    javac FirstProgram.java
  • Run the compiled class using:
    java FirstProgram

Understanding the Basic Java Program

Let's break down the code structure of the first program:

  • public class FirstProgram – Declares a public class named FirstProgram.
  • public static void main(String[] args) – The main method is the entry point of every Java application.
  • System.out.println() – Prints output to the console.

Getting Started with Java Exercise

Select the correct option to complete each statement about starting with Java.

  1. To compile a Java program, you use the command:
  2. The method where Java program execution begins is:
  3. Which tool executes the compiled Java bytecode?

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.