Java Viva Voce -2
1. What is a
variable?
Name which refers memory locations and it can hold a value
which can be changed at runtime is called Variable.
2. What are
primitive data types?
A primitive type is predefined by the language and is named
by a reserved keyword.
3. How many
primitive data types are there in Java?
There are 8 primitive data types and they are byte, int,
short, long, float, double, char and Boolean.
4. Does Java
has any unsigned types?
No, Java does not have any unsigned types.
5. What do
the floating-point numbers without an F suffix indicate?
Floating-point
numbers without an F suffix indicate to be of type double. We can optionally
supply the D suffix also (ex. 3.402D).
6. What are
identifiers?
Identifiers are the names of variables, methods, classes, packages and
interfaces. Unlike literals they are not the things themselves, just ways of
referring to them.
7. Why do we
use Unicode in Java?
Most
of the countries now use Unicode so we use them in Java too.
8. What is
Escape sequence for special character in Java? List some of them.
A character preceded by
a backslash (\) is an escape sequence and has special
meaning to the
compiler. \b, \t, \n, \r etc. are some escape sequences in Java.
9. Can you
use a Java reserved word for a variable name?
No,
we cannot use a Java reserved word for a variable name.
10. Why do
we use the keyword final in Java?
In
Java, you use the keyword final to denote a constant. The keyword final
indicates that you can assign to the variable once, and then its value is set
once and for all. It is compulsory to name constants in all uppercase.
11. How can
you avoid the Math prefix for the mathematical methods and constants?
By importing the package:
import static java.lang.Math.*; we
can avoid the Math prefix for the mathematical methods and constants.
12. Does
Java has built in String type?
Java does not have a built-in string type.
Instead, the standard Java library contains a predefined class called String.
13. how is
Instance variable declared?
Instance variables are created when an object is
created with the use of the keyword 'new' and destroyed when the object is
destroyed.
An
instance variable is a variable which has one copy for an object.
A class variable is a variable which has one copy per class. The class variables will not have a copy in the object.
A class variable is a variable which has one copy per class. The class variables will not have a copy in the object.
For numbers, the default value is 0, for Booleans
it is false and for object references it is null.
Java naming
convention is a rule to follow as you decide what to name your
identifiers such as class, package, variable, constant, method etc.
Class name should start with an Uppercase and
method name should start with Lowercase.
A literal is a value assigned to a
variable or a constant is called a literal. Java language
specifies five major types of literals: Integer literals, Floating
literals, Character literals,
String literals, Boolean literals.
19.
What is Type casting?
When the data is
converted from one data type to another data type, then it is called type
casting. Type casting is nothing but changing the type of the data.
20. What are the types of casting?
There are
two types of casting.
1) Primitive Casting: When
the data is casted from one primitive type (like int, float, double etc…) to another primitive
type, then it is called Primitive Casting.
2) Derived Casting: When the
data is casted from one derived type to another derived type, then it is called
derived casting.
Operator precedence determines the grouping of
terms in an expression. This affects how an expression is evaluated. For example, the multiplication operator has
higher precedence than the addition operator.
Control
flow statements, however, break up the flow of execution by employing
decision making, looping, and branching, enabling your program to conditionally execute particular
blocks of code.
Break, continue and return are Branching statement.
A loop
statement allows us to execute a statement or group of statements multiple
times which reduces the size of program.
26. What are access modifiers in
java?
These are
the modifiers which are used to restrict the visibility of a class or a
field or a method or a constructor.
27. How many access
modifiers are there in Java?
Java
supports 4 access modifiers.
a) Private: private
fields or methods or constructors are visible within the class in which
they are defined.
b) Protected:
Protected members of a class are visible within the package but they can
be inherited to sub classes outside the package.
c) Public: public
members are visible everywhere.
d) Default or No-access modifiers: Members of
a class which are defined with no access modifiers are visible within the
package in which they are defined.
28. Can we declare a class as protected?
We can’t
declare an outer class as protected but we can declare an inner class (class as
a member of another class) as protected.
29. What are non-access modifiers
in java?
These are
the modifiers which are used to achieve other functionalities like static, final, abstract.
A class
is a program construct which encapsulates data and operations on data. In
object oriented programming, the class can be viewed as a blue print of an
object. An object is a program construct that falls under a ‘classification’
(of a class) which has state and behavior.
There are three steps to create an object from a
class −
Declaration
− A variable is declared with an object type.
Instantiation
− the 'new' keyword is used to create the object.
Initialization
− the 'new' keyword is followed by a call to a constructor. This call
initializes the new object.
A method (function) is a collection of statements
that are grouped together to perform an operation.
Constructor is a special type of method
that is used to initialize the object. Java constructor is invoked at the time of
object creation.
There are two types of constructors:
Default
constructor (no-argument constructor), Parameterized constructor.
35.
What is Constructor Overloading?
Constructor
overloading is a technique in Java in which a class can have any number of
constructors that differ in parameter lists.
36. What is Garbage Collection?
Garbage Collection is process of reclaiming the
runtime unused memory automatically. In other words, it is a way to destroy the
unused objects.
37.
What is the advantage of Garbage Collection?
It
makes java memory efficient because
garbage collector removes the unreferenced objects from heap memory.
38. What is finalize method?
The
finalize method is invoked each time before the object is garbage collected.
This method can be used to perform cleanup processing.
39. What is static keyword?
The static keyword in java is used for
memory management mainly. We can apply java static keyword with variables,
methods, blocks and nested class.
40. What is a static
variable?
If you declare any variable as static, it is known
static variable. The static variable can be used to refer the common property
of all objects.
If you apply static keyword with any method, it is
known as static method.
42.What is
java command line argument?
Java command line argument is an
argument i.e. passed at a time of running the java program.
43. Where
the arguments are received and used?
The
arguments passed from the console can be received in the java program and it
can be used as an input.
44.How the
arguments are useful?
They
provide a convenient way to check the behaviour of the program for different
values.
45.What is
an ARRAY?
An array stores the fixed size
sequential collection of elements of the same type.
46.How is an
array used?
An
array is used to store a collection of data, but it is often more useful to
think of an array as a collection of variables of same data type.
47.What is
for each loop also known as?
Enhanced
for loop.
48.What is the
use of for each loop?
It
enables us to traverse the complete array sequentially without using an index
variable.
49.What is
an ARRAY CLASS?
This
class contains various static methods for sorting and searching arrays, comparing
and filling array elements.
50.What is This
keyword in java?
THIS
keyword is used as a reference to the object of the current class, with in an
instance method or a constructor.
51.What is
use of this keyword?
Differentiate
the instance variables from local variables if they have some names, within a
constructor or a method.
52. Can we call method with
this keyword from constructor?
Yes, we can call non static methods from constructor using this keyword.
Yes, we can call non static methods from constructor using this keyword.
53. Is it possible to
assign reference to this?
No we cannot assign any value to "this" because it’s always
points to current object and it is a
final reference in java. If we try to change or assign value to this compile time
error will come.
54. Can we use this in static methods?
No we cannot use this in static methods. if we try to use compile
time error will come: Cannot use this in a static context.
Labels: VIVA-VOCE
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home