Basics of Java

NotzNotz
3 min read

๐Ÿš€ Getting Started with Java: A Beginnerโ€™s Guide

Java is one of the most popular and powerful programming languages in the world. From Android apps to large-scale enterprise systems, Java is used everywhere. Whether you're a student, a job seeker, or simply someone curious about coding โ€” learning Java is a great place to start!

In this blog, we'll cover the basics of Java, from what it is to writing your very first program.


๐Ÿง  What is Java?

Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995 (now owned by Oracle). Itโ€™s known for its platform independence, meaning you can write Java code once and run it anywhere โ€” thanks to the Java Virtual Machine (JVM).


๐Ÿ› ๏ธ Why Learn Java?

  • โœ… Simple and easy to learn

  • ๐Ÿ” Secure and robust

  • ๐Ÿ“ฑ Used in Android app development

  • ๐Ÿ’ผ In-demand in the job market

  • ๐ŸŒ Great for web, desktop, and enterprise applications


๐Ÿ“ Setting Up Java

To start coding in Java, you need:

  1. JDK (Java Development Kit) โ€“ Includes tools to compile and run Java code.

  2. IDE (Integrated Development Environment) โ€“ Like Eclipse, IntelliJ IDEA, or VS Code to write your code easily.

Download Java: https://www.oracle.com/java/technologies/javase-downloads.html


๐Ÿ–ฅ๏ธ Your First Java Program

Letโ€™s write a simple โ€œHello, World!โ€ program in Java.

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

Explanation:

  • public class HelloWorld: Defines a class named HelloWorld.

  • public static void main(String[] args): The main method โ€“ the entry point of any Java program.

  • System.out.println(...): Prints text to the console.


๐Ÿ”ค Java Basics

๐Ÿ“Œ 1. Variables

Java variables store data. Common types:

javaCopyEditint age = 25;
String name = "Alice";
double salary = 50000.50;
boolean isJavaFun = true;

๐Ÿ“Œ 2. Data Types

Java is a statically-typed language. Here are some primitive types:

TypeExample
int10
double20.5
char'A'
booleantrue/false

๐Ÿ“Œ 3. Operators

Java supports arithmetic, relational, and logical operators:

javaCopyEditint a = 10 + 5;       // 15
boolean result = a > 5 && a < 20;  // true

๐Ÿ” Control Structures

๐Ÿ”น if-else

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

๐Ÿ”น for Loop

javaCopyEditfor (int i = 0; i < 5; i++) {
    System.out.println(i);
}

๐Ÿ”น while Loop

javaCopyEditint i = 0;
while (i < 5) {
    System.out.println(i);
    i++;
}

๐Ÿงฑ Object-Oriented Programming (OOP)

Java is an OOP language, which means it is based on classes and objects.

Example:

javaCopyEditclass Car {
    String color = "Red";

    void drive() {
        System.out.println("Car is driving...");
    }
}

public class Main {
    public static void main(String[] args) {
        Car myCar = new Car();
        myCar.drive();
        System.out.println(myCar.color);
    }
}

๐Ÿ“š Conclusion

Java is a versatile and beginner-friendly language that opens up many opportunities in software development. This blog covered the essentials โ€” from setting up your environment to writing your first program and understanding key concepts.

Next Steps:

  • Practice writing small Java programs.

  • Learn about functions, arrays, and exception handling.

  • Explore OOP concepts like inheritance and polymorphism.

0
Subscribe to my newsletter

Read articles from Notz directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Notz
Notz