Java Programming Basics: A Beginner’s Guide
This guide introduces fundamental Java programming concepts for beginners. We will cover core
topics including data types, variables, operators, arrays, control flow statements, functions (methods),
and basic input/output. Each section includes clear explanations and simple code examples (with
comments) to illustrate the concepts. All code snippets are written for console applications (text-based
programs), and we also touch on simple GUI input/output using JOptionPane .
Note: In Java, all code resides within classes. For simplicity, assume code examples are inside a
public static void main(String[] args) method of a class, unless otherwise noted.
Primitive Data Types, Variables, and Operators
Java is a statically-typed language, meaning you must declare a variable’s type before using it. Java has
8 primitive data types (predefined types for simple values) and supports various operators for
performing operations on these values.
Primitive Data Types in Java
The eight primitive data types in Java are:
• byte – 8-bit integer type (range: -128 to 127). Often used for saving memory in large arrays.
• short – 16-bit integer type (range: -32,768 to 32,767).
• int – 32-bit integer type (range: approx. –2 billion to 2 billion). This is the default type for
integers.
• long – 64-bit integer type (very large range, about –9×10^18 to 9×10^18). Use long for
larger integer values (append L to numeric literal, e.g., long bigNum = 12345678910L; ).
• float – 32-bit floating-point (decimal) number. Single-precision (about 6-7 decimal digits
accuracy). Append f to literal (e.g., 3.14f ) when assigning to float.
• double – 64-bit floating-point number. Double-precision (about 15-16 decimal digits). This is
the default type for decimals (e.g., double price = 19.99; ).
• boolean – 1-bit type representing true or false. Often used in conditional logic.
• char – 16-bit Unicode character (holds a single character like 'A' , '5' , or '$' ). Note that
String (sequence of characters) is not a primitive type but a Class in Java.
Example – Declaring and initializing variables of different types:
// Declare and initialize variables of various primitive types
int age = 25; // integer variable
double price = 9.99; // double (floating-point) variable
char initial = 'J'; // char variable (note the single quotes)
boolean isJavaFun = true; // boolean variable (true or false)
[Link](age); // prints 25
[Link](price); // prints 9.99
1
[Link](initial); // prints J
[Link](isJavaFun); // prints true
In the code above, we declared four variables with types int , double , char , and boolean . Each
variable is initialized with a literal value of the appropriate type. You must use matching types (e.g., you
cannot assign a decimal value to an int without casting). Also note the syntax: each statement ends
with a semicolon ; . Variable names should start with a letter, and by convention they begin with a
lowercase letter (e.g., age , price ). Java keywords (like int , double , class , etc.) cannot be
used as variable names.
Operators in Java
Operators are symbols that perform operations on variables and values. Java has several categories of
operators:
• Arithmetic Operators: + , - , * , / , % for addition, subtraction, multiplication, division,
and modulus (remainder) respectively. These work on numeric types. For example, a + b adds
two numbers. Division / between integers discards any fractional part (e.g., 5 / 2 yields 2
in integer division), whereas with doubles it produces a floating-point result ( 5.0 / 2.0 yields
2.5 ). The % operator gives the remainder (e.g., 5 % 2 is 1 ).
• Comparison (Relational) Operators: == , != , < , > , <= , >= . These compare two values
and produce a boolean result ( true or false ). For example, x == y is true if x equals
y , while x < y is true if x is less than y . Important: Use == to compare primitive values
for equality (and use .equals() for comparing objects like strings).
• Logical Operators: && (logical AND), || (logical OR), ! (logical NOT). These operators
evaluate boolean expressions. For example, (a > 0 && a < 10) is true if both conditions are
true. (x % 2 == 0 || y % 2 == 0) is true if either x or y is even. The ! operator
negates a boolean value (e.g., if isJavaFun is true, !isJavaFun is false).
• Assignment Operator: = is used to assign values to variables (we saw this in variable
declarations above). You can combine assignment with arithmetic using operators like += , -= ,
*= , /= , %= (for example, x += 5; adds 5 to the current value of x ).
• Increment and Decrement: ++ and -- increase or decrease an integer variable by 1. They
can be used as a prefix or suffix (e.g., counter++ or ++counter ). For instance, if counter
is 7, then counter++ (post-increment) evaluates to 7 (then counter becomes 8), while +
+counter (pre-increment) would first increment counter to 8, then evaluate to 8. These are
commonly used in loops.
Example – Using arithmetic, comparison, and logical operators:
int a = 10;
int b = 3;
int sum = a + b; // arithmetic addition (sum = 13)
int quotient = a /
b; // integer division (quotient = 3, because 10/3 = 3 remainder
1)
int remainder = a % b; // modulus (remainder = 1, because 10 mod
3 = 1)
boolean compare1 = (a > b); // comparison (true, since 10 > 3)
2
boolean compare2 = (a == b); // comparison (false, 10 is not equal to
3)
boolean logical = (a > 5 && b < 5); // logical AND (true, 10>5 and 3<5 are
both true)
[Link]("a + b = " + sum); // prints "a + b = 13"
[Link]("a / b = " + quotient); // prints "a / b = 3"
[Link]("a % b = " + remainder); // prints "a % b = 1"
[Link]("Is a > b? " + compare1); // prints "Is a > b? true"
[Link]("Is a == b? " + compare2); // prints "Is a == b? false"
[Link]("Condition (a>5 && b<5) is " + logical); // prints true
In this example, we demonstrated arithmetic operations (addition, division, modulus) and their results,
as well as comparison and logical operations producing boolean outcomes. Notice how we use
[Link] to output results to the console, and how string concatenation ( + ) is used to
join text with variables ( "a + b = " + sum ). This + for strings is a different context (used for
concatenation when one operand is a string).
Arrays in Java
An array is a container object that holds a fixed number of values of a single type. Arrays in Java are
used to store multiple values in a single variable, instead of declaring separate variables for each value.
They are essentially a sequence of elements, all of the same type, accessible by an index.
One-Dimensional Arrays
Declaration and Initialization: To use an array, you must declare it and then allocate memory for it.
There are two common ways to declare a one-dimensional array in Java:
• Method 1: Specify the type with square brackets, then allocate with new . For example:
int[] numbers = new int[5];
This declares an array of integers named numbers with length 5. Initially, all elements will have
default values (for numeric types default is 0, for boolean false, for char '\u0000'). You can assign values
later, e.g., numbers[0] = 10; .
• Method 2: Use an array initializer (literal). For example:
int[] primes = {2, 3, 5, 7, 11};
This declares and initializes an int array with 5 elements (2, 3, 5, 7, 11). The length of the array is
determined by the number of values provided.
In both cases, the type of the array and the type of its elements must match. You can access elements
by index using square brackets. Important: Java array indices start at 0 and go up to length-1 . For
an array of length 5, valid indices are 0,1,2,3,4. Attempting to access an invalid index (like numbers[5]
in an array of length 5) will cause an ArrayIndexOutOfBoundsException .
3
Using and Iterating Through Arrays: You can use loops to iterate over array elements or access them
individually by index.
int[] scores = new int[3];
scores[0] = 90; // assign values to each index
scores[1] = 70;
scores[2] = 85;
// Accessing array elements by index:
[Link]("First score: " + scores[0]); // 90
[Link]("Second score: " + scores[1]); // 70
// Iterate over the array with a for loop:
int total = 0;
for (int i = 0; i < [Link]; i++) { // [Link] gives the
size (3)
total += scores[i]; // add each element to total
[Link]("Score at index " + i + ": " + scores[i]);
}
[Link]("Total score = " + total);
Explanation: We created an int array scores of length 3 and manually assigned values. We then
printed the first two elements to show direct access. Next, we used a for loop to go through each
index from 0 to [Link] - 1 . The property [Link] returns the size of the array
(3 in this case). Inside the loop, we accumulate a running total of scores and print each score with its
index. After the loop, we print the total. Using scores[i] accesses the element at index i .
Java also provides an enhanced for-each loop to iterate arrays more easily:
// Enhanced for loop to iterate through array
for (int score : scores) {
[Link](score);
}
This loop reads as “for each int score in scores ” and iterates through each element directly. It’s a
simpler syntax when you don't need the index inside the loop.
Multidimensional Arrays
Java supports multidimensional arrays (arrays of arrays). The most common are two-dimensional
arrays, which you can visualize as a table (rows and columns).
Declaration: For a 2D array, you might do, for example:
int[][] matrix = new int[2][3];
4
This creates a 2D array with 2 rows and 3 columns (total 6 int elements). Initially all are 0. You can access
elements with two indices: matrix[row][col] . For instance, matrix[0][1] refers to the element
in first row, second column.
You can also initialize a 2D array with literal values:
int[][] presetMatrix = {
{1, 2, 3},
{4, 5, 6}
};
// presetMatrix is a 2x3 matrix with specified values.
[Link](presetMatrix[1][2]); // prints 6 (element at second row,
third column)
To iterate through a 2D array, you typically use nested loops: one for the rows, one for the columns:
for (int i = 0; i < [Link]; i++) { // [Link] is
number of rows
for (int j = 0; j < matrix[i].length; j++) { // matrix[i].length is
number of cols in row i
matrix[i][j] = i + j; // example assignment
[Link](matrix[i][j] + " ");
}
[Link](); // new line after each row
}
The above nested loop fills the matrix with some values (here just i+j as an example) and prints them
in a grid form. Multidimensional arrays can have more than two dimensions (e.g., 3D arrays), but those
are less common for beginners.
Note: Arrays are fixed in length once created. If you need dynamic resizable collections, you would use
classes like ArrayList , but that’s beyond the scope of this basics guide.
Basic Control Statements in Java
Control statements allow you to direct the flow of execution in a program, making decisions
(conditional branching) or repeating actions (loops). Java’s basic control structures include conditional
statements ( if , if-else , switch ) and loop constructs ( for , while , do-while ). We will look
at each of these with examples.
Conditional Statements (if, if-else, else-if ladder, switch-case)
if Statement: An if statement tests a boolean condition and executes a block of code if the
condition is true. For example:
int x = 10;
if (x > 0) {
5
[Link]("x is positive!");
}
Here, the message will print only if x > 0 evaluates to true. If x were not greater than 0, the code
inside the if block would be skipped entirely.
if-else Statement: You can provide an alternative block of code to execute when the condition is
false using an else clause:
int num = 5;
if (num % 2 == 0) {
[Link](num + " is even.");
} else {
[Link](num + " is odd.");
}
This checks if num is divisible by 2. If true, it prints an even-number message; otherwise, it prints an
odd-number message. Exactly one of the two println statements will execute depending on the
condition.
else if Ladder: When you have multiple conditions to check sequentially, you can use an
if-else-if ladder. This is a chain of if statements where each subsequent if runs only if the
previous conditions were false:
int score = 75;
if (score >= 90) {
[Link]("Grade: A");
} else if (score >= 80) {
[Link]("Grade: B");
} else if (score >= 70) {
[Link]("Grade: C");
} else if (score >= 60) {
[Link]("Grade: D");
} else {
[Link]("Grade: F");
}
In this example, multiple ranges are checked in order. The first condition that evaluates to true will have
its block executed, and the rest of the ladder is skipped. If none of the if or else if conditions are
true, the final else block runs as a catch-all (assigning an "F" grade in this case). This structure is
useful for mutually exclusive conditions and decision trees.
switch-case Statement: A switch statement is an alternative to a long else-if ladder when you
are comparing the same variable or expression against many possible values. It allows multi-way
branching based on the value of an expression (works with int , char , String , and a few other
types).
The syntax of a switch-case looks like this:
6
int day = 3;
switch (day) {
case 1:
[Link]("Monday");
break;
case 2:
[Link]("Tuesday");
break;
case 3:
[Link]("Wednesday");
break;
case 4:
[Link]("Thursday");
break;
case 5:
[Link]("Friday");
break;
default:
[Link]("Weekend");
break;
}
Explanation: The value of day is compared against each case . If day is 1, it prints "Monday"; if 2,
"Tuesday"; if 3, "Wednesday", etc. The break statements are crucial — they terminate the switch after
executing the matching case, preventing "fall-through" (without break , execution would continue into
subsequent cases, which is usually undesirable except in special scenarios). The default case at the
end is optional but recommended; it runs if none of the cases match. In the example above, any value
of day outside 1–5 will result in "Weekend" (covering 6, 7 or any other number as a default action).
Note: Starting from Java 7, you can also use String in switch cases. For example, switch(str)
with case "yes": ... . But for beginner-level usage, integer or char cases are common.
Looping Statements (for, while, do-while)
Loops allow repeated execution of a block of code as long as a certain condition is met or for a fixed
number of iterations. Java provides for , while , and do-while loops.
for Loop: A for loop is typically used when you know in advance how many times you want to
iterate. It has a built-in structure for initialization, loop condition, and increment/decrement in one line.
Syntax:
for (initialization; condition; update) {
// loop body: code to repeat
}
Example – printing numbers 1 to 5 using a for loop:
7
for (int i = 1; i <= 5; i++) {
[Link]("Count: " + i);
}
Explanation: Here, int i = 1 is the initialization (loop variable i starts at 1). The loop will run
while the condition i <= 5 is true. After each iteration, the update i++ executes (incrementing
i by 1). The loop prints the count and will iterate with i = 1,2,3,4,5. When i becomes 6, the condition
fails and the loop stops. This loop will output:
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
while Loop: A while loop is used when you want to repeat an action while a condition remains
true. It checks the condition at the start of each iteration. Syntax:
while (condition) {
// loop body
}
Example – using a while loop to print numbers 1 to 5:
int j = 1;
while (j <= 5) {
[Link]("j = " + j);
j++; // don't forget to modify the loop variable!
}
Explanation: The variable j starts at 1. The loop checks j <= 5 before each iteration. If true, it
executes the loop body (printing and then incrementing j). This will print j from 1 through 5 just like the
for loop did. If the condition is false at the very beginning, the loop body may not execute at all. For
example, if j were initialized to 6, the while loop would not run even once because the condition
6 <= 5 is false initially.
One must be careful to ensure the loop condition will eventually become false; otherwise, you get an
infinite loop. In the example, incrementing j eventually makes the condition false (when j becomes
6).
do-while Loop: A do-while loop is similar to a while loop, except that it executes the loop body
at least once before checking the condition. The syntax:
8
do {
// loop body
} while (condition);
Notice the condition comes after the body, and the loop ends with a semicolon.
Example – using a do-while loop:
int k = 1;
do {
[Link]("k = " + k);
k++;
} while (k <= 5);
Explanation: This will print k from 1 to 5, similar to the previous loops. The difference is that with do-
while , the check k <= 5 happens after the first iteration. So even if k were initialized to a value
that fails the condition, the loop body would still execute once. For instance, if k started as 6, the do
block would execute once (printing "k = 6"), and only then the condition k <= 5 (now false) would
stop further iterations. This “execute first, check later” behavior is useful for situations where you want
to ensure the loop body runs at least one time, such as menu display prompts or asking for user input
at least once.
Summary of loops: Use for loops when you know the exact count or range of iterations. Use while
loops when the loop should continue until a condition changes (and it might run zero times if the
condition is false initially). Use do-while loops when you need to guarantee the loop runs at least once.
Additionally, Java offers break and continue statements that can alter loop flow: break exits the
loop immediately, and continue skips the rest of the current iteration and goes to the next one.
These are handy in more complex looping scenarios (for example, breaking out of a loop if a certain
condition is met). For basic usage, it’s good to practice writing loops that naturally terminate without
needing these statements.
Functions in Java (Methods)
In Java, what many languages call functions are referred to as methods because they are always
associated with a class (Java is an object-oriented language). A method is a reusable block of code that
performs a specific task. You can pass data (parameters) into methods, and methods can return data as
a result.
Defining and Calling Methods
Defining a Method: A method definition in Java includes: - An access modifier (such as public ,
private – for now, we’ll use public for simplicity or omit it if inside the same class). - A return type
(the data type of the value the method returns; use void if it returns nothing). - A method name
(identifier following Java naming rules, by convention starts with lower-case). - Parameters list in
parentheses (comma-separated, each with a type and name, or empty () if no parameters). - A
method body enclosed in { } , containing the code to execute.
9
Basic syntax example:
[access] [return_type] methodName([type1 param1, type2 param2, ...]) {
// method body
[return value;] // return statement if return_type is not void
}
Example of a simple method definition and usage:
// Define a method that returns the square of an integer
public static int square(int n) {
return n * n; // returns the result of n squared
}
// Define a method that prints a greeting (no return value)
public static void printGreeting(String name) {
[Link]("Hello, " + name + "!");
}
// Inside main method, call the above methods:
public static void main(String[] args) {
int result = square(5); // calling square method with argument 5
[Link]("Square of 5 is: " + result); // prints "Square of 5
is: 25"
printGreeting("Alice"); // calling method, prints "Hello, Alice!"
}
Explanation: We defined two methods: - square(int n) takes an integer n and returns n * n
(an integer). The return statement exits the method and provides a value back to the caller. The
method’s return type is int to match the type of value returned. - printGreeting(String name)
takes a String parameter name and prints a greeting. Its return type is void because it doesn’t
return anything; it just performs an action (printing to console). We simply call
printGreeting("Alice") and it prints the greeting inside the method.
Notice the use of public static in these examples. static means the method belongs to the
class rather than an instance of the class. We used static methods here so that we can call them directly
from the main method (which is also static) without needing to create an object. For a beginner, it's
fine to use static for simple utility methods like these. In object-oriented programming, you would
usually define methods that operate on object instances (non-static), but that requires understanding
classes and objects beyond our current scope.
Calling a Method: To call (invoke) a method, use the method name followed by parentheses containing
any required arguments. If the method returns a value, you can use that value (e.g., assign it to a
variable or print it). If the method is void , just call it as a statement.
10
Parameters and Return Values
Parameters: When you define a method, you specify parameters that act as placeholders for values it
can accept. When calling the method, you provide arguments (actual values) for those parameters. Java
is pass-by-value, meaning that when you pass a variable to a method, the method receives a copy of
that value (for objects, it’s a copy of the reference). For primitive types, this means changes to the
parameter inside the method do not affect the original argument outside the method.
Example to illustrate pass-by-value for primitives:
public static void increment(int num) {
num = num + 1;
[Link]("Inside method, num = " + num);
}
public static void main(String[] args) {
int x = 10;
increment(x);
[Link]("After method call, x = " + x);
}
Output:
Inside method, num = 11
After method call, x = 10
Explanation: We passed x (value 10) to the increment method. Inside the method, num is a copy
of x . We incremented num to 11, but this does not change the original x in main . After the
method returns, x is still 10. This demonstrates that primitives are passed by value. (For object types,
the object reference is passed by value, so a method could modify the state of an object argument, but
cannot replace the object itself that the caller sees. This is an advanced detail — just remember that
Java always uses pass-by-value semantics.)
Return Values: If a method is declared to return a type (not void), it must end with a return
statement returning a value of that type. The caller can then use that returned value. If a method is
void , it does not return anything (and you should not include a return value, though you can use
return; to exit early without a value).
Another example – a method with no parameters and no return (just performs an action):
public static void printTime() {
[Link]("The time is " + [Link]());
}
This method simply prints the current time in milliseconds. You call it as printTime(); and it does its
job without returning anything to the caller.
11
Method Overloading (Brief Mention)
(Java allows multiple methods with the same name but different parameter lists, called method
overloading. For instance, you could have two printGreeting methods if one took no parameters
and one took a String name . The compiler determines which one to call based on the arguments.
This is just a brief mention for completeness; overloading can be useful to provide convenient method
variants.)
Basic Input/Output in Java
Java programs can interact with users or other systems through input and output (I/O). For console-
based programs (text I/O), we typically use Scanner for input and [Link] for output. For a
simple graphical interface, Java provides JOptionPane dialogs. Below, we cover both console I/O and
a brief introduction to GUI I/O.
Console Output (Printing to the Console)
For console output (text displayed to the user in a terminal or command prompt), Java uses the
[Link] stream. The most common methods are:
• [Link](...) – Prints the argument followed by a new line (so the cursor
moves to the next line after printing).
• [Link](...) – Prints the argument without adding a new line (so subsequent
output stays on the same line).
• [Link](...) – Formats output based on a format string (similar to printf in
C). This is more advanced, used for aligning or formatting numbers, etc. For basic usage,
println is usually sufficient.
Example using println and print :
[Link]("Hello ");
[Link]("world");
[Link]("!");
[Link]("Java programming is fun.");
Output:
Hello world!
Java programming is fun.
Explanation: The first two calls to print output text without a newline, so "Hello " and "world"
appear on the same line. The println("!") then prints "!" and adds a newline. The last println
prints the string and adds another newline (so if another print followed, it would appear on a new line).
Console Input with Scanner
To read input from the user via the console, we commonly use the Scanner class (in [Link]
package) which can parse primitive types and strings from an input source like keyboard ([Link]).
12
Setting up a Scanner:
import [Link]; // put this at the top of your file
Scanner scanner = new Scanner([Link]);
This creates a Scanner that reads from standard input (keyboard). The Scanner class has methods
like nextInt() , nextDouble() , nextLine() , etc., to read different types of input.
Example – reading user input from console:
import [Link];
public class ConsoleIOExample {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter your name: ");
String name = [Link](); // reads a full line of text input
[Link]("Enter your age: ");
int age = [Link](); // reads an integer from input
[Link]("Enter your GPA: ");
double gpa = [Link](); // reads a double (for example,
3.5)
// Now use the input values
[Link]("Hello, " + name + "!");
[Link]("In 5 years, you will be " + (age + 5) + " years
old.");
[Link]("Your GPA is " + gpa);
[Link](); // close the scanner when done (releases the
resource)
}
}
Explanation: The program prompts the user and reads three inputs: a string (name), an int (age), and a
double (GPA). We use: - nextLine() to read a line of text (this captures everything the user types until
Enter, including spaces). - nextInt() to read an integer value. - nextDouble() to read a double
(floating-point number). We then output some messages using the collected input. The
[Link] is used for prompts so that the user's input appears on the same line as the
prompt (since print doesn’t add a newline). After inputs are read, we used [Link]
to display results.
We also called [Link]() at the end. This is good practice to free the underlying resource
(the standard input stream). In many simple programs you might omit it (the OS will reclaim resources
13
when the program ends), but it's recommended especially when dealing with files or long-running
programs.
Note: Be cautious when mixing nextInt()/nextDouble() with nextLine() . The numeric
methods don’t consume the newline character after the number, so a subsequent nextLine() may
return an empty string if not handled. A common workaround is to add an extra
[Link]() after reading a number if you plan to read a line next. In our sequence above,
we read the line first and then numeric values, which avoids that issue.
GUI Input/Output with JOptionPane (Simple Dialogs)
Java Swing’s JOptionPane class provides simple pop-up dialog boxes for input and output, useful for
quick GUI interactions without building a full user interface.
• Input Dialog: [Link] prompts the user with a dialog box that asks
for input and returns the input as a String.
• Message Dialog: [Link] displays a message to the user in a
dialog box.
These are part of the [Link] package. (No need for manual GUI setup; JOptionPane handles
it internally.)
Example – asking for user input with a dialog and showing a message:
import [Link];
public class DialogExample {
public static void main(String[] args) {
// Prompt the user for their name
String name = [Link]("What is your name?");
// Show a greeting message
[Link](null, "Hello, " + name + "! Welcome to
Java.");
}
}
When this code runs, a small window will pop up asking “What is your name?” with a text field. The user
enters their name and clicks OK. The showInputDialog method returns the input as a String
which we store in name . Then we call showMessageDialog to display a greeting. The first argument
null means the dialog has no parent window (it will center on screen). The second argument is the
message to display.
By default, showMessageDialog displays an information icon. We could also specify message type or
title by using an overloaded version of the method, but for simplicity we used the basic one.
Note: showInputDialog always returns a string. If the user needs to input numbers, you will get
them as a string and need to convert them. For example, to get an integer:
14
String input = [Link]("Enter your age:");
int age = [Link](input); // convert the String to int
Be mindful that if the input is not a valid number, [Link] will throw an exception. Error
handling can be added, but that is beyond this basic introduction.
JOptionPane is useful for quick scripts or learning purposes to avoid using the console. However,
building robust GUI applications would involve more advanced GUI frameworks or libraries.
Conclusion
In this guide, we covered fundamental Java topics: - Primitive types (int, double, char, boolean, etc.),
variables, and operators, which are the basic building blocks for calculations and logic. - Arrays, which
allow grouping multiple values, and how to use loops to traverse them. - Control flow statements like
conditionals ( if/else , switch ) to make decisions, and loops ( for , while , do-while ) to
repeat tasks. - Functions (methods) in Java, how to define reusable code blocks, pass parameters, and
return values. - Basic Input/Output techniques, both via the console (Scanner for input, [Link] for
output) and simple GUI dialogs (JOptionPane).
All examples given are commented and written in a beginner-friendly manner. With these core
concepts, you have the toolkit to start writing simple interactive Java programs. As you progress, you’ll
build on these fundamentals to explore object-oriented programming (classes, objects), data structures,
and more complex Java features. Happy coding!
15