Java Interview Questions For Freshers: Why Java Is Platform Independent?
Java Interview Questions For Freshers: Why Java Is Platform Independent?
Java is called platform independent because of its byte codes which can run on any
system irrespective of its underlying operating system.
Java is not 100% Object-oriented because it makes use of eight primitive data
types such as boolean, byte, char, int, float, double, long, short which are not
objects.
Java doesn’t use pointers because they are unsafe and increases the complexity of
the program. Since, Java is known for its simplicity of code, adding the concept of
pointers will be contradicting. Moreover, since JVM is responsible for implicit
memory allocation, thus in order to avoid direct access to memory by the user,
pointers are discouraged in Java.
What is the difference between an array and an array list?
Array ArrayList
Cannot contain values of different
Can contain values of different data types.
data types
Size must be defined at the time of
Size can be dynamically changed
declaration
Need to specify the index in order to
No need to specify the index
add data
Arrays are not type parameterized Arraylists are type
Arrays can contain primitive data Arraylists can contain only objects, no
types as well as objects primitive data types are allowed
In Java, Map is an interface of Util package which maps unique keys to values.
The Map interface is not a subset of the main Collection interface and thus it
behaves little different from the other collection types. Below are a few of the
characteristics of Map interface:
1. Bootstrap ClassLoader
2. Extension ClassLoader
3. System/Application ClassLoader
What are access modifiers in Java?
In Java, access modifiers are special keywords which are used to restrict the access
of a class, constructor, data member and method in another class. Java supports
four types of access modifiers:
1. Default
2. Private
3. Protected
4. Public
A class in Java is a blueprint which includes all your data. A class contains fields
(variables) and methods to describe the behavior of an object. Let’s have a look at
the syntax of a class.
1 class Abc {
2 member variables // class body
3 methods}
An object is a real-world entity that has a state and behavior. An object has three
characteristics:
1. State
2. Behavior
3. Identity
Abstraction refers to the quality of dealing with ideas rather than events. It
basically deals with hiding the details and showing the essential things to the user.
Thus you can say that abstraction in Java is the process of hiding the
implementation details from the user and revealing only the functionality to them.
Abstraction can be achieved in two ways:
Example:
A class which inherits the properties is known as Child Class whereas a class
whose properties are inherited is known as Parent class.
Method Overloading :
In Method Overloading, Methods of the same class shares the same name
but each method must have a different number of parameters or parameters
having different types and order.
Method Overloading is to “add” or “extend” more to the method’s behavior.
It is a compile-time polymorphism.
The methods must have a different signature.
It may or may not need inheritance in Method Overloading.
Method Overriding:
In Method Overriding, the subclass has the same method with the same
name and exactly the same number and type of parameters and same return
type as a superclass.
Method Overriding is to “Change” existing behavior of the method.
It is a run time polymorphism.
The methods must have the same signature.
It always requires inheritance in Method Overriding.
If a child class inherits the property from multiple classes is known as multiple
inheritance. Java does not allow to extend multiple classes.
The problem with multiple inheritance is that if multiple parent classes have the
same method name, then at runtime it becomes difficult for the compiler to decide
which method to execute from the child class.
In case you are facing any challenges with these java interview questions, please
comment on your problems in the section below.
1.void forward()
2.void include()
1. Servlet is loaded
2. Servlet is instantiated
3. Servlet is initialized
4. Service the request
5. Servlet is destroyed
1. User Authentication
2. HTML Hidden Field
3. Cookies
4. URL Rewriting
5. Session Management API
JDBC Driver is a software component that enables java application to interact with
the database. There are 4 types of JDBC drivers:
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.
@Required
@Autowired
@Qualifier
@Resource
@PostConstruct
@PreDestroy
1. core tags
2. sql tags
3. xml tags
4. internationalization tags
5. functions tags
1. <%@ page session=“false” %>
1. try
2. catch
3. finally
4. throw
5. throws
String getMessage()
String getLocalizedMessage()
Synchronized Throwable getCause()
String toString()
void printStackTrace()
By implementing the Runnable interface.
By extending the Thread