Java Questions

Q:

What is static initializer block? What is its use?

Answer

A static initializer block is a block of code that declares with the static keyword. It normally contains the block of code that must execute at the time of class loading. The static initializer block will execute only once at the time of loading the class only.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1671
Q:

What is Shallow and deep cloning in Java?

Answer

Cloning refers to creating duplicate copies of objects in java.


Shallow Cloning: Shallow cloning is a bitwise copy of an object. New object is created which is an exact copy that of the original one. In case any objects are referring the fields of these objects, just the references are copied.


Deep Cloning: In deep cloning, complete duplicate copy of the original copy is created. Deep cloning creates not only the primitive values of the original objects but also copies all its sub objects as well.


Clonable interface is used to perform cloning in java.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1669
Q:

What are Native methods in Java?

Answer

Java applications can call code written in C, C++, or assembler. This is sometimes done for performance and sometimes to access the underlying host operating system or GUI API using the JNI.


 


The steps for doing that are:


First write the Java code and compile it


Then create a C header file


Create C stubs file


Write the C code


Create shared code library (or DLL)


Run application

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1664
Q:

What is local class?

Answer

Local class is class defined inside method


EX;


class A { // top level class


  public static void main(string[] args) {


   class B { // local class


   }


}


}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1653
Q:

What are the various elements of OOPS?

Answer

Various elements of OOP are:


• Object


• Class


• Method


• Encapsulation


• Information Hiding


• Inheritance


• Polymorphism

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1642
Q:

What are wrapped classes ?

Answer

Wrapped classes are classes that allow primitive types to be accessed as objects.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1642
Q:

What are the steps required to execute a query in JDBC?

Answer

First we need to create an instance of a JDBC driver or load JDBC drivers, then we need to register this driver with DriverManager class. Then we can open a connection. By using this connection , we can create a statement object and this object will help us to execute the query.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1640
Q:

Can we compile a java program without main?

Answer

Yes, we can. In order to compile a java program, we don't require any main method. But to execute a java program we must have a main in it (unless it is an applet or servlet). Because main is the starting point of a java program.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1623