Q.1 What is the Java API?
Ans:
The Java API is a large collection of ready-made software components
that provide many useful capabilities, such as graphical user interface
(GUI) widgets.
Q.2 Describe the principles of OOPS?
Ans: There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.
Q.3 Explain the Inheritance principle?
Ans: Inheritance
is the process by which one object acquires the properties of another
object. Inheritance allows well-tested procedures to be reused and
enables changes to make once and have effect in all relevant places
Q.4 Explain the Polymorphism principle. Explain the different forms of Polymorphism?
Ans: Polymorphism
in simple terms means one name many forms. Polymorphism enables one
entity to be used as a general category for different types of actions.
The specific action is determined by the exact nature of the situation.
Polymorphism exists in three distinct forms in Java:
* Method overloading
* Method overriding through inheritance
* Method overriding through the Java interface
Q.5 What type of parameter passing does Java support?
Ans:
In Java the arguments (primitives and objects) are always passed by
value. With objects, the object reference itself is passed by value and
so both the original reference and parameter copy both refer to the same
object.
Q.6 Explain the Encapsulation principle?
Ans:
Encapsulation is a process of binding or wrapping the data and the
codes that operates on the data into a single entity. This keeps the
data safe from outside interface and misuse. Objects allow procedures to
be encapsulated with their data to reduce potential interference. One
way to think about encapsulation is as a protective wrapper that
prevents code and data from being arbitrarily accessed by other code
defined outside the wrapper.
Q.7 What do you understand by a variable?
Ans:
Variable is a named memory location that can be easily referred in the
program. The variable is used to hold the data and it can be changed
during the course of the execution of the program.
Q.8 What is data encapsulation?
Ans:
Encapsulation may be used by creating ‘get’ and ‘set’ methods in a
class (JAVABEAN) which are used to access the fields of the object.
Typically the fields are made private while the get and set methods are
public. Encapsulation can be used to validate the data that is to be
stored, to do calculations on data that is stored in a field or fields,
or for use in introspection (often the case when using javabeans in
Struts, for instance). Wrapping of data and function into a single unit
is called as data encapsulation. Encapsulation is nothing but wrapping
up the data and associated methods into a single unit in such a way that
data can be accessed with the help of associated methods. Encapsulation
provides data security. It is nothing but data hiding.
Q.9 Name primitive Java types?
Ans: The 8 primitive types are byte, char, short, int, long, float, double, and boolean.
Q.10 State
the significance of public, private, protected, default modifiers both
singly and in combination and state the effect of package relationships
on declared items qualified by these modifiers.
Ans: public : Public class is visible in other packages, field is visible everywhere (class must be public too)
private : Private variables or methods
may be used only by an instance of the same class that declares the
variable or method, A private feature may only be accessed by the class
that owns the feature.
protected : Is available to all classes
in the same package and also available to all subclasses of the class
that owns the protected feature.This access is provided even to
subclasses that reside in a different package from the class that owns
the protected feature.
default: What you get by default ie,
without any access modifier (ie, public private or protected).It means
that it is visible to all within a particular package.
Q.11 What if the main method is declared as private?
Ans: The program compiles properly but at runtime it will give “Main method not public.” message.
Q.12 What if I write static public void instead of public static void?
Ans: Program compiles and runs properly.
Q.13 What environment variables do I need to set on my machine in order to be able to run Java programs?
Ans: CLASSPATH and PATH are the two variables.
Q.14 How can one prove that the array is not null but empty using one line of code?
Ans:
Print args.length. It will print 0. That means it is empty. But if it
would have been null then it would have thrown a NullPointerException on
attempting to print args.length.
Question.15 If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?
Ans: It is empty. But not null.
Q.16 Can I have multiple main methods in the same class?
Answer: No the program fails to compile. The compiler says that the main method is already defined in the class.
Q.17 Do I need to import java.lang package any time?
Ans: No. It is by default loaded internally by the JVM.
Q.18 Can a top level class be private or protected?
Ans:
No. A top level class can not be private or protected. It can have
either “public” or no modifier. If it does not have a modifier it is
supposed to have a default access.If a top level class is declared as
private the compiler will complain that the “modifier private is not
allowed here”. This means that a top level class can not be private.
Same is the case with protected.
Q.19 What is the difference between a while statement and a do statement?
Ans:
A while statement checks at the beginning of a loop to see whether the
next loop iteration should occur. A do statement checks at the end of a
loop to see whether the next iteration of a loop should occur. The do
statement will always execute the body of a loop at least once.
0 comments:
Post a Comment