[Go to site: main page, start]

0% found this document useful (0 votes)
9 views5 pages

Java Program Practise Question

The document outlines a series of programming tasks and questions related to Java, covering topics such as control structures, object-oriented programming, exception handling, multithreading, and more. Each task requires the implementation of specific Java concepts, such as classes, methods, inheritance, and arrays, along with examples and code snippets. The tasks are designed to test and demonstrate the understanding of fundamental Java programming principles.

Uploaded by

Jyothi
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)
9 views5 pages

Java Program Practise Question

The document outlines a series of programming tasks and questions related to Java, covering topics such as control structures, object-oriented programming, exception handling, multithreading, and more. Each task requires the implementation of specific Java concepts, such as classes, methods, inheritance, and arrays, along with examples and code snippets. The tasks are designed to test and demonstrate the understanding of fundamental Java programming principles.

Uploaded by

Jyothi
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

Sample Program Question idea from 1-5 Modules

1. Illustrate the use of ‘for each’ and ‘switch case’ statement

2. Illustrate the concept of classes and objects to print the area of a rectangle by creating
a class named 'Area' having two methods. First method named as 'setDim' takes length
and breadth of rectangle as parameters and the second method named as 'getArea'
returns the area of the rectangle. Length and breadth of rectangle are entered through
keyboard
3. Demonstrate with example the role of access specifiers in java
4. Develop a java program for the following scenario : There are n people standing in a
circle ready to be executed. The counting out starts at some point in the circle and
proceeds around the circle in a fixed direction. In every step, a certain number of
people are skipped and the next individual is executed. The removal proceeds around
the circle until last person remains, who is given freedom. Given the total number of
person N and a number k which indicates that k-1 persons are skipped and the kth
person is removed in a circle. The task is to choose the place in the initial circle so
that you are the last one remaining and so survive.
5. With code snippets, explain the concept of:
i)break
ii)continue
6. Illustrate the concept of objects and classes using a class named ‘Rectangle'’ with two
data members- length (int) and breadth (float) and a method to calculate the area
which is 'length*breadth'. The class has four constructors which are:

i. length and breadth values are not given - values of both length and breadth are
assigned zero.

ii. Only length is given – the breadth value will be double of length value.

iii. Only breadth is given – the length value will be half of breadth value.

iv. Both length and breadth values are given - both length and breadth are assigned to
given values. Create an object of the ‘Rectangle’ class having none, one and two
parameters and print their areas

7. Explain one dimensional and two dimensional array initialization with a suitable
example in java. Define an array. Write the syntax for array declaration and
initialization. Create an array of 10 integers and initialize each array element to a
random value between 1 10 (both inclusive)

