Lesson 3 of 50 – Features of Java
6%

Features of Java

Java is a popular programming language used to develop desktop applications, web applications, enterprise software, and backend systems. Java provides several features that make it useful for building reliable and maintainable applications.

Note: Important features of Java include object-oriented programming, platform independence, security, robustness, multithreading, portability, and automatic memory management.
1. Simple

Java was designed with a structured syntax and removes several complex features associated with languages such as C++, including direct pointer manipulation and manual memory deallocation.

Java still has important concepts to learn, but its consistent structure helps beginners understand programming.

  • Readable and structured syntax.
  • No direct pointer arithmetic.
  • Automatic memory management.
  • Built-in exception-handling mechanisms.
Example:
public class Main {
    public static void main(String[] args) {
        System.out.println("Java is simple to start learning.");
    }
}
Output:
Java is simple to start learning.
2. Object-Oriented

Java supports object-oriented programming (OOP). OOP organizes programs around classes and objects and helps developers structure large applications.

Important OOP concepts include:

  • Classes and objects
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction
Example:
class Student {
    String name = "Rahul";

    void display() {
        System.out.println(name);
    }
}

public class Main {
    public static void main(String[] args) {
        Student s = new Student();
        s.display();
    }
}
Output:
Rahul

Here, Student is a class and s is an object created from that class.

3. Platform Independent

Java is commonly described as platform-independent because its compiler generates bytecode that can run on different systems with compatible JVMs.

The basic process is:

Java Source Code
       |
       v
Java Compiler (javac)
       |
       v
Bytecode (.class)
       |
       v
Compatible JVM
       |
       v
Program Output
  • Write the Java program once.
  • Compile the source code into bytecode.
  • Run the bytecode on a compatible JVM.
  • Platform-specific dependencies may still require changes.
4. Secure

Java provides security mechanisms that help applications run in a controlled environment. These include bytecode verification, runtime checks, access controls, and security-related APIs.

  • Bytecode verification.
  • Runtime type checking.
  • Access modifiers such as private and protected.
  • Exception handling.
  • Support for secure network communication through appropriate APIs.
Example:
class Account {
    private double balance = 1000;

    public double getBalance() {
        return balance;
    }
}

public class Main {
    public static void main(String[] args) {
        Account a = new Account();
        System.out.println(a.getBalance());
    }
}
Output:
1000.0

The private modifier prevents other classes from directly accessing the balance field. This is an example of access control, not a complete security solution by itself.

5. Robust

Java is considered robust because it provides features that help developers detect errors and manage many common programming problems.

  • Strong type checking.
  • Exception handling.
  • Automatic memory management.
  • Array bounds checking.
  • Runtime checks for many invalid operations.
Example:
public class Main {
    public static void main(String[] args) {
        try {
            int result = 10 / 0;
            System.out.println(result);
        } catch (ArithmeticException e) {
            System.out.println("Cannot divide by zero.");
        }
    }
}
Output:
Cannot divide by zero.

The catch block handles the arithmetic exception instead of allowing it to terminate the program at that point.

6. Multithreaded

Java supports multithreading, which allows multiple threads of execution within a program. Threads can help applications perform different tasks concurrently.

  • Useful for background tasks.
  • Can improve responsiveness.
  • Supports concurrent operations.
  • Requires careful handling of shared data.
Example:
public class Main {
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            System.out.println("Thread is running");
        });

        t.start();
    }
}
Possible Output:
Thread is running

The start() method starts a new thread. The output shown is the expected message from this example.

7. Portable

Java bytecode is designed to be portable across compatible JVM implementations. This helps developers run the same compiled program on multiple systems.

  • Bytecode uses a platform-neutral format.
  • Compatible JVMs execute the bytecode.
  • Standard libraries help maintain consistent behavior.
  • External native libraries can reduce portability.
Example:
public class Main {
    public static void main(String[] args) {
        System.out.println("Java supports portability.");
    }
}
Output:
Java supports portability.
8. Automatic Memory Management

Java uses garbage collection to reclaim memory occupied by objects that are no longer reachable by the program. Developers generally do not manually free object memory.

  • Garbage collection manages eligible objects.
  • It reduces the need for manual memory deallocation.
  • Objects are created using the new keyword in many common cases.
  • Programmers should still manage resources such as files and database connections properly.
Example:
class Student {
    String name = "Amit";
}

public class Main {
    public static void main(String[] args) {
        Student s = new Student();

        System.out.println(s.name);

        s = null;
    }
}
Output:
Amit

After s = null, the object may become eligible for garbage collection if no other references point to it. Garbage collection timing is not guaranteed.

9. High Performance

Java can provide high performance through Just-In-Time (JIT) compilation. The JVM can compile frequently executed bytecode into native machine code at runtime.

  • JIT compilation can improve execution speed.
  • The JVM can optimize frequently executed code.
  • Performance depends on the application and runtime.
  • Java performance can be suitable for demanding server applications.
Remember: Java is not automatically faster than every other programming language. Actual performance depends on the program, algorithms, hardware, and runtime.
10. Distributed and Network Support

Java provides APIs for network communication and distributed applications. Developers can use these tools to build programs that communicate across computers and services.

  • Network communication APIs.
  • Support for sockets and URLs.
  • HTTP client APIs.
  • Libraries for web services and distributed systems.
Example:
import java.net.URI;

public class Main {
    public static void main(String[] args) {
        URI address = URI.create("https://example.com");

        System.out.println(address.getHost());
    }
}
Output:
example.com

This example uses Java's URI API to read the host from a URL. It does not make a network connection.

11. Dynamic

Java supports dynamic behavior through features such as runtime class loading, reflection, and dynamic linking of classes when required.

  • Classes can be loaded at runtime.
  • Reflection can inspect classes and methods.
  • Libraries can be linked when needed.
  • Frameworks use these capabilities for flexible applications.
Example:
public class Main {
    public static void main(String[] args) {
        Class<?> c = String.class;

        System.out.println(c.getName());
    }
}
Output:
java.lang.String

The example obtains runtime class information for Java's String class.

12. Java Features Summary
Feature Meaning
Simple Structured syntax and fewer low-level tasks.
Object-oriented Supports classes, objects, inheritance, and polymorphism.
Platform-independent Bytecode runs on compatible JVMs.
Secure Provides runtime checks and security mechanisms.
Robust Offers type checking, exceptions, and memory management.
Multithreaded Supports multiple threads of execution.
Portable Bytecode can work across supported platforms.
High performance JIT compilation and runtime optimization can improve speed.
Key Points
  • Java is a high-level programming language.
  • Java supports object-oriented programming.
  • Java bytecode can run on compatible JVMs.
  • Java provides security-related runtime features.
  • Exception handling helps manage errors.
  • Java supports multithreaded programming.
  • Garbage collection manages eligible objects.
  • JIT compilation can improve performance.
  • Java includes APIs for networking.
  • Reflection provides runtime class information.


🧠 Quick Quiz

1. Which feature allows Java bytecode to run on compatible JVMs?





2. Which feature helps Java reclaim memory from unreachable objects?





3. What does JIT stand for?