Professional Documents
Culture Documents
JAVA Answers.
JAVA Answers.
JAVA Answers.
1. JVM
JVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the
runtime environment in which java byte code can be executed. It is a specification.
JVMs are available for many hardware and software platforms (so JVM is platform
dependent).
JRE
JRE stands for Java Runtime Environment. It is the implementation of JVM.
JDK
JDK is an acronym for Java Development Kit. It physically exists. It contains JRE +
development tools.
2.
Many types:
1. Class(Method) Area
2. Heap
3. Stack
3.
4.
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:
1. Runtime Environment
6.
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 platform specific and
hence can be fed to any platform.
7.
The class loader is a subsystem of JVM that is used to load classes and interfaces. There
are many types of class loaders e.g. Bootstrap class loader, Extension class loader,
System class loader, Plug-in class loader etc.
8.
The default constructor provides the default values to the objects. The java compiler
creates a default constructor only if there is no constructor in the class.
9.
Yes, that is current instance (You cannot use return type yet it returns a value).
10.
11.
The local variables are not initialized to any default value, neither primitives nor object
references.
13.
Object based programming languages follow all the features of OOPs except Inheritance.
Examples of object based programming languages are JavaScript, VBScript etc.
14.
15.
o Constructor is just like a method that is used to initialize the state of an object. It
is invoked at the time of object creation.
16.
17.
o Static variable is used to refer the common property of all objects (that is not
unique for each object) e.g. company name of employees, college name of
students etc.
o Static variable gets memory only once in class area at the time of class loading.
18.
because object is not required to call static method if It were non-static method,jvm
creates object first then call main() method that will lead to the problem of extra
memory allocation.
19.
20.
Instance method
A method i.e. not declared as static is known as instance method.
22.
Inheritance is a mechanism in which one object acquires all the properties and behaviour
of another object of another class. It represents IS-A relationship. It is used for Code
Reusability and Method Overriding.
23.
To reduce the complexity and simplify the language, multiple inheritance is not
supported in java in case of class.
24.
Holding the reference of the other class within some other class is known as
composition.
25.
Pointer is a variable that refers to the memory address. They are not used in java
because they are unsafe (unsecured) and complex to understand.
26.
If a class have multiple methods by same name but different parameters, it is known as
Method Overloading. It increases the readability of the program.
28.
Yes, You can have many main () methods in a class by overloading the main method.
29.
No, you can't override the static method because they are the part of class not object.
30.
Method Overloading
1) Method overloading increases the readability of the program.
Method Overriding
1) Method overriding provides the specific implementation of the method that is
already provided by its super class.
31.
If you make any variable as final, you cannot change the value of final variable(It will be
constant).
32.
33.
34.
Yes, such as, public static final void main (String [] args){}.
35.
JAVA ANSWERS.
In case of static binding type of object is determined at compile time whereas in dynamic
binding type of object is determined at runtime.
36.
37.
Abstraction hides the implementation details whereas encapsulation wraps code and data
into a single unit.
38.
39.
No, because abstract method needs to be overridden whereas you can't override final
method.
40.
Interface is a blueprint of a class that have static constants and abstract methods. It can
be used to achieve fully abstraction and multiple inheritances.
41.
Abstract class
42.
43.
JAVA ANSWERS.
A package is a group of similar type of classes’ interfaces and sub-packages. It
provides access protection and removes naming collision.
44.
By static import, we can access the static members of a class directly, there is no to
qualify it with the class name.
45.
The classes that extend throwable class except Runtime Exception and Error are known
as checked exceptions e.g.IOException, SQLException etc. Checked exceptions are
checked at compile-time.
46.
throwable.
47.
It is not necessary that each try block must be followed by a catch block. It should be
followed by either a catch block OR a finally block. And whatever exceptions are likely to
be thrown should be declared in the throws clause of the method.
48.
49.
Throw keyword
1) Throw is used to explicitly throw an exception.
throws keyword
1) throws is used to declare an exception.
50.
51.
Because java uses the concept of string literal. Suppose there are 5 reference
variables,all referes to one object "sachin".If one reference variable changes the value of
the object, it will be affected to all the reference variables. That is why string objects are
immutable in java.
52. String is an immutable object. String Buffer is a mutable object. String Buffer is
synchronized whereas String Builder is not synchronized.
53.
A class which is declared inside another class is known as nested class. There are 4
types of nested class member inner class, local inner class, anonymous inner class and
static nested class.
54.
Any interface i.e. declared inside the interface or class, is known as nested interface. It
is static by default.
55.
56.
Finalize () method is invoked just before the object is garbage collected. It is used to
perform cleanup processing.
57.
Final: final is a keyword, final can be variable, method or class. You, can't change the
value of final variable, can't override final method, can't inherit final class.
Finally: finally block is used in exception handling. Finally block is always executed.
Finalize (): finalize () method is used in garbage collection. Finalize () method is
invoked just before the object is garbage collected.The finalize () method can be used
to perform any cleanup processing.
58.
Serialization is a process of writing the state of an object into a byte stream. It is
mainly used to travel object's state on the network.
JAVA ANSWERS.
59.
Yes, by changing the runtime behaviour of a class if the class is not secured.
60.
An applet is a small java program that runs inside the browser and generates dynamic
contents.
61.
o Thread is lightweight.
62.
63.
The join () method waits for a thread to die. In other words, it causes the currently
running threads to stop executing until the thread it joins with completes its task.
64.
Wait ()
sleep ()
65.
Yes, but it will not work as a thread rather it will work as a normal object so there will
not be context-switching between the threads.
66.
67.
68.
If you make any static method as synchronized, the lock will be on the class not on
object.
69.
The notify () is used to unblock one waiting thread whereas notify All () method is
used to unblock all the threads in waiting state.
70.
Deadlock is a situation when two threads are waiting on each other to release a
resource. Each thread waiting for a resource which is held by the other waiting thread.
71.
ArrayList
Vector
Vector is synchronized.
72.
ArrayList
LinkedList
73.
List can contain duplicate elements whereas Set contains only unique elements.
74.
Set contains values only whereas Map contains key and values both.
JAVA ANSWERS.
75.
76.
77.
The Dictionary class provides the capability to store key-value pairs.
78.
JDBC is a Java API that is used to connect and execute query to the database. JDBC
API uses jdbc drivers to connect to the database.
79.
JDBC Driver is a software component that enables java application to interact with the
database. There are 4 types of JDBC drivers:
80.
o Creating connection
o Creating statement
o Executing queries
o Closing connection
JAVA ANSWERS.
81.
The java.sql package contains interfaces and classes for JDBC API.
Interfaces:
o Connection
o Statement
o Prepared Statement
o Result Set
o ResultSetMetaData
o Database Metadata
Classes:
o Driver Manager
o Blob
o Clob
o Types
o SQLException etc.
82.
1. Statement
2. PreparedStatement
3. CallableStatement
83.
84.
JAVA ANSWERS.
The Connection interface maintains a session with the database. It can be used
for transaction management. It provides factory methods that returns the instance of
Statement, PreparedStatement, CallableStatement and Database Metadata.
85.
The Result Set object represents a row of a table. It can be used to change the
cursor pointer and get the information from the database.
86. The DatabaseMetaData interface returns the information of the database such as
username, driver name, driver version, number of tables, number of views etc.