8. Write a java program for finding the perimeter of the rhombus, circle and
parallelogram by accepting input from keyboard and printing the parameter on
console using the method perimeter() by applying the concept of method overloading
9. Write a program to assign a suitable value to the variable of every primitive (or basic
data type) available in Java and print the size of each primitive data type.
10. Develop a JAVA program to add TWO matrices of suitable order N (The value of N
should be read from command line arguments).
11. Write a Java program that takes input from the user, asking them to enter a month
number (1-12). The program should then use a switch case to determine the
corresponding month name and print it. If the entered month number is not between 1
and 12, the program should output "Invalid month number."
12. Illustrate garbage collection and final keyword in java with suitable example.
13. Demonstrate the concept of abstract by creating an abstract class 'Parent' with a
method 'message'. It has two subclasses each having a method with the same name
'message' that prints "This is first subclass" and "This is second subclass"
respectively. Call the methods 'message' by creating an object for each subclass
14. Differentiate between “Class” and “Object”. Write a java program to define a class
named car with attributes (brand, model, year), a constructor to initialize the object,
and a method to display information about the car
15. What is the meaning of a final variable, a final method, and a final class in Java?
Design a Final Java class that cannot be extended. This should have a final method
getCircumference() which returns the circumference for the given radius as its input
and uses the Final mathematical constant PI defined in the same class to compute the
same.
16. Demonstrate with example the concept of nested interfaces.
17. Create a class with a method that prints "This is parent class" and its subclass with
another method that prints "This is child class". Now, create an object for each of the
class and call 1 - method of parent class by object of parent class 2 - method of child
class by object of child class 3 - method of parent class by object of child class
18. Demonstrate with example the concept of super and final keyword with example.
19. Chef is going for vacations on hill station this winter and is willing to go to the
following destinations: Manali, Mussoorie, Gulmarg. Further he wants to explore the
places by knowing the location, the place is famous for and the authentic dishes
available in that places. Develop a Java program to display the above information
based on chef’s destination points
20. Demonstrate with suitable code snippets the concept of creating and accessing the
user defined packages in java
21. Write a java program to implement multilevel inheritance with 4 levels of hierarchy.
22. What is method overloading and constructor overloading? Write a program to
demonstrate method overloading based on number of parameters
23. Design a class hierarchy – The base class is Animal, the derived class is Dog, and the
third class is the test class. The base has a private data member name and an abstract
protected method makeSound() which is dummy. Dog defines a concrete body for this
method (barking). The test class instantiates a dog object and tests all of the above –
printing the name of the dog (with a public method in the class Animal) and the sound
it makes
24. Define Inheritance. Write a program to explain the Multilevel hierarchy
25. What is method overriding? Explain how it allows Java to support run-time
polymorphism with a very simple example
26. What is Interface? What are its benefits? Write a program and Explain how Interface
is implemented in java
27. Define Exception. Write a program which contains one method which will throw
IllegalAccessException and use proper exception handlers so that exception should be
printed in the calling function
28. Illustrate the concept of try and catch block to handle multiple exceptions
29. What is multiple threading? Write a java program to create multiple threads in java by
implementing runnable interface
30. Describe the following keyword in java with suitable code snippets.
i)try ii) catch iii) throw iv) throws iv) finally
31. Write a Java program to check whether the student is eligible for promotion for next
semester considering the marks of two subjects. Accept name and marks of two
subjects. Throw a user defined exception NOELIGIBLITY if the marks scored in
both subjects is less than 40. Otherwise display the message “Student is Promoted”.
32. Descibe with suitable example the following thread methods:
(1) wait( ) (2) sleep( ) (3) resume( ) (4) notify( )
33. Write a program to create two threads, so one thread will print even numbers between
1 to 10 whereas other will print odd numbers between 11 to 20
34. Create two packages, package1 and package2. In package1, define a class with
members having public, protected, default, and private access modifi-ers. In
package2, create another class to import and access the members of the class from
package1. Write a Java program to demonstrate which members can be accessed and
explain the output.
35. What is checked and uncheck exception? Write a java program to illustrate Nested try
catch statement
36. Write a Java program to demonstrate chained exceptions. Create a scenario where an
initial exception causes another exception to occur
37. What is Thread? Write a sample program and explain two different ways of creating a
Thread in Java.
38. Define a class with three threads, first with a minimum priority, second with a normal
priority, and a final one with maximum priority. Use the in-built priorities from the
Java Thread class. Each thread should print its name, priority, and exit.
39. Implement a method that accepts both primitive and wrapper types as argu-ments,
showcasing autoboxing and unboxing in expressions and method calls
40. Use type wrapper classes (Character, Boolean, and numeric type wrappers) to create
objects, perform operations, and display their values.
41. Explain the use of this in JAVA with an example.
42. Explain how an interface is used to achieve multiple Inheritances in Java
43. Explain the method overriding with a suitable example.
44. What is single-level inheritance? Write a Java program to implement single-level
inheritance
45. What is the importance of the super keyword in inheritance? Illustrate with a suitable
example
46. What is abstract class and abstract method? Explain with an example
47. Define package. Explain the steps involved in creating a user-defined package with an
example
48. Write a program that contains one method that will throw an IllegalAccessException
and use proper exception handles so that the exception should be printed.
49. Define an exception. What are the key terms used in exception handling? Explain.
50. Explain the concept of importing packages in Java and provide an example
demonstrating the usage of the import statement.
51. How do you create your own exception class? Explain with a program.
52. Demonstrate the working of a nested try block with an example
53. What is the need of synchronization? Explain with an example how synchronization is
implemented in JAVA.
54. Discuss values() and value Of() methods in Enumerations with suitable examples.
55. What is multithreading? Write a program to create multiple threads in JAVA.
56. Explain with an example how inter-thread communication is implemented in JAVA.
57. Explain auto-boxing/unboxing in expressions
58. Explain the following operations with examples. (i)<< (ii)>> (iii)>>>
59. Explain object-oriented principles.
60. Write a Java program to sort the elements using a for loop
61. Explain different types of if statements in JAVA
62. What are constructors? Explain two types of constructors with an example program
63. Define recursion. Write a recursive program to find nth Fibonacci number.
64. Explain the various access specifiers in Java.
65. Demonstrate the working of interface in JAVA
66. Demonstrate dynamic dispatch using abstract class in JAVA
67. Demonstrate the working of final class and final method in JAVA.
68. Example two uses of super keyword with example.
69. Explain memory allocation and use of garbage collector in JAVA
70. Explain static variable and static methods in JAVA.
71. Write a program to find the biggest of three numbers using ternary operator.
72. Explain different promotion rules in JAVA.
73. Describe the meaning of each of the keyword in “public static void main”
74. Explain different type of integer literals with examples.

You might also like