DEV Community

Cover image for Core Java Tutorial: From Fundamentals to OOP Concepts
suraj kumar
suraj kumar

Posted on

Core Java Tutorial: From Fundamentals to OOP Concepts

Java is one of the most popular and powerful programming languages used worldwide to build desktop applications, web applications, mobile apps, and enterprise-level software. Its reliability, security, and platform independence make it a top choice for developers and companies. If you are beginning your programming journey, mastering Java Tutorial is the most important foundation before moving to advanced frameworks like Spring Boot, Hibernate, and Android development.

This tutorial will guide you step-by-step through the fundamentals of Java and gradually lead you toward understanding Object-Oriented Programming (OOP) concepts, which form the heart of Java programming.

What is Java?

Java is a high-level, object-oriented, class-based, and platform-independent programming language developed by James Gosling at Sun Microsystems in 1995. Java uses the concept of Write Once, Run Anywhere (WORA), meaning that code compiled in Java can run on any system that has the Java Virtual Machine (JVM).

Key Features of Java

  • Simple & Easy to Learn
  • Object-Oriented Language
  • Platform Independent
  • Robust and Secure
  • Multithreaded
  • High Performance
  • Rich API and community support

Java Fundamentals

Before diving into complex programming, understanding the basic syntax and structure is essential.

Java Program Structure Example

class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}
Enter fullscreen mode Exit fullscreen mode

Explanation

  • class HelloWorld – Declares a class named HelloWorld.
  • main() method – The entry point of every Java program.
  • System.out.println() – Prints output to the console.

Java Data Types

Java supports two types of data types:

1. Primitive Data Types

Examples:
int, float, double, char, boolean, long, short, byte

int age = 25;
double salary = 45000.50;
boolean isActive = true;
Enter fullscreen mode Exit fullscreen mode

2. Non-Primitive Data Types

Examples:
String, Arrays, Class, Objects

String name = "Sonali";
Enter fullscreen mode Exit fullscreen mode

Java Variables & Operators

Variables store data, and operators perform operations in Java.

Example:

int a = 10;
int b = 20;
int sum = a + b;
System.out.println("Sum = " + sum);
Enter fullscreen mode Exit fullscreen mode

Control Statements

Control flow statements help manage the execution flow.

If-Else Example

int marks = 75;
if (marks >= 60) {
    System.out.println("First Division");
} else {
    System.out.println("Second Division");
}
Enter fullscreen mode Exit fullscreen mode

For Loop Example

for(int i = 1; i <= 5; i++) {
    System.out.println(i);
}
Enter fullscreen mode Exit fullscreen mode

Introduction to OOP in Java

Java is based strongly on OOP principles, which help create flexible, reusable, and scalable applications.

The Four Pillars of OOP

Concept Meaning
Encapsulation Binding data and code together
Inheritance Reusing properties of one class in another
Polymorphism Same method performing different actions
Abstraction Hiding internal implementation details

1. Encapsulation Example

class Student {
    private String name;

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}
Enter fullscreen mode Exit fullscreen mode

2. Inheritance Example

class Animal {
    void sound(){
        System. out.println("Animal makes a sound");
    }
}

class Dog extends Animal {
    void bark(){
        System. out.println("Dog barks");
    }
}
Enter fullscreen mode Exit fullscreen mode

3. Polymorphism Example

class Shape {
    void draw(){
        System. out.println("Drawing shape");
    }
}

class Circle extends Shape {
    void draw(){
        System.out.println("Drawing circle");
    }
}
Enter fullscreen mode Exit fullscreen mode

4. Abstraction Example

abstract class Vehicle {
    abstract void start();
}

class Car extends Vehicle {
    void start(){
        System.out.println("Car starts with key");
    }
}
Enter fullscreen mode Exit fullscreen mode

Why Learn OOP Concepts?

  • Increases maintainability & scalability
  • Real-world modeling becomes easier
  • Promotes clean, reusable code
  • Foundation for advanced Java frameworks

Conclusion

Understanding Core Java is crucial for anyone who wants to become a successful Java developer. By mastering the fundamentals and OOP concepts, you will be ready to build real projects and step confidently into advanced Java technologies. Practice daily, work with real examples, and keep improving your coding skills.

Top comments (0)