Java Programming Comprehensive Tutorial for
Internal Exam
Data Types in Java
Primitive Data Types
Java has 8 primitive data types that store simple values directly in memory: [1] [2] [3]
Numeric Types
byte: 8-bit signed integer (-128 to 127) [3]
short: 16-bit signed integer (-32,768 to 32,767)
int: 32-bit signed integer (-2³¹ to 2³¹-1)
long: 64-bit signed integer (-2⁶³ to 2⁶³-1)
float: 32-bit floating point
double: 64-bit floating point (default for decimals)
Non-Numeric Types
char: 16-bit Unicode character
boolean: true or false values [3]
Reference Data Types
Reference types store memory addresses of objects, not the actual values: [4] [1]
String: Sequence of characters
Arrays: Collection of elements of same type
Classes and Objects: User-defined types
Interfaces: Abstract contracts
Key Differences Between Primitive and Reference Types
Property Primitive Types Reference Types
Storage Stack memory (actual values) Heap memory (objects), Stack (references) [1]
Default Value 0, false, '\u0000' null [2]
Property Primitive Types Reference Types
Memory Usage Fixed size Variable size
Assignment Copies value Copies reference [1]
Example Program: Data Types
public class DataTypesDemo {
public static void main(String[] args) {
// Primitive types
byte age = 25;
int salary = 50000;
double height = 5.8;
char grade = 'A';
boolean isEmployed = true;
// Reference types
String name = "John Doe";
int[] scores = {85, 90, 78, 92};
[Link]("Name: " + name);
[Link]("Age: " + age);
[Link]("Salary: " + salary);
[Link]("Height: " + height);
[Link]("Grade: " + grade);
[Link]("Employed: " + isEmployed);
[Link]("Scores: " + [Link](scores));
}
}
Control Structures
Decision Making Statements
1. if Statement
Tests a single condition: [5] [6]
public class IfExample {
public static void main(String[] args) {
int marks = 85;
if (marks >= 80) {
[Link]("Excellent!");
}
}
}
2. if-else Statement
Provides two-way decision making: [6] [5]
public class IfElseExample {
public static void main(String[] args) {
int age = 17;
if (age >= 18) {
[Link]("You can vote!");
} else {
[Link]("You cannot vote yet.");
}
}
}
3. if-else-if Ladder
Multiple condition checking: [5]
public class GradeCalculator {
public static void main(String[] args) {
int marks = 78;
if (marks >= 90) {
[Link]("Grade: A+");
} else if (marks >= 80) {
[Link]("Grade: A");
} else if (marks >= 70) {
[Link]("Grade: B");
} else if (marks >= 60) {
[Link]("Grade: C");
} else {
[Link]("Grade: F");
}
}
}
4. switch Statement
Tests exact value matching: [7] [5]
public class SwitchExample {
public static void main(String[] args) {
int day = 3;
String dayName;
switch (day) {
case 1:
dayName = "Monday";
break;
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
dayName = "Thursday";
break;
case 5:
dayName = "Friday";
break;
default:
dayName = "Weekend";
}
[Link]("Today is: " + dayName);
}
}
Looping Statements
1. for Loop
Used when number of iterations is known: [8]
public class ForLoopExample {
public static void main(String[] args) {
// Print numbers 1 to 10
for (int i = 1; i <= 10; i++) {
[Link](i + " ");
}
[Link]();
// Enhanced for loop (for arrays)
int[] numbers = {10, 20, 30, 40, 50};
for (int num : numbers) {
[Link](num + " ");
}
}
}
2. while Loop
Executes while condition is true: [9] [10]
public class WhileLoopExample {
public static void main(String[] args) {
int i = 1;
int sum = 0;
while (i <= 10) {
sum += i;
i++;
}
[Link]("Sum of 1 to 10: " + sum);
}
}
3. do-while Loop
Executes at least once, then checks condition: [11] [9] [8]
public class DoWhileExample {
public static void main(String[] args) {
int num;
Scanner scanner = new Scanner([Link]);
do {
[Link]("Enter a positive number (0 to exit): ");
num = [Link]();
if (num > 0) {
[Link]("You entered: " + num);
}
} while (num != 0);
[Link]("Program ended");
}
}
Strings in Java
String Class Methods
String is immutable in Java. Common methods include: [12] [13] [14]
Method Description Example
length() Returns string length "Hello".length() → 5
charAt(int index) Returns character at index "Hello".charAt(1) → 'e'
substring(int start) Returns substring from start "Hello".substring(2) → "llo"
substring(int start, int Returns substring from start
"Hello".substring(1,4) → "ell"
end) to end-1
Returns first occurrence
indexOf(String str) "Hello".indexOf("ll") → 2
index
"Hello".concat(" World") → "Hello
concat(String str) Concatenates strings
World"
equals(Object obj) Compares string content "Hello".equals("Hello") → true
Method Description Example
Removes leading/trailing
trim() " Hello ".trim() → "Hello"
spaces
replace(char old, char "Hello".replace('l','x') →
Replaces characters
new) "Hexxo"
Checks if string contains
contains(CharSequence s) "Hello".contains("ell") → true
sequence
String Example Program
public class StringMethodsDemo {
public static void main(String[] args) {
String str = " Hello World ";
[Link]("Original: '" + str + "'");
[Link]("Length: " + [Link]());
[Link]("Trimmed: '" + [Link]() + "'");
[Link]("Upper case: " + [Link]());
[Link]("Lower case: " + [Link]());
String trimmed = [Link]();
[Link]("Character at index 6: " + [Link](6));
[Link]("Substring (0,5): " + [Link](0, 5));
[Link]("Index of 'World': " + [Link]("World"));
[Link]("Replace 'o' with '*': " + [Link]('o', '*'));
[Link]("Contains 'Hello': " + [Link]("Hello"));
// String concatenation
String first = "Hello";
String second = "World";
String combined = [Link](" ").concat(second);
[Link]("Concatenated: " + combined);
}
}
Vector in Java
Vector is a dynamic array that can grow and shrink automatically. It's synchronized and thread-
safe. [15] [16] [17] [18]
Vector Declaration and Initialization
import [Link];
public class VectorExample {
public static void main(String[] args) {
// Different ways to create Vector
Vector<Integer> vector1 = new Vector<>();
Vector<String> vector2 = new Vector<>(10); // Initial capacity
Vector<Integer> vector3 = new Vector<>(5, 2); // Initial capacity, increment
}
}
Common Vector Methods
Method Description Example
add(E element) Adds element to end [Link](10)
add(int index, E element) Inserts element at index [Link](2, 15)
remove(int index) Removes element at index [Link](0)
get(int index) Returns element at index [Link](1)
set(int index, E element) Replaces element at index [Link](0, 20)
size() Returns number of elements [Link]()
contains(Object o) Checks if element exists [Link](10)
elementAt(int index) Returns element at index [Link](2)
firstElement() Returns first element [Link]()
lastElement() Returns last element [Link]()
Vector Example Program
import [Link];
public class VectorDemo {
public static void main(String[] args) {
Vector<String> fruits = new Vector<>();
// Adding elements
[Link]("Apple");
[Link]("Banana");
[Link]("Orange");
[Link]("Mango");
[Link]("Initial Vector: " + fruits);
[Link]("Size: " + [Link]());
// Accessing elements
[Link]("First element: " + [Link]());
[Link]("Element at index 2: " + [Link](2));
[Link]("Last element: " + [Link]());
// Modifying elements
[Link](1, "Grapes");
[Link]("After replacing index 1: " + fruits);
// Inserting element
[Link](2, "Pineapple");
[Link]("After inserting at index 2: " + fruits);
// Removing elements
[Link]("Orange");
[Link]("After removing Orange: " + fruits);
// Checking if element exists
if ([Link]("Apple")) {
[Link]("Apple is present in the vector");
}
// Iterating through vector
[Link]("All fruits: ");
for (String fruit : fruits) {
[Link](fruit + " ");
}
}
}
Classes and Objects
Class Declaration and Object Creation
A class is a blueprint for creating objects: [19] [20] [21]
public class Student {
// Instance variables (attributes)
private String name;
private int age;
private double gpa;
// Default constructor
public Student() {
[Link] = "Unknown";
[Link] = 0;
[Link] = 0.0;
}
// Parameterized constructor
public Student(String name, int age, double gpa) {
[Link] = name;
[Link] = age;
[Link] = gpa;
}
// Copy constructor
public Student(Student other) {
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
}
// Getter methods
public String getName() {
return name;
}
public int getAge() {
return age;
}
public double getGpa() {
return gpa;
}
// Setter methods
public void setName(String name) {
[Link] = name;
}
public void setAge(int age) {
if (age > 0) {
[Link] = age;
}
}
public void setGpa(double gpa) {
if (gpa >= 0.0 && gpa <= 4.0) {
[Link] = gpa;
}
}
// Method to display student information
public void displayInfo() {
[Link]("Name: " + name);
[Link]("Age: " + age);
[Link]("GPA: " + gpa);
}
// Method to check if student has honors
public boolean hasHonors() {
return gpa >= 3.5;
}
}
// Main class to test Student class
public class StudentTest {
public static void main(String[] args) {
// Creating objects using different constructors
Student student1 = new Student();
Student student2 = new Student("Alice Johnson", 20, 3.8);
Student student3 = new Student(student2); // Copy constructor
// Display information
[Link]("Student 1:");
[Link]();
[Link]("Has honors: " + [Link]());
[Link]("\nStudent 2:");
[Link]();
[Link]("Has honors: " + [Link]());
// Modify student1 using setters
[Link]("Bob Smith");
[Link](22);
[Link](3.2);
[Link]("\nStudent 1 after modification:");
[Link]();
}
}
Constructor Types
1. Default Constructor: No parameters, provides default values [21]
2. Parameterized Constructor: Takes parameters to initialize object with specific values [21]
3. Copy Constructor: Creates object by copying another object [22] [21]
Inheritance
Inheritance allows a class to inherit properties and methods from another class using the extends
keyword: [23] [24] [25]
Basic Inheritance Example
// Base class (Superclass)
class Vehicle {
protected String brand;
protected String color;
protected int year;
public Vehicle() {
[Link] = "Unknown";
[Link] = "Unknown";
[Link] = 0;
}
public Vehicle(String brand, String color, int year) {
[Link] = brand;
[Link] = color;
[Link] = year;
}
public void start() {
[Link](brand + " vehicle is starting...");
}
public void stop() {
[Link](brand + " vehicle has stopped.");
}
public void displayInfo() {
[Link]("Brand: " + brand);
[Link]("Color: " + color);
[Link]("Year: " + year);
}
}
// Derived class (Subclass)
class Car extends Vehicle {
private int numberOfDoors;
private String transmissionType;
public Car() {
super(); // Call parent constructor
[Link] = 4;
[Link] = "Manual";
}
public Car(String brand, String color, int year, int doors, String transmission) {
super(brand, color, year); // Call parameterized parent constructor
[Link] = doors;
[Link] = transmission;
}
// Method overriding
@Override
public void start() {
[Link]("Car engine is starting with ignition key...");
}
// Additional method specific to Car
public void honk() {
[Link]("Car is honking: Beep! Beep!");
}
@Override
public void displayInfo() {
[Link](); // Call parent method
[Link]("Doors: " + numberOfDoors);
[Link]("Transmission: " + transmissionType);
}
}
// Another derived class
class Motorcycle extends Vehicle {
private boolean hasSidecar;
public Motorcycle(String brand, String color, int year, boolean sidecar) {
super(brand, color, year);
[Link] = sidecar;
}
@Override
public void start() {
[Link]("Motorcycle is starting with kick/electric start...");
}
public void wheelie() {
[Link]("Motorcycle is doing a wheelie!");
}
@Override
public void displayInfo() {
[Link]();
[Link]("Has Sidecar: " + hasSidecar);
}
}
// Test class
public class InheritanceDemo {
public static void main(String[] args) {
// Create objects
Vehicle vehicle = new Vehicle("Generic", "White", 2020);
Car car = new Car("Toyota", "Red", 2022, 4, "Automatic");
Motorcycle bike = new Motorcycle("Harley-Davidson", "Black", 2021, false);
[Link]("=== Vehicle ===");
[Link]();
[Link]();
[Link]();
[Link]("\n=== Car ===");
[Link]();
[Link]();
[Link]();
[Link]();
[Link]("\n=== Motorcycle ===");
[Link]();
[Link]();
[Link]();
[Link]();
// Polymorphism example
[Link]("\n=== Polymorphism ===");
Vehicle[] vehicles = {vehicle, car, bike};
for (Vehicle v : vehicles) {
[Link](); // Different implementations called
}
}
}
The super Keyword
The super keyword is used to: [23]
Call parent class constructor
Access parent class methods
Access parent class variables
class Parent {
String message = "Parent message";
public void display() {
[Link]("Parent display method");
}
}
class Child extends Parent {
String message = "Child message";
public void display() {
[Link](); // Call parent method
[Link]("Child display method");
[Link]("Parent message: " + [Link]);
[Link]("Child message: " + [Link]);
}
}
Packages and Import Statements
Packages group related classes and interfaces together: [26] [27] [28] [29]
Package Declaration and Import
// File: com/company/utils/[Link]
package [Link];
public class MathHelper {
public static int add(int a, int b) {
return a + b;
}
public static int multiply(int a, int b) {
return a * b;
}
public static double calculateCircleArea(double radius) {
return [Link] * radius * radius;
}
}
// File: com/company/main/[Link]
package [Link];
import [Link]; // Import specific class
import [Link].*; // Import all classes from util package
import static [Link].*; // Static import
public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Using imported class
int result1 = [Link](10, 5);
// Using static import (no class name needed)
int result2 = multiply(8, 4);
[Link]("Addition result: " + result1);
[Link]("Multiplication result: " + result2);
// Using imported Scanner
[Link]("Enter radius: ");
double radius = [Link]();
double area = calculateCircleArea(radius);
[Link]("Circle area: " + area);
}
}
Types of Import
1. Import specific class: import [Link];
2. Import all classes: import [Link].*;
3. Static import: import static [Link].*;
Exception Handling
Exception handling manages runtime errors to maintain program flow: [30] [31] [32] [33] [34]
Try-Catch-Finally Block
import [Link].*;
import [Link];
public class ExceptionHandlingDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Example 1: ArithmeticException
try {
[Link]("Enter first number: ");
int a = [Link]();
[Link]("Enter second number: ");
int b = [Link]();
int result = a / b;
[Link]("Result: " + result);
} catch (ArithmeticException e) {
[Link]("Error: Cannot divide by zero!");
[Link]("Exception message: " + [Link]());
} catch (Exception e) {
[Link]("An unexpected error occurred: " + [Link]());
} finally {
[Link]("Division operation completed.");
}
// Example 2: ArrayIndexOutOfBoundsException
try {
int[] numbers = {10, 20, 30, 40, 50};
[Link]("Enter array index (0-4): ");
int index = [Link]();
[Link]("Value at index " + index + ": " + numbers[index]);
} catch (ArrayIndexOutOfBoundsException e) {
[Link]("Error: Array index out of bounds!");
}
// Example 3: NumberFormatException
try {
[Link]("Enter a number as string: ");
String numberStr = [Link]();
int number = [Link](numberStr);
[Link]("Parsed number: " + number);
} catch (NumberFormatException e) {
[Link]("Error: Invalid number format!");
}
// Example 4: NullPointerException
try {
String str = null;
[Link]("String length: " + [Link]());
} catch (NullPointerException e) {
[Link]("Error: String is null!");
}
// Example 5: File handling with multiple exceptions
String filename = "[Link]";
FileReader fileReader = null;
BufferedReader bufferedReader = null;
try {
fileReader = new FileReader(filename);
bufferedReader = new BufferedReader(fileReader);
String line;
while ((line = [Link]()) != null) {
[Link](line);
}
} catch (FileNotFoundException e) {
[Link]("Error: File '" + filename + "' not found!");
} catch (IOException e) {
[Link]("Error: Problem reading file!");
} finally {
// Clean up resources
try {
if (bufferedReader != null) {
[Link]();
}
if (fileReader != null) {
[Link]();
}
} catch (IOException e) {
[Link]("Error closing file resources!");
}
}
[Link]();
}
}
Custom Exception Example
// Custom exception class
class InvalidAgeException extends Exception {
public InvalidAgeException(String message) {
super(message);
}
}
class Person {
private String name;
private int age;
public Person(String name, int age) throws InvalidAgeException {
[Link] = name;
setAge(age);
}
public void setAge(int age) throws InvalidAgeException {
if (age < 0 || age > 150) {
throw new InvalidAgeException("Age must be between 0 and 150. Got: " + age);
}
[Link] = age;
}
public void displayInfo() {
[Link]("Name: " + name + ", Age: " + age);
}
}
public class CustomExceptionDemo {
public static void main(String[] args) {
try {
Person person1 = new Person("Alice", 25);
[Link]();
Person person2 = new Person("Bob", -5); // This will throw exception
[Link]();
} catch (InvalidAgeException e) {
[Link]("Custom Exception caught: " + [Link]());
}
try {
Person person3 = new Person("Charlie", 30);
[Link](200); // This will throw exception
} catch (InvalidAgeException e) {
[Link]("Custom Exception caught: " + [Link]());
}
}
}
Exception Hierarchy
Throwable (top-level class)
Error (serious system errors)
Exception
RuntimeException (unchecked exceptions)
ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException
Checked Exceptions
IOException, ClassNotFoundException, SQLException
Multithreaded Programming
Multithreading allows concurrent execution of multiple threads: [35] [36] [37]
Thread Creation Methods
Method 1: Extending Thread Class
class NumberPrinter extends Thread {
private String threadName;
private int start;
private int end;
public NumberPrinter(String name, int start, int end) {
[Link] = name;
[Link] = start;
[Link] = end;
}
@Override
public void run() {
[Link](threadName + " started");
for (int i = start; i <= end; i++) {
[Link](threadName + ": " + i);
try {
[Link](500); // Pause for 500ms
} catch (InterruptedException e) {
[Link](threadName + " interrupted");
return;
}
}
[Link](threadName + " completed");
}
}
public class ThreadExtendExample {
public static void main(String[] args) {
// Create and start threads
NumberPrinter thread1 = new NumberPrinter("Thread-1", 1, 5);
NumberPrinter thread2 = new NumberPrinter("Thread-2", 6, 10);
[Link]();
[Link]();
// Wait for threads to complete
try {
[Link]();
[Link]();
} catch (InterruptedException e) {
[Link]("Main thread interrupted");
}
[Link]("Main thread completed");
}
}
Method 2: Implementing Runnable Interface
class TaskRunner implements Runnable {
private String taskName;
private int iterations;
public TaskRunner(String name, int iterations) {
[Link] = name;
[Link] = iterations;
}
@Override
public void run() {
[Link](taskName + " started by " + [Link]().getName());
for (int i = 1; i <= iterations; i++) {
[Link](taskName + " - Iteration " + i +
" [" + [Link]().getName() + "]");
try {
[Link](300);
} catch (InterruptedException e) {
[Link](taskName + " interrupted");
return;
}
}
[Link](taskName + " completed");
}
}
public class RunnableExample {
public static void main(String[] args) {
// Create Runnable objects
TaskRunner task1 = new TaskRunner("Download-Task", 3);
TaskRunner task2 = new TaskRunner("Upload-Task", 4);
TaskRunner task3 = new TaskRunner("Processing-Task", 2);
// Create Thread objects
Thread thread1 = new Thread(task1);
Thread thread2 = new Thread(task2);
Thread thread3 = new Thread(task3);
// Set thread names
[Link]("Downloader");
[Link]("Uploader");
[Link]("Processor");
// Start threads
[Link]();
[Link]();
[Link]();
[Link]("All threads started from main thread");
}
}
Thread Synchronization
Synchronization prevents race conditions when multiple threads access shared resources: [38]
[39] [40]
class BankAccount {
private double balance;
private String accountHolder;
public BankAccount(String holder, double initialBalance) {
[Link] = holder;
[Link] = initialBalance;
}
// Synchronized method for deposits
public synchronized void deposit(double amount) {
[Link]([Link]().getName() +
" attempting to deposit $" + amount);
double oldBalance = balance;
try {
[Link](100); // Simulate processing time
} catch (InterruptedException e) {
return;
}
balance = oldBalance + amount;
[Link]([Link]().getName() +
" deposited $" + amount +
". New balance: $" + balance);
}
// Synchronized method for withdrawals
public synchronized void withdraw(double amount) {
[Link]([Link]().getName() +
" attempting to withdraw $" + amount);
if (balance >= amount) {
double oldBalance = balance;
try {
[Link](100); // Simulate processing time
} catch (InterruptedException e) {
return;
}
balance = oldBalance - amount;
[Link]([Link]().getName() +
" withdrew $" + amount +
". New balance: $" + balance);
} else {
[Link]([Link]().getName() +
" - Insufficient funds. Current balance: $" + balance);
}
}
public synchronized double getBalance() {
return balance;
}
}
class BankTransaction implements Runnable {
private BankAccount account;
private String operation;
private double amount;
public BankTransaction(BankAccount account, String operation, double amount) {
[Link] = account;
[Link] = operation;
[Link] = amount;
}
@Override
public void run() {
if ([Link]("deposit")) {
[Link](amount);
} else if ([Link]("withdraw")) {
[Link](amount);
}
}
}
public class SynchronizationDemo {
public static void main(String[] args) {
BankAccount account = new BankAccount("John Doe", 1000.0);
[Link]("Initial balance: $" + [Link]());
// Create multiple transactions
Thread t1 = new Thread(new BankTransaction(account, "deposit", 200), "Customer-1"
Thread t2 = new Thread(new BankTransaction(account, "withdraw", 150), "Customer-2
Thread t3 = new Thread(new BankTransaction(account, "deposit", 300), "Customer-3"
Thread t4 = new Thread(new BankTransaction(account, "withdraw", 500), "Customer-4
Thread t5 = new Thread(new BankTransaction(account, "withdraw", 800), "Customer-5
// Start all threads
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
// Wait for all threads to complete
try {
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
} catch (InterruptedException e) {
[Link]("Main thread interrupted");
}
[Link]("Final balance: $" + [Link]());
}
}
Synchronized Blocks
class Counter {
private int count = 0;
private final Object lock = new Object();
public void increment() {
synchronized(lock) {
count++;
[Link]([Link]().getName() +
" incremented count to: " + count);
}
}
public void decrement() {
synchronized(this) { // Using this object as lock
if (count > 0) {
count--;
[Link]([Link]().getName() +
" decremented count to: " + count);
}
}
}
public int getCount() {
synchronized(lock) {
return count;
}
}
}
Practice Questions
Multiple Choice Questions
1. Which of these is NOT a primitive data type in Java?
a) int
b) String
c) boolean
d) char
Answer: b) String (String is a reference type) [3]
2. What will be the output of the following code?
int x = 10;
if (x > 5)
if (x < 15)
[Link]("A");
else
[Link]("B");
a) A
b) B
c) AB
d) No output
Answer: a) A
3. Which loop executes at least once?
a) for
b) while
c) do-while
d) enhanced for
Answer: c) do-while [41]
4. What is the difference between == and equals() for Strings?
a) No difference
b) == compares references, equals() compares content
c) == compares content, equals() compares references
d) Both compare content
Answer: b) == compares references, equals() compares content
5. Which keyword is used for inheritance in Java?
a) inherits
b) extends
c) implements
d) super
Answer: b) extends [25]
Programming Questions
Question 1: Grade Calculator
Write a Java program that takes student marks as input and displays the grade based on the
following criteria:
90-100: A+
80-89: A
70-79: B
60-69: C
Below 60: F
Question 2: String Manipulation
Create a program that:
1. Takes a string input from user
2. Displays string length, first character, last character
3. Converts to uppercase and lowercase
4. Checks if string contains "java" (case-insensitive)
Question 3: Vector Operations
Write a program that creates a Vector of integers and performs:
1. Add 5 elements
2. Display all elements
3. Remove element at index 2
4. Insert element at index 1
5. Display final vector
Question 4: Bank Account Class
Design a BankAccount class with:
Private attributes: accountNumber, balance, accountHolderName
Constructors: default and parameterized
Methods: deposit(), withdraw(), displayBalance()
Proper validation for withdraw (sufficient balance check)
Question 5: Exception Handling
Create a program that handles multiple exceptions:
1. Division by zero
2. Array index out of bounds
3. Number format exception
4. Use try-catch-finally blocks appropriately
Question 6: Thread Example
Write a program that creates two threads:
Thread 1: Prints even numbers 2, 4, 6, 8, 10
Thread 2: Prints odd numbers 1, 3, 5, 7, 9
Use [Link]() to add delays
This comprehensive tutorial covers all the topics in your Java exam syllabus with detailed
explanations, examples, and practice questions. Each section builds upon previous concepts
and includes real-world programming scenarios to help you understand both theoretical
concepts and practical applications.
⁂
1. [Link]
2. [Link]
-types
3. [Link]
4. [Link]
5. [Link]
6. [Link]
7. [Link]
8. [Link]
9. [Link]
10. [Link]
11. [Link]
12. [Link]
13. [Link]
14. [Link]
15. [Link]
16. [Link]
17. [Link]
18. [Link]
19. [Link]
20. [Link]
21. [Link]
22. [Link]
23. [Link]
24. [Link]
25. [Link]
26. [Link]
27. [Link]
28. [Link]
29. [Link]
30. [Link]
31. [Link]
32. [Link]
33. [Link]
34. [Link]
35. [Link]
36. [Link]
37. [Link]
38. [Link]
39. [Link]
40. [Link]
41. [Link]
42. [Link]
43. [Link]
44. [Link]
45. [Link]
46. [Link]
47. [Link]
48. [Link]
49. [Link]
50. [Link]
51. [Link]
52. [Link]
53. [Link]
54. [Link]
55. [Link]
56. [Link]