0% found this document useful (0 votes)
3 views2 pages

Java Top3 Easy Programs

The document outlines three easy Java programming exercises for quick revision: creating a Student class to display an object's properties, using a static method to print a welcome message without instantiating an object, and demonstrating an ArithmeticException using a try-catch block. Each example highlights the simplicity of the concepts involved, making them suitable for beginners. Additionally, it provides a tip on naming conventions for Java files and how to compile and run them.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Top3 Easy Programs

The document outlines three easy Java programming exercises for quick revision: creating a Student class to display an object's properties, using a static method to print a welcome message without instantiating an object, and demonstrating an ArithmeticException using a try-catch block. Each example highlights the simplicity of the concepts involved, making them suitable for beginners. Additionally, it provides a tip on naming conventions for Java files and how to compile and run them.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

■ Java Internal Exam – Top 3 Easiest Programs

Prepared for Quick Revision | Good Luck! ■

#1 Q1. Student Class with id, name – Display using Object

■ Why Easy: Just one class, two variables, one object — basic OOP basics.
class Student {
int id;
String name;

void display() {
[Link]("ID: " + id);
[Link]("Name: " + name);
}

public static void main(String[] args) {


Student s = new Student();
[Link] = 101;
[Link] = "Rahul";
[Link]();
}
}

#2 Q2. Static Method – Print Welcome Message Without Creating Object

■ Why Easy: Single class, one static method, called directly via class name.
class Welcome {
static void greet() {
[Link]("Welcome to Java Programming!");
}

public static void main(String[] args) {


[Link]();
}
}

#3 Q7. Try-Catch Block – Demonstrate ArithmeticException

■ Why Easy: Just divide by zero inside try, catch prints error — 8 lines total.
class TryCatchDemo {
public static void main(String[] args) {
try {
int a = 10, b = 0;
int result = a / b;
[Link]("Result: " + result);
} catch (ArithmeticException e) {
[Link]("Error: " + [Link]());
}
}
}

■ Exam Tip: Write class name = filename, compile with javac [Link], run with java
FileName

You might also like