Java Language Introduction
⏱️ Estimated time: 15 minutes | Difficulty: Beginner
Table of Contents
What is Java Programming?
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It was developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation) and released in 1995.
Write Once, Run Anywhere (WORA)
Java is famous for its WORA philosophy, meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. This is achieved by running the code on a JVM (Java Virtual Machine).
Why Should We Learn Java?
Java is the undisputed king of enterprise-level architecture.
- Platform Independent: As long as the target machine has a JVM installed, the Java bytecode will run flawlessly whether it's Windows, Mac, or Linux.
- Purely Object-Oriented: Everything in Java is an object (except primitive types), ensuring extremely organized, scalable codebases.
- Memory Management: Java handles memory allocation and deallocation automatically using an incredible feature called the Garbage Collector.
- Multithreading: Java provides an inherently built-in way to run multiple parts of a program concurrently to maximize CPU utilization.
First Java Program (Hello World)
Java requires every line of code to be encapsulated within a Class. This makes the "Hello World" slightly more verbose than Python or C.
// Simple Java program to display "Hello World"
class HelloWorld {
public static void main(String[] args) {
// Print statement
System.out.println("Hello World");
}
}
Try It Yourself
Space Complexity: O(1)
Explanation of the Java Program
Because Java is strictly object-oriented, even a basic print statement involves a class and structural keywords.
class HelloWorld { ... }
In Java, every application begins with a class name, and that class must match the filename. `HelloWorld` is the name of the class.
public static void main(String[] args)
public means anyone can access it. static means the method can be run without creating an instance of the class containing it. void means the method doesn't return anything. main is the entry point of the program.
System.out.println("Hello World");
System is a built-in class. out is a static member of the System class representing standard output stream. println() is the method to print the string to the console and append a new line.
Applications of Java
- Android Apps: Until Kotlin came around, Java was the exclusive language for Android Application development.
- Enterprise Software: Large scale banking, backend, and billing software heavily rely on Java's stability and Spring Framework.
- Big Data Technologies: Hadoop and other big data frameworks are written in Java.
- Server-side Applications: Apache, JBoss, GlassFish, etc.