Java Questions

Q:

What is a package?

Answer

Package is a collection of related classes and interfaces. package declaration should be first statement in a java class.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 1426
Q:

What is the difference between method overriding and overloading?

Answer

Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1421
Q:

In a class if private data member is declared then how to set data to that private data member?

Answer

By using method.


The method used to set the data is called setter method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1415
Q:

What is JAR file? what are the main uses of JAR files?

Answer

JAR files are java's version of ZIP files. In fact, JAR uses the ZIP file format.


uses:


- to compress a number of . class files into one file


- to make a java executable JAR file.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1408
Q:

What is the security mechanism used in java?

Answer

Java uses sand box security model.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1403
Q:

What is the difference between array and ArrayList ?

Answer

Array is collection of same data type. Array size is fixed, It cannot be expanded.


 


But ArrayList is a growable collection of objects.ArrayList is a part of Collections Framework and can work with only objects.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1400
Q:

What is the syntax to create the object?

Answer

new ClassName();


This expression creates object in heap area and returns that obj address. Here JVM creates object but JVM does not returns object original address. JVM returns duplicate address, duplicate address is also called as hashcode. 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1396
Q:

When should I use abstract classes and when should I use interfaces?

Answer

Use Interfaces when…


- You see that something in your design will change frequently.


- If various implementations only share method signatures then it is better to use Interfaces.


- You need some classes to use some methods which you don't want to be included in the class, then you go for the interface, which makes it easy to just implement and make use of the methods defined in the interface.


 


Use Abstract Class when…


- If various implementations are of the same kind and use common behavior or status then abstract class is better to use.


- When you want to provide a generalized form of abstraction and leave the implementation task with the inheriting subclass.


- Abstract classes are an excellent way to create planned inheritance hierarchies. They're also a good choice for nonleaf classes in class hierarchies.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1393