Content-Length: 3117059 | pFad | https://www.scribd.com/document/635104421/Top-100-Java-Interview-Qns-Ans

1 Top 100 Java Interview Qns & Ans | PDF | Java (Programming Language) | Class (Computer Programming)
0% found this document useful (0 votes)
51 views5 pages

Top 100 Java Interview Qns & Ans

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

Top 100 Java Interview Questions & Answers

1. What is a class in Java?


Answer: Java encapsulates the codes in various classes which define new data types. These new data
types are used to create objects.

2. What is a JVM?
Answer: JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

3. What is the right data type to represent a price in Java?


Answer: BigDecimal, if memory is not a concern and Performance, is not critical, otherwise double with
predefined precision.

4. Does Java support multiple inheritances?


Answer: Java doesn’t support multiple inheritances.

5. What are the supported platforms by Java Programming Language?


Answer: Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of
UNIX/Linux like HP-Unix, Sun Solaris, Red hat Linux, Ubuntu, Cent OS, etc.

6. List any five features of Java?


Answer: Some features include Object Oriented
Platform Independent
Robust
Interpreted
Multi-threaded

7. Explain method overloading?


Answer: When a Java program contains more than one methods with the same name but different
properties, then it is called method overloading.

8. What restrictions are placed on the location of a package statement within a source code file?
Answer: A package statement must appear as the first line in a source code file (eliminating blank lines
and comments).
9. What method is used to specify a container’s layout?
Answer: The setLayout() method is used to specify a container’s layout.

10. What is the immediate superclass of the Applet class?


Answer: The Panel class is the immediate superclass of the Applet class.

11. What are the access modifiers in Java?


Answer: There are 3 access modifiers. Public, protected and private, and the default one if no identifier
is specified is called friendly, but programmer cannot specify the friendly identifier explicitly.

12. What is are packages?


Answer: A package is a collection of related classes and interfaces providing access protection and
namespace management.

13. What is meant by Inheritance and What are its advantages?


Answer: Inheritance is the process of inheriting all the features from a class. The advantages of
inheritance are reusability of code and accessibility of variables and methods of the super class by
subclasses.

14. Can we rethrow the same exception from catch handler?


Answer: Yes, we can rethrow the same exception from our catch handler. If we want to rethrow
checked exception from a catch block we need to declare that exception.

15. what value is a variable of the String type automatically initialized?


Answer: The default value of a String type is null.

16. When a thread blocks on I/O, what state does it enter?


Answer: When it blocks on I/O, A thread enters the waiting state.

17. Which containers use a Flow Layout as their default layout?


Answer: The Panel and Applet classes use the Flow Layout as their default layout.

18. Explain Java Coding Standards for Constants ?


Answer:
Constants in java are created using static and final keywords.
1) Constants contain only uppercase letters.
2) If the constant name is a combination of two words it should be separated by an underscore.
3) Constant names are usually nouns.
Ex:MAX_VALUE, MIN_VALUE, MAX_PRIORITY, MIN_PRIORITY

19. What is synchronization and why is it important?


Answer: The term synchronization is the ability to control the access of multiple threads to shared
resources. And it is important because, without it, it is not possible for one thread to modify a shared
object while another thread is in the process of using or updating that object’s value. This often leads to
major errors.

20. Explain Java Coding Standards for variables?


Answer:
1) Variable names should start with small letters.
2) Variable names should be nouns
3) Short meaningful names are recommended.
4) If there are multiple words every inner world should start with Uppercase character.
Ex : string,value,empName,MEP salary

21. What is an abstract class?


Answer: An abstract class is a class designed with implementation gaps for subclasses to fill in and is
deliberately incomplete.

22. Name three Component subclasses that support painting?


Answer: The Canvas, Frame, Panel, and Applet classes support painting.

23. What is the difference between JDK and JVM?


Answer: Full-Form: Java Development Kit Full Form: Java Virtual Machine
For Development Purpose
To execute the java programs
It provides all the tools, executables and binaries required to compile, debug and execute a Java
Program The execution part is handled by JVM to provide machine independence.

24. Why Java doesn’t support multiple inheritances?


Answer: Because of “Diamond Problem”, Java doesn’t support multiple inheritances in classes.
25. What modifiers may be used with an inner class that is a member of an outer class?
Answer: A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.

26. Which java. util classes and interfaces support event handling?
Answer: The Event Object class and the Event Listener interface support event processing.

27. What is a transient variable?


Answer: A transient variable is a variable that may not be serialized.

28. Is null a keyword?


Answer: No, the null is not a keyword.

29. What is an applet?


Answer: Applet is a dynamic and interactive program that runs inside a web page displayed by a java
capablebrowser

30. What is the lifecycle of an applet?


Answer:
init() method – Can be called when an applet is first loaded
start() method – Can be called each time an applet is started.
paint() method – Can be called when the applet is minimized or maximized.
stop() method – Can be used when the browser moves off the applet’s page.
destroy() method – Can be called when the browser is finished with the applet.

31. What’s new with the stop(), suspend() and resume() methods in JDK 1.2 ?
Answer:
These methods have been deprecated in JDK 1.2.

32. What is the Vector class?


Answer: The term Vector class provides the ability to implement a growable array of objects.

33. What is the difference between the >> and >>> operators?
Answer: The >> operator carries the sign bit when shifting right while the >>> zero-fills bits that have
been shifted out.
34. What is the difference between this() and super()?

Answer: this() can be used to invoke a constructor of the same class whereas super() can be used to
invoke a super class constructor.

35. What is a native method?


Answer: A native method is a method that is applied in a language other than Java.

36. What value does read Line() return when it has reached the end of a file?
Answer:The readLine() method returns null when it has reached the end of a file.

37. What is the Java API?

Answer: The Java API is a large collection of ready-made software components that provide many
usefulcapabilities, such as graphical user interface (GUI) widgets.

38. Why there are no global variables in Java?

Answer: Global variables are globally accessible. Java does not support globally accessible variables due
to following reasons:
The global variables breaks the referential transparency
Global variables creates collisions in namespace.

39. What are different types of access modifiers?

Answer: public: Any thing declared as public can be accessed from anywhere. private: Any thing
declared asprivate can’t be seen outside of its class. protected: Any thing declared as protected can be
accessedby classes in the same package and subclasses in the other packages. default modifier : Can
beaccessed only to classes in the same package.

40. What is Constructor?


Answer: A constructor is a special method whose task is to initialize the object of its class.
It is special because its name is the same as the class name.
They do not have return types, not even void and therefore they cannot return values.
They cannot be inherited, though a derived class can call the base class constructor.
Constructor is invoked whenever an object of its associated class is created.

41. What is an Iterator ?


Answer: The Iterator interface is used to step through the elements of a Collection.

You might also like









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://www.scribd.com/document/635104421/Top-100-Java-Interview-Qns-Ans

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy