Introduction to Java Programming

Java is one of the most popular and widely used programming languages in the world. Developed by Sun Microsystems (now owned by Oracle) in 1995, Java is known for its “write once, run anywhere” (WORA) capability, meaning compiled Java code can run on all platforms that support Java without recompilation.

Features of Java programming 

There are numerous features of Java programming, some of which are described below.

  • Simple: Java is easy to read and learn, so it’s good for both beginners and experienced programmers. It avoids confusing things like pointers and operator overloading that can cause mistakes.
  • Object-Oriented: Java is fully object-oriented, which means it uses objects and classes to organize the code. This helps make the code reusable, easy to manage, and well-organized.
  • Platform Independent: Java follows the rule “Write Once, Run Anywhere.” This means you can write the code once and run it on any computer that has a Java Virtual Machine (JVM).
  • Robust: Java is designed to avoid errors. It checks data types carefully and handles mistakes using exception handling. It also cleans up unused memory automatically.
  • Secure: Java has strong security features, like checking code before it runs and controlling what the code can do, to keep programs safe and reliable.
  • High Performance: Java uses a Just-In-Time (JIT) compiler that makes the program run faster by optimizing the code while it is running.
  • Multithreading: Java can do many tasks at the same time using multithreading, which makes programs work faster and more efficiently.
  • Rich API: Java comes with a large collection of ready-to-use classes and functions, which makes it easier for developers to build applications.
  • Architecture-Neutral: Java code can run on any kind of computer system without any changes because of the JVM.
  • Dynamic: Java can adjust to changes while the program is running, which makes it flexible and powerful.

Java Environments

The Java Environment refers to the ecosystem and components required to develop, compile, and run Java applications. It encompasses the software, tools, and runtime infrastructure that enable Java’s “write once, run anywhere” capability. Below is a concise explanation of the key elements of the Java environment:

Components of Java Environments

  • Java Development Kit (JDK): The Java Development Kit (JDK) is a software development environment used for developing Java applications. It includes tools, libraries, and executables necessary for compiling, debugging, and running Java programs. Below are the main components of the JDK, along with explanations of their roles:
  • javac: javac is the Java compiler tool. It is used to convert Java source code (files with .java extension) into bytecode (files with .class extension), which can then be run by the Java Virtual Machine (JVM).
  • Javadoc: Javadoc is a tool in Java used to create documentation for your code. It reads special comments in your Java programs (written using /** ... */) and generates HTML pages that describe the classes, methods, and variables in your program.
  • Java Runtime Environment (JRE): it is a software package that provides the necessary tools and libraries to run Java programs on a computer. It does not include tools for developing Java applications (like a compiler), but it is essential for running Java applications.
  • Java Debugger (jdb): is a command-line tool provided by Java to help developers find and fix bugs in Java programs. It allows you to inspect, pause, and control the execution of a Java application to understand what it is doing step by step.
  • Java Archive Tool (jar): The Java Archive Tool (jar) is a command-line utility that comes with the Java Development Kit (JDK). It is used to create, view, extract, and manage Java Archive (JAR) files

What is the Java Standard Library?

The Java Standard Library is a collection of built-in classes and interfaces provided by Java to help developers write programs more easily. It includes a wide range of pre-written code that performs common tasks like input/output, string handling, data structures, networking, file handling, math operations, and more.

You don’t need to write everything from scratch — the Java Standard Library gives you ready-made tools to use in your programs.

Main Packages in the Java Standard Library:
  1. java.lang
    • Automatically imported in every Java program
    • Includes classes like String, Math, System, Object, Integer, Thread, etc.
  2. java.util
    • Provides utility classes like ArrayList, HashMap, Date, Collections, etc.
  3. java.io
    • Supports input and output operations using classes like File, InputStream, OutputStream, Reader, Writer, etc.
  4. java.nio
    • Advanced Input/Output (New I/O), for faster and more efficient file and data handling.
  5. java.net
    • Used for networking operations such as connecting to websites or sending data over the internet (Socket, URL, HttpURLConnection, etc.).
  6. java.sql
    • Used for working with databases using JDBC (Java Database Connectivity).
  7. java.time
    • Provides classes for handling dates and times (LocalDate, LocalTime, LocalDateTime, etc.).
  8. javax. swing
    • For building Graphical User Interfaces (GUIs) with windows, buttons, menus, etc.
  9. java.security
    • Provides classes for security features such as encryption and authentication.

