Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Core Java Interview Questions Part 01 _ iNeuron

This document contains a series of interview questions and answers related to Core Java, covering fundamental concepts such as the Java programming language, its features, and components like JVM, JDK, and class loaders. It also discusses variables, data types, operators, control statements, methods, constructors, and the concept of method overloading. The content is structured to help candidates prepare for Java-related interviews by providing essential knowledge and explanations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Core Java Interview Questions Part 01 _ iNeuron

This document contains a series of interview questions and answers related to Core Java, covering fundamental concepts such as the Java programming language, its features, and components like JVM, JDK, and class loaders. It also discusses variables, data types, operators, control statements, methods, constructors, and the concept of method overloading. The content is structured to help candidates prepare for Java-related interviews by providing essential knowledge and explanations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

INTERVIEW QUESTIONS - Core Java (Part- 1) of 5

1. Tell me about Java as a programming language?

Java is a high-level, object-oriented, robust, secure, high-performance,


Multithreaded programming language.It is also platform-independent.
James Gosling and his team at SunMicrosystems created it.

2. List the Java programming language's features?

• Object-oriented

• Platform-independent

• Robust

• Secure

• Multithreaded

• Distributed

• Both Compiled and Interpreted

3. What enables Java to be "write once, run anywhere"?

When Java code is compiled ,Java compiler converts the Java programs
into the class file (Byte Code) which is the intermediate language
between source code and machine code. This bytecode can be run on any
machine and is not platform-specific.

4. What exactly do you mean by Java virtual machine?


JVM is known as the Java Virtual Machine.The JVM provides the
runtime environment in which Java bytecode can be executed. JRE is the
name of its implementation. For every platform there are different JVMs
(so JVM is platform dependent).
5. What is the difference between JDK and JVM?

The Java Development Kit (JDK) is used for development. JDK contains
all of the tools, executables, and binaries needed to compile, debug, and
run a Java programme. JVM is known as the Java Virtual Machine.The
JVM provides the runtime environment in which Java bytecode can be
executed.

6. Why isn't Java a pure object-oriented language?


Because Java supports primitive data types such as byte, boolean, char,
short, int, float, long, and double, it is not a pure object oriented language.

7. What exactly is a ClassLoader?


TIn Java, a classloader is a subsystem of the Java Virtual Machine that is
responsible for loading class files when a programme is executed;
ClassLoader is the first to load the executable file. Java classloaders
include Bootstrap, Extension, and Application.

8. In Java, What is a class?


Everything in Java is associated with classes and objects. A class is
defined as a blueprint for creating objects as well as defining fields and
method.
9. What does Object mean in Java?
The instance of a class is called an object. Every object in Java has
property(fields) and behavior(method).
To create an object of a class, specify the class name, followed by the
object name, and use the new keyword.

class Demo{

int age; //field

void disp(){ /// method

Creation of object : Demo d=new Demo();


10.What are the different types of variables in Java?

Java, there are primarily three types of variables available, they are as
follows a) Static variable b) Instance variable c)Local Variable

Static Variables: A variable that has the static keyword in its declaration
is referred to as a static variable. Local variables cannot be static
variables, and memory is only allocated once for them in the Heap area at
the time of class loading.

Instance variable: The variable declared inside the class but outside the
body of the method or block or loop is called the instance variable. This
variable cannot be declared as static and its value is instance-
specific(Object specific) for every new object created, new memory will
be allocated inside that object in heap area

Local variable: A local variable is a variable that is declared inside the


method or loop or block body of a class. The static keyword cannot be
used to declare a local variable.

11.What if we write public static void as static public void?

Since Java specifier order doesn't, the programmes' compilation and


executions are both done successfully.

12.What is the local variables' default value?

The local variables are not initialized to any default value, neither
primitives nor object references

13.What are the data types in Java?

The data types define the different size and values that can be stored in
the variable. In Java, there are two kinds of data types:
Primitive data types: The primitive data types include boolean, char, byte,
short, int, long, float and double.
Non-primitive data types include: Classes, Interfaces, String and Arrays
are examples of non-primitive data types.
14. What are primitive data types?

Primitive data type specifies the size and type of variable values, and it
has no additional methods. The primitive data types include char, byte,
short, int float, double, and boolean.
char 2 bytes ‘u0000’

byte 1 byte 0

short 2 bytes 0

int 4 bytes 0

long 8 bytes 0L

float 4 bytes 0.0f

double 8 bytes 0.0d

boolean false

15.What distinguishes the increment operators ++a and a++?

++a is a pre - increment


a++ is the post - increment.
The prefix increment is used to return the value after incrementing the
present value.

In case of postfix increment, the value is returned before


incrementing it.

16. What exactly is a ternary operator?

In Java, the ternary operator is used to replace the if-else expression. The
ternary operator's representation or syntax is as follows:
variable= (expression) ? expression true : expression false
17. What are Java keywords?

Java has a set of reserved keywords that cannot be used as variables,


methods, classes, or other identifiers.
void, if, static, switch, break, continue, new, while, extends, this, super,
return …….

18.What are Java's selection/conditional statements?

A selection/conditional statement is primarily used to direct programme


control to a specific flow based on a true or false condition.

Selection/Conditional statements in Java include:

1. If statement

2. If-else statement

3. Switch statements

19. What are the various kinds of iterative/looping statements?

These are the statements that are repeated continuously until the
termination condition is not met.
Looping/iterative statements in Java include:

1. For loop

2. For each loop

3. While loop

4. Do-while loop
20.In Java, how many different types of operators are there?

Arithmetic operators
Assignment operators
Logical operators
Relational operators
Bitwise operators
Unary operators
Ternary operators
Shift operators

21.Explain the main method public static void main(String args[]) in


Java.

In Java, main() is the entry point for any Java programme. The syntax is
always public static void main (String[] args).
public: The access modifier public specifies who has access to this
method. This Method is public, which means that it can be accessed by
any Class.
Static : In Java, main() is made static so that it can be accessed without
creating an Instance of the class(Object). If main is not made static, the
compiler will throw an error because the JVM calls main() before
creating any objects and only static methods can be directly invoked via
the class.
void: This is the method's return type. Void denotes a method that does
not return any value.
main: This is the name of the method that the JVM looks for as a starting
point for an application with a specific signature.
String args[]: This is the parameter to receive command line argument.

22.What is a constructor in Java?

A constructor is a special type of method or setter which is used to


initialize the object.
It needs to be given the same name as the class. It is also automatically
called when an object is created and has no return type.
There are two types of constructors:
Default Constructor: A default constructor is the one which does not take
any inputs(zero parameters). In other words, default constructors are the
no argument constructors which will be created by default in case you no
other constructor is defined by the user in class. Its main purpose is to
initialize the instance variables with the default values.

Parameterized Constructor: The parameterized constructor in Java, is the


constructor which is capable of initializing the instance variables(fields)
with the provided values. In other words, the constructors which take the
arguments are called parameterized constructors.

23.What does a default Constructor do?

The default constructor's purpose is to assign the default value to the


objects. If there is no Constructor in the class, the java compiler builds
one implicitly.

24.Can we overload the constructors?

Yes, constructors can be overloaded by changing the number of


parameters accepted or by modifying the data type of the parameters.

25.What is method overloading?

It refers to creating multiple methods with the same name within a class
and different parameters and data types. It can also be referred to as
compile time polymorphism.

26.What is Constructor chaining in Java?

It refers to one constructor calling another Constructor.


It can be achieved using this() call and super() call.
this() is used to call constructor within same class
super() is used to call constructor of parent class
27.Can you talk about static variables in Java ?

Static variables are created using static keyword. Whenever a common


copy of data has to be shared among all the objects of a class then we
must use static variables. Memory will be allocated once at the time of
class loading in the Heap area.

28.What is a static block?

It is used to initialize the static data members(static variables). It gets


executed even before the main method at the time of class loading.

29.What is a static method in Java?

It is a method which is object independent and created using a static


keyword. It can be invoked using class name directly and can also be
invoked using object reference if required.
It cannot access non-static variables.

30.Is it possible to make constructors static?

The static context (method, block, or variable) belongs to the class, not
the object, as we know constructors are only called when an
object is created, making them static makes no sense. However,
attempting to do so will result in a compiler error.

You might also like