JAVA Interview Questions For Freshers

What is an Object?          An object is an entity with certain attributes or qualities and behaviors, for a simple example, a 'Laptop...

What is an Object? 
        An object is an entity with certain attributes or qualities and behaviors, for a simple example, a 'Laptop' is an object which has certain attributes like weight,color,screen size,manufacturer etc.It has various behaviors or activities to do or act upon, as play games,browse Internet,write/check emails , watch movies ,listen music etc.

What is a Class?
         A class is a collection of attributes and behaviors of objects with certain similarities and an instance of a class is represented by an object.

What is OOAD?

       Object Oriented Analysis and Design(OOAD) is a methodology to analyze,design and develop application using objects and their relations and message based communication to each other.Everything in OOAD is visualized in terms of objects and classes.OOAD introduced a paradigm shift from thinking and programming procedurally to objects oriented programming.This approach helps in designing complex real time systems with ease.The features like Data Abstraction and Encapsulation, Inheritance and Polymorphism form fundamentals of object oriented

What is difference between JDK,JRE and JVM?
     * JVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the           runtime environment in which java bytecode can be executed. 
     *JVMs are available for many hardware and software platforms 
       (so JVM is plateform dependent).
     * JRE stands for Java Runtime Environment. It is the implementation of JVM and physically           exists. 
     *JDK is an acronym for Java Development Kit. It physically exists. It contains JRE +                       development tools.

What is JIT compiler?
       Just-In-Time(JIT) compiler.It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.Here the term “compiler” refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.

What is platform?
        A platform is basically the hardware or software environment in which a program runs. There are two types of platforms software-based and hardware-based. Java provides software-based platform.

What is the main difference between Java platform and other platforms?
        The Java platform differs from most other platforms in the sense that it's a software-based platform that runs on top of other hardware-based platforms.
It has two components: 
 *Runtime Environment .
 *API(Application Programming Interface).

What is Data Abstraction ?
       Data Abstraction is extraction of essential information for a particular purpose and ingnoring the remainder of the information.

What is Data Encapsulation?
        Data Encapsulation is wrapping informations(attributes and behaviors) within an object.A suitable example is a class as it wraps methods and data within itself. The attributes of a class corresponds to its data members while behaviour corresponds to member methods of the class.

What is Inheritance and what are different types of it?
       Inheritance is a mechanism by which a specific object acquires attributes and behaviors of more general objects.In OOP terminology ,Inheritance is the mechanism which allows a Class 'A' to inherit properties of Class 'B' and we say 'A inherits from B' or in other words B is a 'Superclass'/'Parent class' while A is a 'Subclass'/'Child class'. 
1.Single Inheritance 
2.Multiple Inheritance 
3.Multilevel Inheritance 
4.Hierarchical Inheritance 
5.Hybrid Inheritance

What gives Java its 'write once and run anywhere' nature?
      The bytecode. Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platorm specific and hence can be fed to any platform

Why Java uses Singly rooted hierarchy?
       All objects in Java are inherited from same base class called 'Object'.In Java all objects have common interface to implement and it makes implementaion of Garbage collector lot easier in Java.The necessary implementaion is provided in base class , and the garbage collector can then send the necessary messages to every objectc in the system.Without singly rooted hierarchy,it would have been difficult to implement garbage collection feature.It enables lot of ease to programmers not to be bothered about memory management while development.It greatly simplifies argument passing amongst object too on the heap.

What's the difference between the methods sleep() and wait()
        The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

What is Generalization?
       In UML , a generalization relationship is a relationship in which one model element (the child) is based on another model element (the parent). Generalization relationships are used in class, component, deployment, and use case diagrams. Generalization corresponds to inheritance implemenation amongst classes.

How is Java different from C++?
       Java is a platform independent, object oriented language while C++ is having some of its features from C, which is a procedural language so it is not pure object oriented. Even Java is not 100% pure object oriented. 1. Pointers are supported in C++ while not in Java. The memory management is done automatically with help of part of JVM called Garbage Collector. 2. Multiple inheritance is not supported in Java but supported in C++. 3. There are no structures and unions in Java. 4. There is no scope resolution operator in Java (::). 5. There are no destructors in Java like C++. 6. There is no virtual keyword in Java because all non-static method use dynamic binding.

