33 Java Interview Questions and Answers

Compiled By Unknown - No Comments
376. 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

377. 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

378. 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

379. 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

380. 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

381. 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

382. 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

383. 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

384. Question: Can you make an instance of abstract class
Answer : No you cannot create an instance of abstract class

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

386. 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

387. 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

388. Question: What are null or Marker interfaces in Java
Answer : The null interfaces are marker interfaces, they do not have function declarations in them, they are empty interfaces, this is to convey the compiler that they have to be treated differently

389. Question: Does java Support multiple inheritance
Answer : Java does not support multiple inheritance directly like C++, because then it is prone to ambiguity, example if a class extends 2 other classes and these 2 parent classes have same method names then there is ambiguity. Hence in Java Multiple inheritance is supported using Interfaces

390. Question: What are virtual function
Answer : In OOP when a derived class inherits from a base class, an object of the derived class may be referred to (or cast) as either being the base class type or the derived class type. If there are base class functions overridden by the derived class, a problem then arises when a derived object has been cast as the base class type. When a derived object is referred to as being of the base's type, the desired function call behavior is ambiguous
The distinction between virtual and not virtual is provided to solve this issue. If the function in question is designated "virtual" then the derived class's function would be called (if it exists). If it is not virtual, the base class's function would be called

391. Question: Does java support virtual functions
Answer : No java does not support virtual functions direclty like in C++, but it supports using Abstract class and interfaces

392. Question: Describe what happens when an object is created in Java
Answer : Several things happen in a particular order to ensure the object is constructed properly:
1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data
2. The instance variables of the objects are initialized to their default values
The constructor for the most derived class is invoked. The first thing a constructor does is call the consctructor for its superclasses. This process continues until the constrcutor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java
Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.

393. Question: What is the purpose of System Class
Answer : The purpose of the system class is to provide the access to the System reources

394. Question: What is instanceOf operator used for
Answer : It is used to if an object can be cast into a specific type without throwing Class cast exception

395. Question: Why we should not have instance variable in an interface
Answer : Since all data fields and methods in an Interface are public by default, then we implement that interface in our class then we have public members in our class and this class will expose these data members and this is violation of encapsulation as now the data is not secure

396. Question: What is JVM
Answer : When we install a java package. It contains 2 things The Java Runtime Environment (JRE) The Java Development Kit (JDK)
The JRE provides runtime support for Java applications. The JDK provides the Java compiler and other development tools. The JDK includes the JRE
Both the JRE and the JDK include a Java Virtual Machine (JVM). This is the application that executes a Java program. A Java program requires a JVM to run on a particular platform

397. Question: Can abstract class be final
Answer : No, abstract class cannot be final


398. Question: When a new object of derived Class is created, whose constructor will be called first, childs or parents
Answer : Even when the new object of child class is created, first the Base class constructor gets executed and then the child classes constructor

399. Question: What is a singleton class
Answer : A singleton is an object that cannot be instantiated. The restriction on the singleton is that there can be only one instance of a singleton created by the Java Virtual Machine (JVM) - by prevent direct instantiation we can ensure that developers don't create a second copy

400. Question: Can an abstract class have final method
Answer : Yes

What do you know about Java?
Solution to Interview Question

Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.


What are the supported platforms by Java Programming Language?
Solution to Interview Question

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


List any five features of Java?
Solution to Interview Question

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


Why is Java Architectural Neutral?
Solution to Interview Question

It’s compiler generates an architecture-neutral object file format, which makes the compiled code to be executable on many processors, with the presence of Java runtime system.


How Java enabled High Performance?
Solution to Interview Question

Java uses Just-In-Time compiler to enable high performance. Just-In-Time compiler is a program that turns Java bytecode, which is a program that contains instructions that must be interpreted into instructions that can be sent directly to the processor.


Why Java is considered dynamic?
Solution to Interview Question

It is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.


What is Java Virtual Machine and how it is considered in context of Java’s platform independent feature?
Solution to Interview Question

When Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run.


List two Java IDE’s?
Solution to Interview Question

Netbeans, Eclipse, etc.




Tags:

No Comment to " 33 Java Interview Questions and Answers "