J
JavaCraft
← Back to all posts

Core Java

Java Syntax & Data Types – A Gentle Introduction

Published: Nov 21, 2025 5 min read By Sanjay
Core Java Syntax Data Types

Every Java program begins with simple concepts: structure, basic syntax, and data types. Even though these look simple, they form the foundation for everything else — OOP, collections, Spring Boot, and large enterprise systems.

1. Basic Java Program Structure

Here’s the simplest Java program you can write:


public class Main {
    public static void main(String[] args) {
        System.out.println("Hello Java!");
    }
}
  • class Main → Java code lives inside classes.
  • main() → Entry point of every Java application.
  • System.out.println() → Prints to console.

2. Variables in Java

Variables store data. In Java, you must declare the type before using them.


int age = 21;
double price = 99.99;
String name = "Sanjay";
boolean active = true;

3. Primitive Data Types

Java has 8 primitive types:

  • byte – small numbers
  • short
  • int
  • long
  • float
  • double
  • char
  • boolean

These are stored directly in memory and are very fast.

4. Reference Types

Anything that is not a primitive is a reference type.


String title = "Java Developer";
int[] numbers = {1, 2, 3};
ArrayList list = new ArrayList<>();

Reference types store the address of the object, not the object itself.

5. Type Conversion

Java supports both implicit and explicit casting:


// Implicit (safe)
int a = 10;
double b = a;

// Explicit (manual)
double x = 9.7;
int y = (int) x; // y = 9

Final thoughts

Mastering syntax and data types is the first step toward writing clean, efficient Java code. Once you're comfortable with these, you’re ready to learn OOP, collections, and real-world Spring Boot projects.