JDK Versions

  • Latest Version: As of May 19, 2025, the latest stable version is JDK 22 (released March 2024). JDK 23 is in early access or preview stages, based on recent patterns.
  • Long-Term Support (LTS): JDK 21 (September 2023) is the latest LTS version, recommended for production use. Previous LTS versions include JDK 17, 11, and 8.
  • Release Cycle: Oracle releases new JDK versions every six months (March and September), with LTS versions every two years.

JDK Providers

  • Oracle JDK: The official JDK from Oracle, free for development but requires a license for commercial use in production (post-JDK 8).
  • OpenJDK: An open-source implementation of the JDK, widely adopted and free for all uses. Most vendors base their distributions on OpenJDK.
  • Other Vendors: AdoptOpenJDK (now Adoptium), Amazon Corretto, Azul Zulu, Red Hat, and IBM provide prebuilt OpenJDK binaries with support options.

Basic Structure of a Java Program

A Java program is a collection of classes and objects that work together to perform a specific task. Every Java program follows a standard structure so that the compiler and JVM (Java Virtual Machine) can understand and execute it correctly.

The main parts of a Java program are:

  1. Documentation Section
    • Contains comments to explain the code’s purpose, author, or instructions.
    • Example: // This is a simple Java program or /* Multi-line comment */.
  2. Package Declaration
    • Defines the package for organizing classes (optional for simple programs).
    • Example: package com.example;.
  3. Import Statement
    • Imports external classes or libraries needed for the program
  4. Interface Section
    • Defines interfaces (optional), which are abstract types used to specify a contract.
    • Example: interface MyInterface { void myMethod(); }.
  5. Class Definition
    • Declares the class, which is the blueprint for objects or the main container for the program.
    • Example: public class MyProgram { ... }.
  6. Class Variables
    • Declares variables that belong to the class, accessible throughout it.
    • Example: int myVariable = 10;.
  7. Main Method Class
    • Contains the main method, the entry point of the program.
    • Example:
    • public static void main(String[] args) { ... }.
  8. Methods and Behaviors
    • Includes additional methods and logic defining the program’s functionality.
  • Example: public void myMethod() {
    System.out.println(“Behavior”);
    }.
  1. Documentation Section (Again)
    • Optional additional comments at the end for further clarification.

Example:

// Documentation Section: A simple Java program
package com.example; // Package Declaration
import java.util.Scanner; // Import Statement

interface Printable { // Interface Section
void print();
}
public class MyProgram { // Class Definition
int classVariable = 5; // Class Variables
public static void main(String[] args) { // Main Method Class
System.out.println("Program started. Class variable: " + new MyProgram().classVariable);
}
public void display() { // Methods and Behaviors
System.out.println("This is a behavior.");
}
output: 
Program started. Class variable: 5

Object-Oriented Programming Concepts: 

Java is an object-oriented language. It provides the feature to implement an object-oriented model, where it is organised around objects and logic rather than data it is used at the beginning of the software lifecycle and also used to develop other applications. Object-oriented programming is a technique in which programs are written on the basis of objects, for example, (Java), where it adopts a concept that views everything as an object and implements logic about it. Let’s see the concepts of object-oriented programming in detail with a real-time example.

Object
An object is nothing but a matter of things that we find in everyday life. Technically, Java is a software bundle of related state and behaviour. An object has a state or properties (information such as size, height, colour, position, etc.), for example.

object oriented

Class
In Java programming, a class is defined as a blueprint from which objects are created. It models and describes the state and behaviour of an object. For example, consider a car with several properties like the clutch, steering, brake, etc.

Inheritance: 
Inheritance is a property by which the state and behaviour of one class (super class) can be inherited by its subclass. It is a powerful and natural mechanism for organising and
structuring software. For example, Human heredity.

Abstraction
Hiding the implementation details from the user is called as abstraction. Here, only the functionality will be provided. In Java, abstraction can be achieved by the abstract class and
Interface.
A class with an abstract keyword is called as abstraction.
Interface – blueprint of a class. Full abstraction can be achieved using this mechanism.

For example, the Invention of flight is based on the flying mechanism learnt from birds. So flights are derived from base class birds.

Encapsulation:
Encapsulation is one of the fundamental concepts of OOP. The mechanism of binding the data and function together in a single unit is called encapsulation. For example, Medicine hidden in a capsule. Where medicine is an important component that is hidden in a capsule.

Polymorphism
Polymorphism is the ability of an object to take many forms. It reacts differently in different situations. In Java, polymorphism is used to reduce code complexity. Methods or functions of a class imply the behaviour of polymorphism. In Java, all Java objects are polymorphic. For example, Frogs live indifferently on land or in water.

Compiled by Er. Basant Kumar Yadav

error: Content is protected !!
Scroll to Top