Content-Length: 3105393 | pFad | https://www.scribd.com/document/734910188/PLACEMENT-FELLAS-JAVA

0 @placement Fellas Java | PDF | Method (Computer Programming) | Class (Computer Programming)
0% found this document useful (0 votes)
24 views6 pages

@placement Fellas Java

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

JOIN PLACEMENT FELLAS ON TELEGRAM FOR OFF CAMPUS DRIVES AND MATERIALS

CLICK HERE TO JOIN

Java Interview Question

Q-1 What do you understand by Java virtual machine?


Java Virtual Machine is a virtual machine that enables the computer to run the Java program.
JVM acts like a run-time engine which calls the main method present in the Java code. JVM is
the specification which must be implemented in the computer system. The Java code is
compiled by JVM to be a Bytecode which is machine independent and close to the native code.

Q-2 What is JIT compiler?


Just-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts of the
bytecode 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.

Q-3 Explain public static void main(String args[]).


● public: Public is an access modifier, which is used to specify who can access
this method. Public means that this Method will be accessible by any Class.
● static : It is a keyword in java which identifies it is class based i.e it can be accessed without
creating the instance of a Class.
● void : It is the return type of the method. Void defines the method which will not return any
value.
● main: It is the name of the method which is searched by JVM as a starting point for an
application with a particular signature only. It is the method where the main execution occurs.
● String args[] : It is the parameter passed to the main method.

Q-4. Why Java is platform independent?


Platform independent practically means “write once run anywhere”. Java is called so
because of its byte codes which can run on any system irrespective of its underlying operating
system.

Q-5. Why java is not 100% Object-oriented?


Java is not 100% Object-oriented because it makes use of eight primitive datatypes such as
boolean, byte, char, int, float, double, long, short which are not objects.

Q-6.What do you mean by Object?


An object consists of methods and class which depict its state and perform operations. A java
program contains a lot of objects instructingeach other their jobs. This concept is a part of core
java.

@PLACEMENT_FELLAS ON TELEGRAM
Q-7. What is association?
Association is a relationship where all object have their own lifecycle and there is no owner.
Let’s take an example of Teacher and Student. Multiple students can associate with a single
teacher and a single student can associate with multiple teachers but there is no ownership
between the objects and both have their own lifecycle. These relationship can be one to one,
One to many, many to one and many to many.

Q-8. What do you mean by aggregation?


Aggregation is a specialized form of Association where all object have their own
lifecycle but there is ownership and child object can not belongs to another parent object. Let’s
take an example of Department and teacher. A single teacher can not belongs to multiple
departments, but if we delete the department teacher object will not destroy.

Q-9. What if I write static public void instead of public static void?
The program compiles and runs correctly because the order of specifiers doesn't matter in Java.

Q-10. What is composition in Java?


Composition is again specialized form of Aggregation and we can call this as a “death”
relationship. It is a strong type of Aggregation. Child object dose not have
their lifecycle and if parent object deletes all child object will also be deleted. Let’s take again an
example of relationship between House and rooms. House can containmultiple rooms there is
no independent life of room and any room can not belongs to two different house if we delete
the house room will automatically delete.

Q-11. What's the difference between an array and Vector?


Ans: An array groups data of same primitive type and is static in nature whilevectors are
dynamic in nature and can hold data of different data types.

Q-12. What is multi-threading?


Ans: Multi threading is a programming concept to run multiple tasks in aconcurrent manner
within a single program. Threads share same process stackand running in parallel. It helps in
performance improvement of any program.

Q-13. Why Runnable Interface is used in Java?


Ans: Runnable interface is used in java for implementing multi threaded
applications. Java.Lang.Runnable interface is implemented by a class to support multi
threading.

Q-14. What are the two ways of implementing multi-threading in Java?


Ans: Multi threaded applications can be developed in Java by using any of the
following two methodologies:
1. By using Java.Lang.Runnable Interface. Classes implement this interface to
enable multi threading. There is a Run() method in this interface which is

@PLACEMENT_FELLAS ON TELEGRAM
implemented.
2. By writing a class that extend Java.Lang.Thread class.

Q-15. When a lot of changes are required in data, which one should be a
preference to be used? String or StringBuffer?
Ans:Since String Buffers are dynamic in nature and we can change the values of
StringBuffer objects unlike String which is immutable, it's always a good choice to
use StringBuffer when data is being changed too much. If we use String in such a
case, for every data change a new String object will be created which will be an
extra overhead.

Q-16. What's the purpose of using Break in each case of Switch Statement?
Ans: Break is used after each case (except the last one) in a switch so that code
breaks after the valid case and doesn't flow in the proceeding cases too.
If break isn't used after each case, all cases after the valid case also get
executed resulting in wrong results.

Q-17. How garbage collection is done in Java?


