Core Java Interview Questions Part 01 _ iNeuron
Core Java Interview Questions Part 01 _ iNeuron
• Object-oriented
• Platform-independent
• Robust
• Secure
• Multithreaded
• Distributed
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.
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.
class Demo{
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
The local variables are not initialized to any default value, neither
primitives nor object references
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
boolean false
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?
1. If statement
2. If-else statement
3. Switch 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
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
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.
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.
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.