Java Tutorial For Beginners #2 Easy Learning Guide

Robert Jul 13, 2026

Welcome back to our comprehensive Java tutorial series! In our first session, we explored the basics of Java, its installation, and why it's a powerful programming language. Today, we dive deeper into the Java world, learning about variables, data types, and operators – essential building blocks for any software developer.

Learn Java Tutorial for Beginners, Part 27: Encapsulation and the API Docs
Learn Java Tutorial for Beginners, Part 27: Encapsulation and the API Docs

We'll approach this tutorial with a mix of theory and practical examples, ensuring you grasp concepts firmly. So, let's buckle up and embark on this exciting journey!

Java Tutorial for Beginners | Java Programming | Intellipaat
Java Tutorial for Beginners | Java Programming | Intellipaat

Variables and Data Types

Variables are containers for data values, which are essential for storing and manipulating data in your programs. They enable you to use meaningful names for your data instead of working with raw values.

10 Best Websites to Learn Java for Free in 2026
10 Best Websites to Learn Java for Free in 2026

Java supports eight primitive data types, used for storing values of different types, such as integers, floating-point numbers, characters, and Boolean values.

Primitive Data Types

the info sheet shows how to learn in 30 days
the info sheet shows how to learn in 30 days

Java's primitive data types include byte, short, int, long, float, double, char, and boolean. Each has a fixed size and cannot be null.

Here are their sizes, valid ranges, and an example:

Data TypeSize (bits)Valid RangeExample
byte8-128 to 127byte b = 100;
short16-32,768 to 32,767short s = 10000;
int32-2,147,483,648 to 2,147,483,647int i = 1000000;
long64-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807long l = 1000000000000L;
float321.4E-45 to 3.4E+38float f = 10.99f;
double644.9E-324 to 1.8E+308double d = 10.99;
char16'\u0000' to '\uffff'char c = 'a';
booleanUnknowntrue | falseboolean b1 = true;
Our First Java Program
Our First Java Program

Non-Primitive Data Types (Reference Types)

Besides primitive types, Java supports reference types, such as classes, interfaces, and arrays. These variables store memory address references rather than actual values.

Let's create an array of integers as our first example of a reference type:

Master Two Pointers Technique 💻 | Java DSA Interview Preparation Guide
Master Two Pointers Technique 💻 | Java DSA Interview Preparation Guide

Type name;

Here, Type could be any reference type (like int[], String, or CustomClass), and name is the variable name.

☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
Learn Java in 30 Days Only
Learn Java in 30 Days Only
a poster with different types of writing and numbers on it, including the words'jwa beginner notes '
a poster with different types of writing and numbers on it, including the words'jwa beginner notes '
☕ Java Operators Cheat Sheet | Master Java Operators Easily 🚀
☕ Java Operators Cheat Sheet | Master Java Operators Easily 🚀
Java Cheatsheet
Java Cheatsheet
a woman with long black hair sitting in front of a computer monitor and smiling at the camera
a woman with long black hair sitting in front of a computer monitor and smiling at the camera
Top 8 YouTube Channels to Learn Programming for Free in 2026
Top 8 YouTube Channels to Learn Programming for Free in 2026
Java Project Ideas For Beginners
Java Project Ideas For Beginners
Programming in Java Netbeans - A Step by Step Tutorial for Beginners: Lesson 14
Programming in Java Netbeans - A Step by Step Tutorial for Beginners: Lesson 14
Learn Java Collections Fast 🚀 | ArrayList HashMap Set Queue Explained
Learn Java Collections Fast 🚀 | ArrayList HashMap Set Queue Explained
Top 5 Java Projects for Beginners
Top 5 Java Projects for Beginners
Web development programming coding for beginners
Web development programming coding for beginners
Java Basics Cheat Sheet 📘⚡ | Learn Coding Faster & Smarter
Java Basics Cheat Sheet 📘⚡ | Learn Coding Faster & Smarter
How to Become a Java Developer (Step-by-Step)
How to Become a Java Developer (Step-by-Step)
java array operations
java array operations
the top 10 javasecript projects for beginners to do list application calculator
the top 10 javasecript projects for beginners to do list application calculator
Java OOP concepts cheat sheet
Java OOP concepts cheat sheet
30 Days of Java – Day 9 | Java Methods Explained for Beginners
30 Days of Java – Day 9 | Java Methods Explained for Beginners
java at a glance 😎
java at a glance 😎

int[] numbers;

Initializing the array:

int[] numbers = new int[5];

Operators in Java

Operators perform operations on variables and values. Java supports a rich set of operators, facilitating efficient and expressive code.

Let's classify and explore Java operators in detail.

Arithmetic Operators

Arithmetic operators perform mathematical operations, like addition (+), subtraction (-), multiplication (*), division (/), modulus (%), increment (++), and decrement (--).

Example:

int a = 10;

int b = 5;

int c = a + b;

System.out.println(c);

Output: 15

Comparison Operators

Comparison operators compare two values and return a Boolean value (true or false): equality (==), not equal (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (=<).

Example:

int a = 10;

int b = 5;

boolean isEqual = a == b;

System.out.println(isEqual);

Output: false

Logical Operators

Logical operators combine and manipulate Boolean values: AND (&&), OR (||), and NOT (!).

Example:

boolean a = true;

boolean b = false;

boolean c = a || b;

System.out.println(c);

Output: true

Expriment with these operators in your coding environment to gain a better understanding of their usage. In our next session, we'll delve into control structures, loops, and decision-making in Java.

Your journey into the world of Java is just beginning, and we're excited to have you along for the ride. Keep practicing, experimenting, and building – that's the best way to master any programming language. Until next time, happy coding!