Java_prac[1]
Java_prac[1]
Unit 1:
1. Design a Java program that uses various data types and operators to
perform a calculation
2. What are the rules for naming variables in Java?
🔍 Example Code:
java
CopyEdit
public class Hello {
public static void main(String[] args) {
System.out.println("Hello Java");
}
}
Tokens in this example:
public, class, Hello, {, static, void, main, String, args, [], System, ., out, .,
println, ("Hello Java"), ;, }
✅ Conclusion:
Java tokens are essential elements that form the structure of a Java
program. The compiler uses these tokens to understand and compile the
code properly.
4. Demonstrate how to use input and output streams in
a Java program.
In Java, streams are used for handling input (reading data) and output
(writing data). Streams are like pipes through which data flows. Java
provides these features in the java.io package.
There are two types of streams:
Input Stream: Used to take input (data goes into the program).
→ Example: System.in, FileInputStream
Output Stream: Used to display output (data goes out of the
program).
→ Example: System.out, FileOutputStream
Java provides three default stream objects:
System.in → takes input from keyboard
System.out → prints output to screen
System.err → shows error messages
✅ Explanation:
System.in.read() reads one character as a number (ASCII value).
System.out.write(ch) prints the same character to the screen.
Example: If user types A, it will print You entered: A.
This is the simplest way to demonstrate both input stream and output
stream using System.in and System.out.
✅ Conclusion:
Input and Output streams in Java are essential for interacting with users
and files. Using System.in.read() and System.out.write(), we can perform
basic I/O operations. This helps in understanding the basic working of data
flow in a Java program
✅ Explanation:
int[] marks declares an array of 5 integers.
marks.length gives the size of the array.
A for loop is used to read and update elements.
This program increases each student’s marks by 5 and displays the
updated list.
✅ Output:
yaml
CopyEdit
Original Marks:
65 70 75 80 85
Updated Marks:
70 75 80 85 90
✅ Conclusion:
Arrays are helpful when we need to store multiple values. This program
clearly shows how to declare, access, update, and print array values. It
demonstrates basic array manipulation in a beginner-friendly and exam-
appropriate way.
Unit 3:
1 . Assess the importance of exception handling in Java. What are the
consequences of not handling exceptions?
2. What are Java packages, and why are they used?
3. . Design a multi-threaded Java application that demonstrates thread
synchronization.
4. Explain the concept of thread priority and how it affects thread
execution.
.5. Create a Java application that handles exceptions and demonstrates
various error handling techniques.
6. . Justify the need for synchronization in multi-threaded applications.
What issues can arise without it?
Unit 4:
1. Explain how to create and use a popup menu in a Java application.
2.Describe how to handle AWT events in a Java application.
3.Analyze the role of layout managers in Java GUI applications. How do
they affect component arrangement?
4. Demonstrate how to display an image in a Java GUI application
.5. What are the different types of components available in AWT?
6. . Explain the concept of event listeners and their role in event handling.
7. create a java program using switch case .
Application based (use college notes ) :
1.Food order system using jcheckbox
2. Then find ip address
3. Then create calculator + addition and subtraction