Search This Blog

Sunday, June 27, 2021

Most common Core Java Interview Questions

1) What is the difference between an Abstract class and an Interface?

1. Abstract classes may have some executable methods and methods left unimplemented. Interfaces contain no implementation code.

2. An class can implement any number of interfaces, but subclass at most one abstract class.

3. An abstract class can have nonabstract methods. All methods of an interface are abstract.

4. An abstract class can have instance variables. An interface cannot.

5. An abstract class can define the constructor. An interface cannot.

6. An abstract class can have any visibility: public, protected, private or none (package). An interface's visibility must be public or none (package).

7. An abstract class inherits from Object and includes methods such as clone() and equals().


2) What are checked and unchecked exceptions?

Java defines two kinds of exceptions :

• Checked exceptions: Exceptions that inherit from the Exception class are checked exceptions. Client code has to handle the checked exceptions thrown by the API, either in a catch clause or by forwarding it outward with the throws clause. Examples - SQLException, IOException.

• Unchecked exceptions: RuntimeException also extends from Exception. However, all of the exceptions that inherit from RuntimeException get special treatment. There is no requirement for the client code to deal with them, and hence they are called unchecked exceptions. Example Unchecked exceptions are NullPointerException, OutOfMemoryError, DivideByZeroException typically,programming errors.


3) What is the difference between C++ & Java?

Well as Bjarne Stroustrup says "..despite the syntactic similarities, C++ and Java are very different languages. In many ways, Java seems closer to Smalltalk than to C++..". 

Here are a few I discovered:

• Java is multithreaded

• Java has no pointers

• Java has automatic memory management (garbage collection)

• Java is platform-independent (Stroustrup may differ by saying "Java is a platform"

• Java has built-in support for comment documentation

• Java has no operator overloading

• Java doesn’t provide multiple inheritance.

• There are no destructors in Java


4) What are the statements in JAVA?

Statements are equivalent to sentences in natural languages. A statement forms a complete unit of execution. The following types of expressions can be made into a statement by terminating the expression with a semicolon

• Assignment expressions

• Any use of ++ or --

• Method calls

• Object creation expressions

These kinds of statements are called expression statements. In addition to these kinds of expression statements, there are two other kinds of statements. A declaration statement declares a variable. A control flow statement regulates the order in which statements get executed. The for loop and the if statement are both examples of control flow statements.


5) What is the JAR file?

JavaARchive files are a big glob of Java classes, images, audio, etc., compressed to make one simple, smaller file to ease Applet downloading. Normally when a browser encounters an applet, it goes and downloads all the files, images, audio, used by the Applet separately. This can lead to slower downloads.

No comments:

Post a Comment

Submit a Comment