Core Java Interview Questions
Core Java Interview Questions
Core Java Interview Questions
CORE
JAVA
...........................................................................................................................................................
2
WHY
IS
JAVA
SO
POPULAR?
.............................................................................................................................................
2
WHAT
IS
PLATFORM
INDEPENDENCE?
...............................................................................................................................
2
WHAT
ARE
THE
IMPORTANT
DIFFERENCES
BETWEEN
C++
AND
JAVA?
.......................................................................................
3
WHAT
ARE
WRAPPER
CLASSES?
........................................................................................................................................
3
WHAT
ARE
THE
DIFFERENT
UTILITY
METHODS
PRESENT
IN
WRAPPER
CLASSES?
...........................................................................
4
WHAT
IS
AUTO
BOXING?
................................................................................................................................................
5
ARE
ALL
STRINGS
IMMUTABLE?
.......................................................................................................................................
6
WHERE
ARE
STRING
LITERALS
STORED
IN
MEMORY?
..............................................................................................................
6
CAN
YOU
GIVE
EXAMPLES
OF
DIFFERENT
UTILITY
METHODS
IN
STRING
CLASS?
............................................................................
6
EXPLAIN
ABOUT
TOSTRING
METHOD
IN
JAVA?
....................................................................................................................
7
WHAT
IS
THE
USE
OF
EQUALS
METHOD
IN
JAVA?
..................................................................................................................
8
WHAT
ARE
THE
IMPORTANT
THINGS
TO
CONSIDER
WHEN
IMPLEMENTING
EQUALS
METHOD?
........................................................
9
WHAT
IS
THE
HASHCODE
METHOD
USED
FOR
IN
JAVA?
.........................................................................................................
9
WHAT
IS
CASTING?
......................................................................................................................................................
10
WHAT
IS
IMPLICIT
CASTING?
.........................................................................................................................................
10
WHAT
IS
EXPLICIT
CASTING?
.........................................................................................................................................
10
HOW
ARE
VARIABLES
INITIALIALIZED
IN
JAVA?
...................................................................................................................
10
WHAT
IS
A
NESTED
IF
ELSE?
CAN
YOU
EXPLAIN
WITH
AN
EXAMPLE?
.......................................................................................
11
ARRAYS
..............................................................................................................................................................
12
HOW
DO
YOU
DECLARE
AND
CREATE
AN
ARRAY?
................................................................................................................
12
CAN
THE
SIZE
OF
AN
ARRAY
BE
CHANGED
DYNAMICALLY?
.....................................................................................................
12
ENUM
................................................................................................................................................................
14
WHAT
IS
AN
ENUM?
....................................................................................................................................................
14
HOW
DO
YOU
CREATE
AN
ENUM
FROM
A
STRING
VALUE?
....................................................................................................
14
WHAT
IS
AN
ENUM
ORDINAL?
.......................................................................................................................................
14
HOW
DO
YOU
COMPARE
TWO
ENUMS?
...........................................................................................................................
14
CAN
YOU
USE
A
SWITCH
STATEMENT
AROUND
AN
ENUM?
...................................................................................................
14
Core
Java
Following
videos
cover
these
topics
in
great
detail.
In
addition
to
following
this
guide,
we
recommend
that
you
watch
the
videos
as
well.
Java
Interview
:
A
Freshers
Guide
-
Part
1:
https://www.youtube.com/watch?v=njZ48YVkei0.
Java
Interview
:
A
Freshers
Guide
-
Part
2:
https://www.youtube.com/watch?v=xyXuo0y-xoU
Java
Interview
Questions
www.JavaInterview.in
At
http://www.JavaInterview.in,
we
want
you
to
clear
java
interview
with
ease.
So,
in
addition
to
focussing
on
Core
and
Advanced
Java
we
also
focus
on
topics
like
Code
Reviews,
Performance,
Design
Patterns,
Spring
and
Struts.
We
have
created
more
than
20
videos
to
help
you
understand
these
topics
and
become
an
expert
at
them.
Visit
our
website
http://www.JavaInterview.in
for
complete
list
of
videos.
Other
than
the
videos,
we
answer
the
top
200
frequently
asked
interview
questions
on
our
website.
With
more
900K
video
views
(Apr
2015),
we
are
the
most
popular
channel
on
Java
Interview
Questions
on
YouTube.
Register
here
for
more
updates
:
https://feedburner.google.com/fb/a/mailverify?uri=RithusTutorials
Java
Interview
:
A
Freshers
Guide
-
Part
1:
https://www.youtube.com/watch?v=njZ48YVkei0
Java
Interview
:
A
Freshers
Guide
-
Part
2:
https://www.youtube.com/watch?v=xyXuo0y-xoU
xxxValue
methods
xxxValue methods help in creating primitives
Integer
integer
=
Integer.valueOf(57);
int
primitive
=
seven.intValue();//57
float
primitiveFloat
=
seven.floatValue();//57.0f
Float
floatWrapper
=
Float.valueOf(57.0f);
int
floatToInt
=
floatWrapper.intValue();//57
float
floatToFloat
=
floatWrapper.floatValue();//57.0f
parseXxx
methods
parseXxx methods are similar to valueOf but they return primitive values
Note
that
the
value
of
str3
is
not
modified
in
the
above
example.
The
result
should
be
assigned
to
a
new
reference
variable
(or
same
variable
can
be
reused).
String
concat
=
str3.concat("value2");
System.out.println(concat);
//value1value2
However,
if
new
operator
is
used
to
create
string
object,
the
new
object
is
created
on
the
heap.
Following
piece
of
code
create
2
objects.
//1.
String
Literal
"value"
-
created
in
the
"String
constant
pool"
//2.
String
Object
-
created
on
the
heap
String
str2
=
new
String("value");
What
is
casting?
Casting is used when we want to convert on data type to another.
There are two types of Casting
Implicit Casting
Explicit Casting
If
local
variables
are
used
before
initialization,
it
would
result
in
a
compilation
error.
package
com.rithus.variables;
public
class
VariableInitialization
{
public
static
void
main(String[]
args)
{
Player
player
=
new
Player();
//score
is
an
int
member
variable
-
default
0
System.out.println(player.score);//0
-
RULE1
//name
is
a
member
reference
variable
-
default
null
System.out.println(player.name);//null
-
RULE1
int
local;
//not
initialized
//System.out.println(local);//COMPILER
ERROR!
RULE3
String
value1;//not
initialized
//System.out.println(value1);//COMPILER
ERROR!
RULE3
String
value2
=
null;//initialized
System.out.println(value2);//null
-
NO
PROBLEM.
}
}
Arrays
Refer
to
this
video(https://www.youtube.com/watch?v=8bVysCXT-io)
for
exhaustive
coverage
of
all
the
interview
questions
about
arrays.
Lets
now
look
at
how
to
create
an
array
(define
a
size
and
allocate
memory).
marks
=
new
int[5];
//
5
is
size
of
array
Default
Values
byte,short,int,long
0
float,double
0.0
boolean
false
object null
Printing
a
2D
Array
int[][]
matrix3
=
{
{
1,
2,
3
},
{
4,
5,
6
}
};
System.out.println(matrix3);
//[[I@1d5a0305
System.out.println(
Arrays.toString(matrix3));
//[[I@6db3f829,
[I@42698403]
System.out.println(
Arrays.deepToString(matrix3));
//[[1,
2,
3],
[4,
5,
6]]
matrix3[0]
is
a
1D
Array
System.out.println(matrix3[0]);//[I@86c347
System.out.println(
Arrays.toString(matrix3[0]));//[1,
2,
3]
Enum
Refer
to
this
video
(https://www.youtube.com/watch?v=64Y7EP8-Ark)
for
exhaustive
coverage
of
all
the
interview
questions
about
Enum.
What
is
an
Enum?
Enum allows specifying a list of values for a Type. Consider the example below. It declares an enum
Season with 4 possible values.
enum
Season
{
WINTER,
SPRING,
SUMMER,
FALL
};
How
do
you
create
an
enum
from
a
String
value?
Function valueOf(String) is used to convert a string to enum.
//Converting
String
to
Enum
Season
season
=
Season.valueOf("FALL");
Function name() is used to find String value of an enum.
//Converting
Enum
to
String
System.out.println(season.name());//FALL
Videos
We
have
created
more
than
20
videos
to
help
you
understand
these
topics
and
become
an
expert
at
them.
You
can
watch
these
videos
for
free
on
YouTube.
Visit
our
website
http://www.JavaInterview.in
for
complete
list
of
videos.
We
answer
the
top
200
frequently
asked
interview
questions
on
the
website.
Register
here
for
more
updates
:
https://feedburner.google.com/fb/a/mailverify?uri=RithusTutorials
Java
Interview
:
A
Freshers
Guide
-
Part
1:
https://www.youtube.com/watch?v=njZ48YVkei0
Java
Interview
:
A
Freshers
Guide
-
Part
2:
https://www.youtube.com/watch?v=xyXuo0y-xoU
Java
Interview
:
A
Guide
for
Experienced:
https://www.youtube.com/watch?v=0xcgzUdTO5M
Collections
Interview
Questions
1:
https://www.youtube.com/watch?v=GnR4hCvEIJQ
Collections
Interview
Questions
2:
https://www.youtube.com/watch?v=6dKGpOKAQqs
Collections
Interview
Questions
3:
https://www.youtube.com/watch?v=_JTIYhnLemA
Collections
Interview
Questions
4:
https://www.youtube.com/watch?v=ZNhT_Z8_q9s
Collections
Interview
Questions
5:
https://www.youtube.com/watch?v=W5c8uXi4qTw