Core Java Interview Question, Interview Question

This page discusses - Core Java Interview Question, Interview Question

Core Java Interview Question, Interview Question

Core Java Interview Question Page 24

     

Question: Why do we need public static void main(String args[]) method in Java

Answer: We need

  • public: The method can be accessed outside the class / package
  • static: You need not have an instance of the class to access the method
  • void: Your application need not return a value, as the JVM launcher would return the value when it exits
  • main(): This is the entry point for the application

If the main() was not static, you would require an instance of the class in order to execute the method.
If this is the case, what would create the instance of the class? What if your class did not have a public constructor?

Question: What is the difference between an Interface and an Abstract class

Answer: In abstract class you can define as well as declare methods, the methods which are declared are to be marked as abstract.
In interface all we just declare methods and the definition is provided by the class which is implementing it

Question: Explain serialization

Answer: Serialization means storing a state of a java object by coverting it to byte stream

Question: What are the rules of serialization

Answer: Rules:

1. Static fileds are not serialized because they are not part of any one particular object
2. Fileds from the base class are handled only if hose are serializable
3. Transient fileds are not serialized

Question: What is difference between error and exception

Answer: Error occurs at runtime and cannot be recovered, Outofmemory is one such example. Exceptions on the other hand are due conditions which the application encounters such as FileNotFound exception or IO exceptions

Question: What do you mean by object oreiented programming

Answer: In object oreinted programming the emphasis is more on data than on the procedure and the program is divided into objects.
The data fields are hidden and they cant be accessed by external functions.
The design approach is bottom up.
The functions operate on data that is tied together in data structure

Question: What are 4 pillars of object oreinted programming 

Answer:

1. Abstraction
It means hiding the details and only exposing the essentioal parts

2. Polymorphism
Polymorphism means having many forms. In java you can see polymorphism when you have multiple methods with the same name

3. Inheritance
Inheritance means the child class inherits the non private properties of the parent class

4. Encapsulation
It means data hiding. In java with encapsulate the data by making it private and even we want some other class to work on that data then the setter and getter methods are provided

Question: Difference between procedural and object oreinted language

Answer: In procedural programming the instructions are executed one after another and the data is exposed to the whole program
In OOPs programming the unit of program is an object which is nothing but combination of data and code and the data is not exposed outside the object

Question: What is the difference between constructor and method

Answer: Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.

Question: What is the difference between parameters and arguments

Answer: While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

Question: What is reflection in java

Answer: Reflection allows Java code to discover information about the fields, methods and constructors of loaded classes and to dynamically invoke them

Question: What is a cloneable interface and how many methods does it contain

Answer: It is not having any method because it is a TAGGED or MARKER interface

Question: What's the difference between a queue and a stack

Answer: Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule

Question: Can you make an instance of abstract class

Answer: No you cannot create an instance of abstract class

Question: What are parsers

Answer: Parsers are used for processing XML documents. There are 2 types of parsers DOM parser and SAX Parser

Question: Difference between SAX and DOM parser

Answer: DOM parsers are Object based and SAX parsers are event based
DOM parsers creates Tree in the memory whereas SAX parser does not and hence it is faster than DOM
DOM parser are useful when we have to modify the XML, with SAX parser you cannot modify the xml, it is read only

Question: What is the difference between Java Bean and Java Class
  

Answer: Basically a Bean is a java class but it has getter and setter method and it does not have any logic in it, it is used for holding data.
On the other hand the Java class can have what a java bean has and also has some logic inside it

Tutorials

  1. Core Java Interview Question Page 1
  2. Core Java Interview Question Page 3
  3. Core Java Interview Question Page 8
  4. Core Java Interview Question, Interview Question
  5. Core Java Interview Question, Interview Question
  6. Core Java Interview Question, Interview Question
  7. Core Java Interview Question, Interview Question
  8. Core Java Interview Question, Interview Question
  9. Core Java Interview Question, Interview Question
  10. Core Java Interview questions and answers
  11. Core Java Interview Question, Interview Question
  12. Core Java Interview Question, Interview Question
  13. Core Java Interview Question, Interview Question
  14. Core Java Interview Question, Interview Question
  15. Core Java Interview Question, Interview Question
  16. Core Java Interview Question, Interview Question
  17. Core Java Interview Question, Interview Question
  18. Core Java Interview Question, Interview Question
  19. Core Java Interview Question, Interview Question
  20. Core Java Interview Question, Interview Question
  21. Core Java Interview Question, Interview Question
  22. Core Java Interview Question, Interview Question
  23. Core Java Interview Question, Interview Question
  24. Core Java Interview Question, Interview Question
  25. Core Java Interview Question, Interview Question
  26. Core Java Interview Question, Interview Question
  27. Core Java Interview Question, Interview Question
  28. Core Java Interview Question, Interview Question
  29. Core Java Interview Question, Interview Question
  30. Core Java Interview Question, Interview Question
  31. Core Java Interview Question, Interview Question
  32. Core Java Interview Question, Interview Question
  33. Core Java Interview Question, Interview Question
  34. Core Java Interview Question, Interview Question
  35. Core java Interview Questions