Introduction to Java Programming

Subject: Data Structures and Algorithms · Language: Java · Level: beginner · 4 min read

Start Java for DSA with class structure, main method, input, output, variables, and fast beginner-friendly coding habits.

Java is a high-level, object-oriented programming language. It is used to create desktop applications, web applications, Android apps, enterprise software, backend systems, and many real-world products. Java is beginner-friendly because its syntax is clean and readable. At the same time, it is powerful enough for large applications and DSA problem solving.

History of Java

Java was developed by James Gosling and his team at Sun Microsystems. It was officially released in 1995. Earlier, Java was designed for electronic devices, but later it became popular for internet-based applications because it could run on different systems.

Today, Java is widely used in companies, Android development, banking systems, backend services, and placement coding interviews.

Purpose of Java

The main purpose of Java is to write reliable programs that can run on different platforms without major changes. This idea is commonly explained as: write once, run anywhere. A Java program is not directly converted into machine code for one operating system. Instead, it is converted into bytecode, and that bytecode runs on the JVM.

Why Java Is Platform Independent

Java source code is saved in a `.java` file. When it is compiled, the compiler creates a `.class` file containing bytecode. This bytecode is executed by the JVM, which stands for Java Virtual Machine.

Because every operating system can have its own JVM, the same bytecode can run on Windows, Linux, or macOS. This is the reason Java is called platform independent.

JVM, JRE, and JDK

Java uses JVM, JRE, and JDK to compile and run programs. These three are important enough to study separately, so this introduction only gives the basic idea. JDK is used to develop Java programs, JRE is used to run Java programs, and JVM executes the bytecode.

Features of Java

Java Program Structure

Every Java program is written inside a class. A class is like a container that holds the program code. For most Java compilers used in practice sections, the class name is usually written as `Main`.

The `main` method is the starting point of a Java program. When the program runs, Java begins execution from `public static void main(String[] args)`.

First Java Program

```java

public class Main {

public static void main(String[] args) {

System.out.println("Hello, Java DSA!");

}

}

```

`public class Main` creates a class named `Main`. `public static void main(String[] args)` is the main method. This is where execution starts.

`System.out.println("Hello, Java DSA!");` prints the message on the screen. The semicolon `;` is used to end a statement in Java. The curly braces `{ }` define the body of the class and method.

How Java Code Runs

First, the programmer writes source code in a `.java` file. Next, the Java compiler converts that source code into bytecode and creates a `.class` file. Finally, the JVM reads the bytecode and runs the program.

This flow is important because it explains why Java programs can run on different operating systems.

Why Java Is Used for DSA

Java is commonly used for DSA because it is strongly typed, readable, and supported by most coding platforms. It also has the Collections Framework, which provides ready-made data structures such as `ArrayList`, `HashMap`, `HashSet`, `Queue`, and `PriorityQueue`. However, a student should first understand the logic behind arrays, strings, linked lists, stacks, queues, recursion, searching, and sorting. Built-in collections should make the solution cleaner, not hide the concept.

Where Java Is Used

Java is used in Android apps, banking software, enterprise applications, backend APIs, cloud applications, desktop tools, and large-scale systems. Many companies also use Java in coding rounds because it is reliable, structured, and has strong library support.

Practice Question

Write your first Java program that prints `Welcome to Java Programming` on the screen.

More Java Lessons

Browse all PrepCampus study materials