Java interview questions

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is the main objective of garbage collection?

To free up memory space occupied by unncessary and unreachable objects during a java program execution by deleting the objects.

Can the static methods be overloaded?

Yes, two or more static methods can exist in one class with the same name if they have differing inputs.

What do you mean by data encapsulation?

- OOP concept of hiding data attributes and behaviors in one unite - modularity: each object has its own methods, attributes, functionalities - used for security of private properties and hides data

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

Heap

Tell us something about JIT compiler.

JIT stands for Just-in-Time and improves performance during run time (part of JVM). It compiles parts of byte code having similar functionality at the same time.

Why is Java a platform independent language?

Java does not depend on hardware/software as the compiler compiles the code into platform independent byte code, just need a runtime environment

Why is Java not a pure object oriented language?

Java has support for primitive data types - byte, boolean, char, short, int, float, long, and double

Can the static methods be overridden?

No, run time polymorphism cannot take place. overriding or dynamic polymorphism occurs during runtime but the static methods are loaded and looked up at the compile time statically.

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

No, they each have their own utility. Final: used if any restriction is required for classes, variables, or methods. Finally: the block that is present where all code written inside of it get executed irrespective of handling exceptions. (in conjunction with try catch blocks) Finalize: prior to garbage collection, finalize method is called so that clean-up activity is implemented.

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

Pointers are complicated and unsafe. java uses references instead which cannot be directly manipulated.

When can you use super keyword?

Used to access hidden fields and overridden methods or attributes of the parent class. Specific Cases: - Accessing data members of parent class where names overlap with the child - to call default and parametrized constructor of parents - accessing parent class methods that the child has overridden

Can a single try block and multiple catch blocks co-exist in a Java Program?

Yes but only first catch block satisfying the condition is executed so specific approaches should come prior to general approach.

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

equals(): - method defined in the object class - used for checking equality of contents between two objects as per business logic == : - binary operator - used for comparing addresses(or references)

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

final variable: - value cannot be modified once assigned - if a value has been assigned, then only the constructor can assign it a value final Method: - cannot be overridden by children classes - constructor cannot be marked as final, since constructors are not inherited final class: - No classes can be inherited from the class by the final class can extend other classes


Kaugnay na mga set ng pag-aaral

drivers ed class 11 quiz answers

View Set

Chapter 10 Global logistics and international trade

View Set

GSU Microbiology Exam 2 Chapter 5-7

View Set

Pharmacology Respiratory Quiz Questions

View Set

Chapter 3 (3.1-3.2) quiz History

View Set