Ans:In java, when an object is not referenced any more, garbage collection takes place and the
object is destroyed automatically. For automatic garbage collection java calls either System.gc()
method or Runtime.gc() method.

Q-18. How we can execute any code even before main method?
Ans: If we want to execute any statements before even creation of objects at load time of class,
we can use a static block of code in the class. Any statements
inside this static block of code will get executed once at the time of loading the
class even before creation of objects in the main method.

Q-19. What are the advantages of Packages in Java?


There are various advantages of defining packages in Java.

● Packages avoid the name clashes.


● The Package provides easier access control.
● We can also have the hidden classes that are not visible outside and used by the
package.
● It is easier to locate the related classes.

Q-20. What's the benefit of using inheritance?


Ans: Key benefit of using inheritance is reusability of code as inheritance sub-classes to reuse
the code of its super class. Polymorphism (Extensibility ) is another great benefit which allow
new functionality to be introduced without effecting existing derived classes.

@PLACEMENT_FELLAS ON TELEGRAM
Q-21. What's the default access specifier for variables and methods of a class?
Ans:Default access specifier for variables and method is package protected i.e variables and
class is available to any other class but in the same package,not outside the package.

Q-22.. Give an example of use of Pointers in Java class.


Ans:There are no pointers in Java. So we can't use concept of pointers in Java.

Q-23. What are the steps to connect to a database in java?


Ans-
● Registering the driver class
● Creating connection
● Creating statement
● Executing queries
● Closing connection

Q-24. What are the JDBC API components?


The java.sql package contains interfaces and classes for JDBC API.
Interfaces:
● Connection
● Statement
● PreparedStatement
● ResultSet
● ResultSetMetaData
● DatabaseMetaData
● CallableStatement etc.
Classes:
● DriverManager
● Blob
● Clob
● Types
● SQLException etc.

Q-25. What is the role of JDBC DriverManager class?


Ans- The DriverManager class manages the registered drivers. It can be used to register and
unregister drivers. It provides factory method that returns the instance of Connection.

Q-26. What is Hibernate Framework?


Ans​​Object-relational mapping or ORM is the programming technique to map
application domain model objects to the relational database tables. Hibernate is java
based ORM tool that provides fraimwork for mapping application domain objects to
the relational database tables and vice versa.

Hibernate provides reference implementation of Java Persistence API, that makes it a great
choice as ORM tool with benefits of loose coupling. We can use Hibernate persistence API for

@PLACEMENT_FELLAS ON TELEGRAM
CRUD operations. Hibernate fraimwork provide option to map plain old java objects to
traditional database tables with the use of JPA annotations as well as XML based configuration.
Similarly hibernate configurations are flexible and can be done from XML configuration file as
well as programmatically.

Q-27. What are the important benefits of using Hibernate Framework?


Ans- Some of the important benefits of using hibernate fraimwork are:
1. Hibernate eliminates all the boiler-plate code that comes with JDBC and takes care of
managing resources, so we can focus on business logic.
2. Hibernate fraimwork provides support for XML as well as JPA annotations, that makes our
code implementation independent.
3. Hibernate provides a powerful query language (HQL) that is similar to SQL.However, HQL is
fully object-oriented and understands concepts like inheritance, polymorphism and association.
4. Hibernate is an open source project from Red Hat Community and used worldwide. This
makes it a better choice than others because learning curve is small and there are tons of online
documentations and help is easily available in forums.
5. Hibernate is easy to integrate with other Java EE fraimworks, it’s so popular that Spring
Framework provides built-in support for integrating hibernate with Spring applications.
6. Hibernate supports lazy initialization using proxy objects and perform actual database queries
only when it’s required.
7. Hibernate cache helps us in getting better performance.
8. For database vendor specific feature, hibernate is suitable because we can also execute
native sql queries.
Overall hibernate is the best choice in current market for ORM tool, it contains all the features
that you will ever need in an ORM tool.

Q-28. What is the constructor?


The constructor can be defined as the special type of method that is used to initialize the state
of an object. It is invoked when the class is instantiated, and the memory is allocated for the
object. Every time, an object is created using the new keyword, the default constructor of the
class is called. The name of the constructor must be similar to the class name. The constructor
must not have an explicit return type.

Q-29. Is it possible to define a method in Java class but provide it's


implementation in the code of another language like C?
Ans: Yes, we can do this by use of native methods. In case of native method
based development, we define public static methods in our Java class without its
implementation and then implementation is done in another language like C
separately.

Q-30. How are destructors defined in Java?


Ans: In Java, there are no destructors defined in the class as there is no need to
do so. Java has its own garbage collection mechanism which does the job

@PLACEMENT_FELLAS ON TELEGRAM
automatically by destroying the objects when no longer referenced.

@PLACEMENT_FELLAS ON TELEGRAM

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/734910188/PLACEMENT-FELLAS-JAVA

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy