ThoughtWorks Core Java Interview Questions Answers

ThoughtWorks Most Frequently Asked Core Java Interview Questions Answers

What Is A Jvm?

JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

What Is The Difference Between A Jdk And A Jvm?

JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

What Is A Pointer And Does Java Support Pointers?

Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.

What Is The Base Class Of All Classes?

java.lang.Object

Does Java Support Multiple Inheritance?

Java doesn't support multiple inheritance.

Is Java A Pure Object Oriented Language?

Java uses primitive data types and hence is not a pure object oriented language.

Are Arrays Primitive Data Types?

In Java, Arrays are objects.

What Is Difference Between Path And Classpath?

Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.
ThoughtWorks Most Frequently Asked Core Java Interview Questions Answers
ThoughtWorks Most Frequently Asked Core Java Interview Questions Answers

What Are Local Variables?

Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them.

What Are Instance Variables?

Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.

How To Define A Constant Variable In Java?

The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also. static final int PI = 2.14; is an example for constant.

Should A Main Method Be Compulsorily Declared In All Java Classes?

No not required. main method should be defined only if the source class is a java application.

What Is The Return Type Of The Main Method?

Main method doesn't return anything hence declared void.

Why Is The Main Method Declared Static?

main method is called by the JVM even before the instantiation of the class hence it is declared as static.

What Is The Arguement Of Main Method?

main method accepts an array of String object as arguement.

Can A Main Method Be Overloaded?

Yes. You can have any number of main methods with different method signature and implementation in the class.

Can A Main Method Be Declared Final?

Yes. Any inheriting class will not be able to have it's own default main method.

Does The Order Of Public And Static Declaration Matter In Main Method?

No it doesn't matter but void should always come before main().

Can A Source File Contain More Than One Class Declaration?

Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public.

What Is A Package?

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

Which Package Is Imported By Default?

java.lang package is imported by default even without a package declaration.

Can A Class Declared As Private Be Accessed Outside It's Package?

Not possible.

Can A Class Be Declared As Protected?

A class can't be declared as protected. only methods can be declared as protected.

What Is The Access Scope Of A Protected Method?

A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.

What Is The Purpose Of Declaring A Variable As Final?

A final variable's value can't be changed. final variables should be initialized before using them.

What Is The Impact Of Declaring A Method As Final?

A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.

I Don't Want My Class To Be Inherited By Any Other Class. What Should I Do?

You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.

Can You Give Few Examples Of Final Classes Defined In Java Api?

java.lang.String,java.lang.Math are final classes.

How Is Final Different From Finally And Finalize?

final is a modifier which can be applied to a class or a method or a variable. final class can't be inherited, final method can't be overridden and final variable can't be changed.

finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment.

finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.

Can A Class Be Declared As Static?

No a class cannot be defined as static. Only a method,a variable or a block of code can be declared as static.

When Will You Define A Method As Static?

When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.

Post a Comment

Previous Post Next Post