0% found this document useful (0 votes)
19 views3 pages

Java Programming Practice Questions

The document outlines a series of technical questions related to Java programming, covering topics such as object-oriented principles, memory management, exception handling, and data structures. It serves as a resource for students at the Dadi Institute of Engineering & Technology to enhance their understanding of Java. The institute is accredited and offers various engineering and technology programs.

Uploaded by

CRICKET ARMY
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)
19 views3 pages

Java Programming Practice Questions

The document outlines a series of technical questions related to Java programming, covering topics such as object-oriented principles, memory management, exception handling, and data structures. It serves as a resource for students at the Dadi Institute of Engineering & Technology to enhance their understanding of Java. The institute is accredited and offers various engineering and technology programs.

Uploaded by

CRICKET ARMY
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

DADI INSTITUTE OF ENGINEERING & TECHNOLOGY

An Autonomous Institute
(Approved by A.I.C.T.E., New Delhi & Permanently Affiliated to JNTU GV)
Accredited by NAAC with ‘A’ Grade and Inclusion u/s 2(f) & 12(B) of UGC Act
An ISO 9001:2015, ISO 14001:2015 & ISO 45001:2018 Certified Institute.
NH-16, Anakapalle – 531002, Visakhapatnam, A.P.
Website: [Link], 9963694444 E-mail: info@[Link]

Skill cluster 1: Java, ANSI SQL, HTML, CSS, JavaScript

1. Why is Java a platform independent language?

2. Why is Java not a pure object oriented language?

3. Difference between Heap and Stack Memory in java. And how java utilizes this.

4. Can java be said to be the complete object-oriented programming language?

5. How is Java different from C++?

6. Pointers are used in C/ C++. Why does Java not make use of pointers?

7. What do you understand by an instance variable and a local variable?

8. What are the default values assigned to variables and instances in java?

9. What do you mean by data encapsulation?

10. Tell us something about JIT compiler.

11. Can you tell the difference between equals() method and equality operator (==)
in Java?

12. How is an infinite loop declared in Java?

13. Briefly explain the concept of constructor overloading

14. Define Copy constructor in java.

15. Can the main method be Overloaded?

16. Comment on method overloading and overriding by citing relevant examples.

17. A single try block and multiple catch blocks can co-exist in a Java Program.
Explain.

18. Explain the use of final keyword in variable, method and class.

19. Do final, finally and finalize keywords have the same function?

20. Is it possible that the ‘finally’ block will not be executed? If yes then list the
case.

21. Identify the output of the java program and state the reason.

22. When can you use super keyword?

23. Can the static methods be overloaded?

24. Why is the main method static in Java?


DADI INSTITUTE OF ENGINEERING & TECHNOLOGY
An Autonomous Institute
(Approved by A.I.C.T.E., New Delhi & Permanently Affiliated to JNTU GV)
Accredited by NAAC with ‘A’ Grade and Inclusion u/s 2(f) & 12(B) of UGC Act
An ISO 9001:2015, ISO 14001:2015 & ISO 45001:2018 Certified Institute.
NH-16, Anakapalle – 531002, Visakhapatnam, A.P.
Website: [Link], 9963694444 E-mail: info@[Link]

25. Can the static methods be overridden?

26. Difference between static methods, static variables, and static classes in java.

27. What is the main objective of garbage collection?

28. What is a ClassLoader?

29. What part of memory - Stack or Heap - is cleaned in garbage collection process?

30. What are shallow copy and deep copy in java?

1. Apart from the security aspect, what are the reasons behind making strings
immutable in Java?

2. What is a singleton class in Java? And How to implement a singleton class?

3. Which of the below generates a compile-time error? State the reason.

4. How would you differentiate between a String, StringBuffer, and a StringBuilder?

5. Using relevant properties highlight the differences between interfaces and abstract
classes.

6. Is this program giving a compile-time error? If Yes then state the reason and
number of errors it will give. If not then state the reason.

7. What is a Comparator in java?

8. In Java, static as well as private method overriding is possible. Comment on the


statement.

9. What makes a HashSet different from a TreeSet?

10. Why is the character array preferred over string for storing confidential
information?

11. What do we get in the JDK file?

12. What are the differences between JVM, JRE and JDK in Java?

13. What are the differences between HashMap and HashTable in Java?

14. What is the importance of reflection in Java?

15. What are the different ways of threads usage?

16. What are the different types of Thread Priorities in Java? And what is the
default priority of a thread assigned by JVM?

17. What is the difference between the program and the process?
DADI INSTITUTE OF ENGINEERING & TECHNOLOGY
An Autonomous Institute
(Approved by A.I.C.T.E., New Delhi & Permanently Affiliated to JNTU GV)
Accredited by NAAC with ‘A’ Grade and Inclusion u/s 2(f) & 12(B) of UGC Act
An ISO 9001:2015, ISO 14001:2015 & ISO 45001:2018 Certified Institute.
NH-16, Anakapalle – 531002, Visakhapatnam, A.P.
Website: [Link], 9963694444 E-mail: info@[Link]