What is Dependency and how it maps into a Java class?
        A Dependency relationship means when a class consumes/uses methods or variables from other class(supplier).So a change to supplier class affects the consumer class as well.Here supplier is indepenedent of any changes being made to consumer classs.

What is a Java Virtual Machine (JVM)?
        A Java Virtual Machine is a runtime environment required for execution of a Java application.Every Java application runs inside a runtime instance of some concrete implementation of abstract specifications of JVM.It is JVM which is crux of 'platform independent' nature of the language.

What is heap and stack?
      The heap is the part of memory of JVM where all objects reside.
  The stack is consisted of stack frames.When a thread invokes a method,the JVM pushes a new frame onto that thread's Java stack.Each stack frame is consisted of operand stack and the local variable array.All arguments,local variables,intermediate computations and return values if any are kept in these stack corresponding to the method invoked.The stack frame on the top of the stack is called the active stack frame,which is the current place of execution.When the method completes, the virtual machine pops and discards the frame for that method.

What is a transient variable?
       The lexical meaning of word transient is 'existing for a short duration',in Java,a transient variable is one which one would not like to be saved during seralization. This is mostly the case when a variable is sensitive enough that it should not be saved during serialization, such as a password.Even when such variable is private in the object,once it is serialized it is possible to read it inside a file or over a network.The keyword 'transient' is solution for such variables that are not required to be serialized.

What is a thread?
       A thread is most fundamental unit of a computer program which is under execution independent of other parts.A thread and a task are similar and often confused.An operating system executes a program by allocating it certain resources like memory,CPU cycles and when there are many a programs doing several things corresponding to several users requests.In such a scenario each program is viewed as a 'task' by OS for which it identifies an allocate resources. An OS treats each application e.g. Word Processor,spreadsheet,email client etc as a separate task , if a certain program initiates some parallel activity e.g. doing some IO operations,printing then a 'thread' will be created for doing this job.

What is JDBC ?
        JDBC is Java Database Connectivity, a collection of APIs for connecting a Java application to a database. It is an abstraction over ODBC so as to provide Java clients an interface to connect to the database end.The latest update of the JDBC API is JDBC3.0. It contains many features, including scrollable result sets and the SQL:1999 data types. The first version of JDBC(JDBC1.22 with JDK1.1.x release) had only one pacakge named java.sql.* but in JDBC2.0(released with Java2) there had been introduced several new features in two pacakges namely,java.sql.* and javax.sql.*

What are different socket options?

       The different Socket options are :
 SO_TIMEOUT 
SO_LINGER 
TCP_NODELAY 
SO_RCVBUF 
SO_SNDBUF. 
                       They may be specified in various scenarios e.g. one might like to specify a timeout for read operations, to control the amount of time a connection will linger for before a reset is sent, whether Nagle's algorithm is enabled/disabled, or the send and receive buffers for datagram sockets.

What is serialization in java?
        Serialization is a process of converting object into a sequences of byte which can be written to disk or database or sent over network to any other running JVM. The reverse process of creating object from sequences of byte is called Deserialization.

Why Java does not support pointers?
        Because pointers are unsafe. Java uses reference types to hide pointers and programmers feel easier to deal with reference types without pointers. This is why Java and C# shine.

What is meant by "Abstract Interface"? 
         First, an interface is abstract. That means you cannot have any implementation in an interface. All the methods declared in an interface are abstract methods or signatures of the methods

What is a servlet? Explain its lifecycle.
        The Servlets are server side java programs, which are used to generate dynamic web content for a web clients. They reside inside a servlet container on a web server or an application server. 
                        The servlet container provides them a runtime environment. If an instance of servlet is non existent then web container loads the servlet class and creates an instance of the servlet.Once the servlet instantiates, web container calls init() method on it to initialize the servlet.This process of initialization can be customized to allow servlet to read persistent configuration data,initialize resources like database connections etc. by overriding init() method of Servlet interface.
                                      If initialization of a servelet fails it throws UnavailableException. Once initialization is done, web container invokes the service method, passing a request and response object depending upon incoming request.
                                       If the container needs to remove the servlet(e.g.when web container is shutting down), it finalizes the servlet by calling the servlet's destroy method. The javax.servlet.Servlet interface defines the three life-cycle method:- public void init(ServletConfig config) throws ServletException public void service( ServletRequest req, ServletResponse res) throws ServletException, IOException public void destroy().

