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

Java Practice Set UNIT 1&2

The document is a Java practice set consisting of multiple-choice questions, short answer questions, and long answer questions covering fundamental concepts of Java programming. Topics include JVM, JRE, JDK, data types, memory management, object-oriented programming principles, and various programming tasks. It serves as a comprehensive resource for learners to test their knowledge and skills in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Java Practice Set UNIT 1&2

The document is a Java practice set consisting of multiple-choice questions, short answer questions, and long answer questions covering fundamental concepts of Java programming. Topics include JVM, JRE, JDK, data types, memory management, object-oriented programming principles, and various programming tasks. It serves as a comprehensive resource for learners to test their knowledge and skills in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JAVA PRACTICE SET (Unit 1 + Unit 2)

Section A: MCQs (1 Mark Each)


1. What is the full form of JVM?
a) Java Variable Machine
b) Java Virtual Machine
c) Java Verified Machine
d) Java Visual Machine

2. Which component compiles Java code?


a) JRE
b) JVM
c) JDK
d) JIT

3. Which method is the entry point of a Java program?


a) start()
b) main()
c) run()
d) init()

4. Which of the following is not a primitive data type?


a) int
b) float
c) String
d) char

5. Default value of boolean is:


a) true
b) false
c) 0
d) null

6. Which class is used for input in Java?


a) Input
b) Scanner
c) Reader
d) Console

7. Which method reads an integer using Scanner?


a) nextInt()
b) getInt()
c) readInt()
d) scanInt()

8. Which operator is used for comparison?


a) =
b) ==
c) :=
d) !=

9. Result of 10 / 3 (int)?
a) 3.33
b) 3
c) 4
d) Error

10. Typecasting from double to int is:


a) implicit
b) explicit
c) automatic
d) none

11. Which loop executes at least once?


a) for
b) while
c) do-while
d) none

12. Which keyword is used to create an object?


a) class
b) object
c) new
d) create

13. A class is:


a) blueprint
b) object
c) variable
d) function

14. Which keyword refers to current object?


a) self
b) this
c) object
d) current
15. Constructor name must be:
a) same as method
b) same as class
c) different
d) none

16. Default constructor is:


a) created by user
b) created by compiler
c) always parameterized
d) none

17. Stack stores:


a) objects
b) local variables
c) heap data
d) files

18. Heap stores:


a) primitive variables
b) local variables
c) objects
d) methods

19. Which memory is automatically managed?


a) Stack
b) Heap
c) Both
d) None

20. Object lifecycle ends when:


a) object is used
b) program ends
c) garbage collected
d) method ends

Section B: Short Answer (4 Marks Each)


21. Explain JVM, JRE, and JDK.

22. Write a Java program to print your name and age.

23. Explain primitive vs non-primitive data types with examples.

24. Write a program using Scanner to input two numbers and print their sum.
25. Explain implicit and explicit type casting with example.

26. Write a program to check if a number is even or odd.

27. Write a program to find the largest of three numbers using if-else.

28. Write a program to print numbers from 1 to 10 using a loop.

29. Write a program to calculate factorial using a loop.

30. Define class and object with example.

31. Write a simple class Student with name and roll number.

32. Explain this keyword with example.

33. Write a program using constructor to initialize values.

34. Differentiate between default and parameterized constructor.

35. Explain stack and heap memory in Java.

36. Write a Java program to create a class Student with data members name and rollNo, and
display them.

37. Write a Java program to create a class Rectangle and calculate the area using a method.

38. Explain the use of the ‘this’ keyword with a small Java example.

39. Write a Java program using a default constructor to initialize and display values.

40. Differentiate between parameterized constructor and default constructor with example.

Section C: Long Answer (10 Marks Each)


41. Write a Java program to find the sum of digits of a number.

42. Write a program to reverse a number.

43. Write a program to check if a number is palindrome.

44. Write a program to check if a number is prime.

45. Create a class Student with name, rollNo, methods to set and display data.

46. Create a class Rectangle with attributes length, breadth and method to calculate area.

47. Create a class BankAccount with account number, balance and methods deposit,
withdraw, display.
48. Write a program demonstrating constructor overloading.

49. Create a class Employee with id, name, salary using parameterized constructor and
display details.

50. Create a class with default and parameterized constructor and show both usages.

51. Write a program to demonstrate this keyword to resolve variable shadowing.

52. Explain object lifecycle with a program demonstrating object creation and garbage
collection.

53. Create a class BankAccount with:

 Data members: account number, balance


 Methods: deposit(), withdraw(), display()
 Write a complete Java program to demonstrate its working.

54. Write a Java program to demonstrate constructor overloading by creating a class


Employee with:

 Default constructor
 Parameterized constructor
 Display employee details

55. Create a class Student with:

 Data members: name, roll number


 Method to set data using this keyword
 Method to display data
 Create multiple objects and demonstrate working

You might also like