Basics of Java

๐ 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:
JDK (Java Development Kit) โ Includes tools to compile and run Java code.
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 namedHelloWorld
.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:
Type | Example |
int | 10 |
double | 20.5 |
char | 'A' |
boolean | true/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.
Subscribe to my newsletter
Read articles from Notz directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
