JAVA Questions for exam| 100 Java notes Interview Questions | Java Internship Questions | Bsc CSIT Course Java Questions | Java advance questions with solution | Learn java from hello world |Csit Exam questions with solution |

Table of Contents

Chapter-wise Java Questions

Unit 1: Programming in Java

Unit #1.2

1) An array is called balanced if it’s even numbered elements (a[0], a[2], etc.) are even and its odd numbered elements (a[1], a[3], etc.) are odd. Write a function named balanced that accepts an array of integers which returns 1 if the array is balanced and returns 0 otherwise.[answer]
2) Write an object oriented program to find area and perimeter of rectangle.[answer]
3) Write a program to input and add two numbers using static methods (procedural programming).[answer]
4) Write a program to input principle, time and rate, then calculate simple interest using static methods.[answer]
5) Write both procedural and object oriented programs to calculate the area of a
a) Circle
b) Square
c) Rectangle
d) Sphere [answer1] [answer2]
6) Write a static method to calculate the sum of a one dimensional array.[answer]
7) Write a static method to calculate the average of a one dimensional array.[answer]
8) Create a class with static methods to calculate the sum, difference and product of two matrices (represented by 2D arrays). The methods must return the resulting matrices. [answer]
9) Write a program to demonstrate encapsulation.[answer]
10) Write a program to demonstrate inheritance.[answer]
11) Write a program to demonstrate polymorphism using non-abstract class as parent. [answer]
12) Write a program to demonstrate polymorphism using abstract class as parent.[answer]
13) Write a program to demonstrate polymorphism using interface as parent.[answer]
14) Write a program to create two classes Circle and Square, with appropriate fields and methods, in a package name shape. Create a separate class ShapeDemo to test the classes. [answer]

Unit #1.3

1) Write a program to demonstrate try-catch-finally. [Answer]
2) Write a program to demonstrate try-finally. [Answer]
3) Write a program to create two threads. The first thread should print numbers from 1 to 10 at intervals of 0.5 second and the second thread should print numbers from 11 to 20 at the interval of 1 second. [ Answer ]
4) Write a program to execute multiple threads in priority base. [ Answer ]

Unit #1.4


1) Write the simple java program that reads data from one file and writes data to another file.
2) Write a program to duplicate each character in a text file and write the output in a separate file using
character stream.
e.g.
source.txt
apple
destination.txt
aappppllee
3) Write a program to read records from a text file which contains people’s name, principle, rate and
time values. Calculate simple interest and write all the contents of the source file along with simple
interest to destination file.
source.txt
John 10000 10.5 2.5
Jane 5000 9.25 5.0
destination.txt
John 10000 10.5 2.5 2625.00
Jane 5000 9.25 5.0 2312.50
4) Write a program to read the contents of a file one line at a time and output them to the screen.
5) Write a program to input whole lines from the keyboard and write them to a file. Exit the program
when the user types “quit”.

Unit 2, 3: User Interface Components with Swing, Event Handling

1) Write a program using components to add two numbers. Use text fields. For inputs and output. Your program should display the result when the user presses a button.
2) Write a program using swing components to multiply two numbers. Use text fields for inputs and output. Your program should display the result when the user presses a button.
3) Write a program using swing components to find simple interest. Use text fields for inputs and output. Your program should display the result when the user presses a button.
4) Design a GUI form using swing with a text field, a text label for displaying the input message “Input any string”, and three buttons with caption “Check Palindrome”, “Reverse”, “Find Vowels”. Write a complete program for above scenario and for checking palindrome in first button, reverse it after clicking second button and extract the vowels from it after clicking third button.
5) Write a program to illustrate the use of BorderLayout.
6) Write a program to calculate simple interest using
a) FlowLayout
b) GridLayout
c) GridBagLayout
7) Create a login form with username and password fields. Print “access granted” if the username and password both are “admin”, when user clicks on Login button. If authentication fails, print “access denied”.
8) (Optional) Create a basic notepad app with the following features:
a) New
b) Open
c) Save
d) Exit
Use JButton components to implement these features.
9) Create an application with UI similar to the windows notepad app.
10) Create the UI for tic-tac-toe app using JButton array and GridLayout.
11) Demonstrate the use of Open and Save dialogs for opening and saving files.
12) Create a simple app with menus. Include a menu item inside the Help menu to show a custom dialog named AboutDialog. The dialog must contain your App name, version and copyright information, along with a working close button (JButton).
13) Create a form using JFrame to collect the records of students in Trinity. Each record should contain
the following information:
a) First Name (JTextField)
b) Last Name (JTextField)
c) Age (JTextField)
d) Gender (JRadioButton)
e) Faculty (JComboBox/JList)
f) Semester (JComboBox/JList)
g) Remarks (JTextArea)
Add both menus and toolbars to save the form to a file (display a save dialog). Also add menu/toolbar items to reset the form as well as exit the program. Remember to close the file on exit command.

Unit 4: Database Connectivity

1) Write a Java program using JDBC to extract name of those students who live in Kathmandu district,assuming that the student table has four attributes (ID, name, district, and age).[answer]
2) Write a program to illustrate the process of executing SQL statements in JDBC? [answer]
3) Implement CRUD (Create/Insert, Read/Select, Update, Delete) operations for student table. Ask for user input where applicable. [answer]
4) Implement CRUD operations for student table using prepared statements. Ask for user input where applicable.[answer]
5) Implement CRUD operations for student table in Swing. Ask for user input where applicable. [Answer ]
6) Implement account balance transfer operation (use transactions). Ask for user input where applicable.[answer]

Unit 5: Network Programming

1) Write two programs that can communicate in a network using TCP Socket?
2) Write a program to illustrate the use of InetAddress class.
3) Write client and server programs in which a server program accepts a radius of a circle from the client program, computes area, sends the computed area to the client program, and displays it by client program. [Answer]
4) Write a program to send email using Java. [Answer]
5) Write client and server programs in which a server program accepts the length and breadth of a rectangle from the client program, computes area, sends the computed area to the client program, and displays it by client program.[Answer]
6) Write echo server and echo client program using UDP.
7) Write client and server programs in which a server program accepts a radius of a circle from the client program, computes area, sends the computed area to the client program, and displays it by client program. The server should be able to handle multiple clients. [Answer]
8) Write client and server programs in which a server program accepts the length and breadth of a rectangle from the client program, computes area, sends the computed area to the client program, and displays it by client program. The server should be able to handle multiple clients.[Answer]
9. Create a Chat Connection Between two client in a single server. [Answer]

Unit 6: Java Beans

1) Write a suitable program illustrating the use of Java Beans.

Unit 7: Servlets and Java Server Pages

1) Write a simple JSP program to display “Kathmandu, Nepal” 10 times.
2) Write a simple JSP program to display “Lalitpur, Nepal” 10 times.
3) Write a simple JSP program to display “Tribhuvan University” 10 times.
4) Write a program that to illustrate the use of JSP.
5) Write a Java program using servlet to display “Tribhuvan University”.
6) Write a program to create a JSP web form to take input of a student and submit it to second JSP file
which may simply print the values of form submission.

Unit 8: RMI and CORBA

1) Use RMI to develop programs that runs in different machines.

All the Questions answer are uploaded in github, please comment if you have any questions

Facebook Comments