Core Java 1 Mark Questions Part 1
What
is Java?
·
Java is an object-oriented
programming language.
·
It is a high-level programming
language developed by James Gosling in Sun Microsystem in 1995.
·
Java is a fast, secure and reliable
language used for many games, devices and applications.
Differentiate
between JDK, JRE and JVM.
·
JVM stands for Java Virtual Machine which provides runtime
environment for Java Byte Codes to be executed.
·
JRE (Java Runtime Environment) that includes sets of files
required by JVM during runtime.
·
JDK (Java Development Kit) consists of JRE along with the
development tools required to write and execute a program.
What
is IDE?
An Integrated Development
Environment is a software application that provides comprehensive
facilities to computer programmers for software development. An IDE normally
consists of a source code editor, build automation tools and a debugger.
Example Eclipse, NetBeans etc.
What
is Class?
Class is a template that describes
the data and behavior associated with instances of that class. A class is a
user defined blueprint or prototype from which objects are created.
What
is Object?
An Object is an Instance of Class.
In real-world an entity that has state and its behavior is known as an object.
For Example: A Car is an object. It has states (name, color, model) and its
behavior (changing gear, applying brakes, runnin).
What
is Data Encapsulation?
Encapsulation is a concept in Object
Oriented Programming for combining properties and methods in a single unit.
Encapsulation helps programmers to
follow a modular approach for software development as each object has its own
set of methods and variables and serves its functions independent of other
objects. Encapsulation also serves data hiding purpose.
What
are Loops in Java? What are three types of loops?
Looping is used in programming to
execute a statement or a block of statement repeatedly.
There are three types of loops in
Java:
1) For Loops
For loops are used in java to
execute statements repeatedly for a given number of times. For loops are used
when number of times to execute the statements is known to programmer.
2) While Loops
While loop is used when certain
statements need to be executed repeatedly until a condition is fulfilled. In
while loops, condition is checked first before execution of statements.
3) Do While Loops
Do While Loop is same as While loop
with only difference that condition is checked after execution of block of
statements. Hence in case of do while loop, statements are executed at least
once.
What
are the two environment variables that must be set in order to run any Java
programs?
Java programs can be executed in a machine
only once following two environment variables have been properly set:
1.
PATH variable
2.
CLASSPATH variable
Can
variables be used in Java without initialization?
In Java, if a variable is used in a code without prior initialization
by a valid value, program doesn’t compile and gives an error as no default
value is assigned to variables in Java.
What’s
the base class in Java from which all classes are derived?
java.lang.object
What
is Package in Java?
In Java, package is a collection of classes and interfaces
which are bundled together as they are related to each other.
When
the constructor of a class is invoked?
The constructor of a class is invoked every time an object is
created with new keyword.
Can
a class have multiple constructors?
Yes, a class
can have multiple constructors with different parameters.
Is
String a data type in java?
String is not
a primitive data type in java. When a string is created in java, it’s actually
an object of Java.Lang.String class that gets created. After creation of this
string object, all built-in methods of String class can be used on the string
object.
What’s
the benefit of using inheritance?
Key benefit of using inheritance is reusability and
extensibility of code
How
can we restrict inheritance for a class so that no class can be inherited from
it?
If we want a class not to be extended further by any
class, we can use the keyword Final with
the class name.
What
are the access scopes of access specifiers in Java?
MODIFIER
|
CLASS
|
PACKAGE
|
SUBCLASS
|
WORLD
|
public
|
Y
|
Y
|
Y
|
Y
|
no
modifier
|
Y
|
Y
|
N
|
N
|
protected
|
Y
|
Y
|
Y
|
N
|
private
|
Y
|
N
|
N
|
N
|
Can
a class in Java be inherited from more than one class?
In Java, a class can be derived from
only one class and not from multiple classes. Multiple inheritances are not
supported by Java.
What’s
the order of call of constructors in inheritance?
In case of inheritance, when a new
object of a derived class is created, first the constructor of the super class
is invoked and then the constructor of the derived class is invoked.
Is
JDK required on each machine to run a Java program?
JDK is development Kit of Java and is required for development only and to run a Java program on a machine, JDK isn’t required. Only JRE is required.
Comments
Post a Comment