1) What declarations are required for every Java application?

A class and the main( ) method declarations.

2) What are the two parts in executing a Java program and their purposes?

Java Compiler and Java Interpreter. The Java Compiler is used for compilation and the Java Interpreter is used for execution of the application.

3) What are identifiers and what is naming convention?

Identifiers are used for class names, method names and variable names. An identifier may be any descriptive sequence of upper case & lower case letters,numbers or underscore or dollar sign and must not begin with numbers.

4) What is the return type of program’s main( ) method?

void

5) What is the argument type of program’s main( ) method?

string array

6) What are different comments?

1) // -- single line comment 2) /* -- */ multiple line comment 3) /** -- */ documentation

7) What is the use of bin and lib in JDK?

Bin contains all tools such as javac, applet viewer, awt tool etc., whereas Lib contains all packages and variables.


Data Types,Variables and Arrays


8) What is meant by variable?

Ans: Variables are locations in memory that can hold values. Before assigning any value to a variable, it must be declared.

9) What are the kinds of variables in Java? What are their uses?

Java has three kinds of variables namely, the instance variable, the local variable and the class variable. Local variables are used inside blocks as counters or in methods as temporary variables and are used to store information needed by a single method. Instance variables are used to define attributes or the state of a particular object and are used to store information needed by multiple methods in the objects. Class variables are global to a class and to all the instances of the class and are useful for communicating between different objects of all the same class or keeping track of global states.

10) How are the variables declared?

Variables can be declared anywhere in the method definition and can be initialized during their declaration.They are commonly declared before usage at the beginning of the definition. Variables with the same data type can be declared together. Local variables must be given a value before usage.

11) What are variable types?

Variable types can be any data type that java supports, which includes the eight primitive data types, the name of a class or interface and an array.

12) How do you assign values to variables?

Values are assigned to variables using the assignment operator =.

13) What is a literal? How many types of literals are there?

A literal represents a value of a certain type where the type describes how that value behaves. There are different types of literals namely number literals, character literals, boolean literals, string literals,etc.

14) What is an array?

An array is an object that stores a list of items.

15) How do you declare an array?

Array variable indicates the type of object that the array holds. Ex: int arr[]; Java supports multidimensional arrays. An array of arrays can be created.

16) What are primitive data types?

Ans : byte, short, int, long float, double boolean char

17) What are default values of different primitive types?

int - 0 short - 0 byte - 0 long - 0 l float - 0.0 f double - 0.0 d boolean - false char - null

18) What is final varaible?

If a variable is declared as final variable, then you can not change its value. It becomes constant.

19) What is static variable?

Static variables are shared by all instances of a class.

Operators


20) What are operators and what are the various types of operators available in Java?

Operators are special symbols used in expressions. The following are the types of operators: Arithmetic operators, Assignment operators, Increment & Decrement operators, Logical operators, Biwise operators, Comparison/Relational operators and Conditional operators

21) What is the % operator?

% operator is the modulo operator or reminder operator. It returns the reminder of dividing the first operand by second operand.

22) Can a byte object be cast to a double value ?

No. An object cannot be cast to a primitive value.

23) What are order of precedence and associativity?

Order of precedence the order in which operators are evaluated in expressions. Associativity determines whether an expression is evaluated left-right or right-left.

24) What is the difference between prefix and postfix of -- and ++ operators?

The prefix form returns the increment or decrement operation and returns the value of the increment or decrement operation. The postfix form returns the current value of all of the expression and then performs the increment or decrement operation on that value.

Control Statements


25) What are the programming constructs?

a) Sequential b) Selection -- if and switch statements c) Iteration -- for loop, while loop and do-while loop

26) What are difference between break and continue?

The break keyword halts the execution of the current loop and forces control out of the loop. The continue is similar to break, except that instead of halting the execution of the loop, it starts the next iteration.

27) What is the difference between while statement and a do statement?

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.

Classes and Methods


28) Which is used to get the value of the instance variables?

Dot notation.

29)What is class?

A class is a template for multiple objects with similar features.

30)What is new keyword?

The new operator creates a single instance named class and returns a reference to that object.

31) What is mean by garbage collection?

When an object is no longer referred to by any variable, Java automatically reclaims memory used by that object. This is known as garbage collection.

32) What are methods and how are they defined?

Methods are functions that operate on instances of classes in which they are defined.Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method's signature is a combination of the first three parts mentioned above.

33) What is calling method?

Calling methods are similar to calling or referring to an instance variable. These methods are accessed using dot notation

34) Which method is used to determine the class of an object?

getClass( ) method can be used to find out what class the belongs to. This class is defined in the object class and is available to all objects.

35) How can class be imported to a program?

To import a class, the import keyword should be used as shown.; import classname;

36) How can class be imported from a package to a program?

import java . packagename . classname (or) import java.package name.*;

37) What is a constructor?

A constructor is a special kind of method that determines how an object is initialized when created.

38) Which method is used to garbage collect an object?

finalize ().

39) What is casting?

Casting is bused to convert the value of one type to another.

40) Which cast must be used to convert a larger value into a smaller one?

Explicit cast.

Which cast must be used to cast an object to another class?

Specific cast.

41) When must the main class and the file name coincide?

When class is declared public.

42) What are different modifiers?

public, private, protected, default, static, transient, volatile, final, abstract.

43) What are access modifiers?

public, private, protected, default

44) What is meant by "Passing by value" and " Passing by reference"?

objects – pass by referrence Methods - pass by value

45) What modifiers may be used with top-level class?

public, abstract, final.

46) Is a class a subclass of itself?

A class is a subclass itself.