18. What is the difference between the ‘throw’ and ‘throws’ keyword in java?

19. What are the differences between constructor and method of a class in Java?

20. Identify the output of the below java program and Justify your answer.

21. Java works as “pass by value” or “pass by reference” phenomenon?

22. What is the ‘IS-A ‘ relationship in OOPs java?

23. Which among String or String Buffer should be preferred when there are lot of
updates required to be done in the data?

24. How to not allow serialization of attributes of a class in Java?

25. What happens if the static modifier is not included in the main method
signature in Java?

26. Consider the below program, identify the output, and also state the reason for
that.

27. Can we make the main() thread a daemon thread?

28. What happens if there are multiple main methods inside one class in Java?

29. What do you understand by Object Cloning and how do you achieve it in Java?

30. How does an exception propagate in the code?

31. How do exceptions affect the program if it doesn't handle them?

32. Is it mandatory for a catch block to be followed after a try block?

33. Will the finally block get executed when the return statement is written at the
end of try block and catch block as shown below?

34. Can you call a constructor of a class inside the another constructor?

35. Contiguous memory locations are usually used for storing actual values in an
array but not in ArrayList. Explain.

36. Why does the java array index start with 0?

37. Why is the remove method faster in the linked list than in an array?

38. How many overloaded add() and addAll() methods are available in the List
interface? Describe the need and uses.

39. How does the size of ArrayList grow dynamically? And also state how it is
implemented internally.

Common questions

Powered by AI

Java's garbage collector manages memory in the 'Heap' where objects are allocated and dynamically deallocated when they are no longer referenced, thus preventing memory leaks. The 'Stack' memory is managed automatically by the JRE and is used for method execution and storing local variables, and it gets cleared once a method completes execution. This distinction is crucial as it affects performance optimization, object lifecycle management, and user control over memory resources .

The 'finally' block is intended to execute regardless of whether an exception is thrown or not, providing a mechanism to release resources. However, it may not execute if the JVM exits, such as through a call to System.exit(), or if the thread executing the finally block is interrupted or killed. Proper resource management strategies are crucial as relying solely on the 'finally' block could lead to resource leakage .

StringBuffer is preferred over String when frequent modifications are required because it is mutable, allowing dynamic changes without creating a new object, hence optimizing memory usage and performance. Unlike Strings, which produce a new instance upon each modification, StringBuffer can modify data in place, making it ideal for scenarios involving heavy string manipulations. This reduces overhead and speeds up operations that require frequent alteration of string content .

Strings are made immutable in Java to increase performance by allowing their interned objects to be reused, thus saving memory. Immutability also leads to thread safety because concurrent threads can work on strings without the risk of interfering with each other’s data. Furthermore, immutability allows efficient use of hash-based collections like HashMap since strings' hash codes do not change once calculated .

HashMap is a part of Java's collection framework and allows null keys and values, whereas Hashtable doesn't. HashMap is non-synchronized and, therefore, better suited for non-thread-safe operations, leading to higher performance in single-threaded environments. In contrast, Hashtable is synchronized, being thread-safe, and more suitable for multi-threaded applications, though at a performance cost due to synchronized methods. Moreover, HashMap offers improved iteration performance with fail-fast iterators, reflecting concurrent modifications via a ConcurrentModificationException .

Encapsulation in Java refers to bundling the data (fields) and code (methods) that operate on the data into a single unit or class, restricting access to some component's data and methods from outside access. This is implemented using access specifiers like private, protected, and public, and providing public getter and setter methods to modify the private variables. Encapsulation ensures data integrity by controlling how data is accessed and modified, thus maintaining object boundaries and improving overall program robustness and security .

Java employs 'pass by value' to prevent methods from modifying the actual memory location of variables. When dealing with objects, Java passes the reference’s value (i.e., object copy), ensuring that while the object reference is a copy, any modifications affect the original object. This model avoids unintended side effects and retains clear separation between method scopes, increasing code predictability and reducing bugs resulting from unintended data manipulation by methods .

In Java, exceptions propagate up the call stack, meaning if a method does not handle an exception, it is passed to the method that invoked it, continuing up the hierarchy until it is caught or reaches the main method, triggering program termination if unhandled. This can lead to abrupt termination of the application and potential data loss. Hence, effective exception handling is vital to ensure program stability and a proper shutdown sequence .

Interfaces in Java define a contract for subclasses to implement all its methods, allowing multiple inheritance and facilitating loose coupling between components. They are ideal when different classes need to agree on a set of functionalities without sharing common states. Abstract classes, on the other hand, can contain both abstract methods and code, allowing shared base class functionality. They offer more structure but limit inheritance to single types. Use abstract classes when sharing code between a group of closely related classes as they provide a common implementation .

Java does not use pointers to prevent developers from accidentally corrupting memory by accessing unauthorized memory locations, which enhances security and program stability. This design choice also contributes to Java's strong encapsulation and abstraction by not exposing memory addresses directly. It simplifies memory management and enhances the safety and portability of the code across different platforms .

You might also like