Why there are no constructors in servlets?
        A servlet is just like an applet in the respect that it has an init() method that acts as a constrcutor. Since the servlet environment takes care of instantiating the servlet, an explicit constructor is not needed. Any initialization code you need to run should be placed in the init() method since it gets called when the servlet is first loaded by the servlet container.

What is a Servlet Context?
        A ServletContext interface empowers a servlet to view its environment. A servlet can use this interface to get following informations: - Initial Web Application Parameters - Application Scope for binding objects - Virtual Directory Translation - A common mechanism for Logging information Each vendor provides specific ServletContext object but they all provide the same functionality defined by the ServletContext interface.



How will you handle runtime exceptions in your JSPs?
       JSP runtime exceptions are handled through the implicit object named "exception". This exception object can be used in a special type of JSP page called an error page, where you display the exception's name and class, its stack trace, and an informative message for your user.  
        In any JSP which is made eligible for catching exceptions then it must have a mention to error page in @page directive,something like: <%@ page errorPage="ErrorHandling.jsp" %> The error page, in this case ' ErrorHandling.jsp', has 'isErrorPage' attribute in page directive which should be set to true. When a JSP page has been declared an errorPage, it is made available an object with name of "exception" of type java.lang.Throwable.

What is session facade?
        A session façade is an EJB design pattern in which a session bean is works like a wrapper over entity beans. A client does not have a direct access to Entity beans but through session beans only for reducing network overhead.
                                             Usually stateless session beans are used as single access point for the clients but stateful session beans can also be used for the same purpose. A layer of session beans exposed to clients to access not only gives a clean approach towards client access to bean components but also reduce network calls so as to make the whole system of high performance.

What is JTS ?
        JTS is Transaction related services and it specifies the implementation of a Transaction Manager, which supports the Java Transaction API (JTA) 1.1 Specification at the high-level and implements the Java mapping of the OMG Object Transaction Service (OTS) 1.1 Specification at the low-level. JTS uses the standard CORBA ORB/TS interfaces and Internet Inter-ORB Protocol (IIOP) for transaction context propagation between JTS Transaction Managers.

What are Bean-Managed Transactions?
         Bean Managed Transactions are - -Not supported in entity beans -Either Session or Message Driven Beans can have Bean Managed Transactions. -These transactions could be of two types: a.JDBC Transactions: - is controlled by the transaction manager of the DBMS. -invoke the commit and rollback methods of the java.sql.Connection interface. -The beginning of a transaction is implicit. - A transaction begins with the first SQL statement that follows the most recent commit, rollback, or connect statement. (This rule is generally true, but may vary with DBMS vendor.)
                 JTA(Java Transaction API) Transactions: -is controlled by the Java EE transaction manager which does not support nested transactions,means a new transaction cannot start unless previous one is finished. -use when transaction can span updates to multiple databases from different vendors. -invoke the begin, commit, and rollback methods of the javax.transaction.UserTransaction interface.

What is Connection Pooling? Is it advantageous?
         An EJB container provides the service of connection pooling in order to provide efficient way of database connectivity to its concurrent and continuous user requests. Whenever a client request for a database connection then an instance is picked from the connection pool to get an access to database as soon as user is through with his work instance is returned to connection pool. There is a limit specified by App server administrator for the availability of number of connections and beyond a specified limit a predefined number increases numbers of connection pool instances. When demand goes back to normal then access amount of connection pool instances are removed. This mechanism of connection pooling helps in smart and efficient use of system resources and improving the overall performance of the whole system.



Related

Interview Questions 4029538562532087731

Post a Comment

Follow Us

Hot in week

Recent

Comments

Side Ads

item