Back to Blog
Getting Started with Java

1/30/20223 min read

Getting Started with Java

Java is a high-level, object-oriented programming language known for its portability and strong memory management. It's widely used in enterprise applications, Android development, and backend systems.

Note: Java follows the principle of "Write Once, Run Anywhere" thanks to the Java Virtual Machine (JVM).

Features of Java

  • Object-Oriented
  • Platform Independent
  • Robust and Secure
  • Rich API
  • Multithreaded

Hello World Example

java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Basic Syntax

Variables

java
int age = 25;
String name = "Alice";
boolean isStudent = true;

Conditional Statement

java
if (age > 18) {
    System.out.println("Adult");
} else {
    System.out.println("Minor");
}

Loops

java
for (int i = 0; i < 5; i++) {
    System.out.println("Iteration: " + i);
}

Java Class Structure

java
public class MyClass {
    // Fields
    private int number;

    // Constructor
    public MyClass(int num) {
        this.number = num;
    }

    // Method
    public void displayNumber() {
        System.out.println("Number: " + number);
    }
}

Tip: Always follow naming conventions and keep your code readable!

Summary

Java is a great starting point for any programmer due to its readability and widespread usage. Start experimenting and build something fun!

Other posts that might interest you...