Download JAVA - Sheriff

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
UNIT- I
1. List java buzzwords.
ANSWER:
I) Simple II) Secure III) Portable IV) Object-oriented V) Robust VI) Multithreaded
VII) Architecture-neutral VIII) Interpreted IX) High performance X) Distributed XI) Dynamic
2. What is java byte code?
ANSWER:
Byte code is a highly optimized set of instructions designed to be executed by the Java run-time
system, which is called the Java Virtual Machine (JVM).JVM Interprets byte code to executable code.
3. What are the various OOPs concepts?
ANSWER:
I) Abstraction II) Encapsulation III) Inheritance IV) Polymorphism V) Classes & Objects
4. What are the various java Lexical issues?
ANSWER:
I) White space II) Identifiers III) Literals IV) Comments V) Separators
5. List ten java keywords.
ANSWER:
i) abstract ii) new iii) while iv) switch v) package vi) boolean vii) this viii) for ix) continue x) if
6. List various java data types.
ANSWER:
Java defines eight primitive types of data: byte, short, int, long, char, float, double, Boolean.
7. What is Literal? Give different types of literals
ANSWER:
Types:
I) Integer II) Floating-point III) Boolean IV) Character V) String
8. What is a variable? How do you declare and initialize the variable? Give an example.
ANSWER:
The variable is the basic unit of storage in a java program. A variable is defined by the combination
of an identifier, a type, and an optional initializez.
General syntax for declaring a variable: type identifier [=value] [ , identifier [= value]….]
Initialization types: Static and Dynamic
Example: int a, b, c=10 ; // declaration and initialization
9. Define dynamic initialization with example.
ANSWER:
It can be defined as the initialization of the variables dynamically at run time.
E,g
int a=5, b=10;
int c= a+b*2; //variable c is initialized at run time dynamically
10. What is the difference between type conversion and casting?
ANSWER:
The difference between them is that in type conversion the conversion takes place automatically by
the compiler according to the program where as in case of casting the conversion is done by the
user. Ex: int=byte; // type conversion and int=int (double); //type casting
11. What are the two conditions for automatic conversions?
ANSWER:
The conditions are:
I) the source and destination types are compatible II) the destination type is larger than the source
type
12. Give example for automatic type promotion expressions.
ANSWER:
Example: 1
byte a=40;
byte b=50;
int d= a*b;
Here variable a and b are of byte type. When these variables used in the expression, they are
automatically promoted to integer.
13. What is an array? How to declare an array?
ANSWER:
An array is a group of like-typed variables that are referred to by a common name.
Declaration of array: (Syntax)
I) type var_name [ ];
II) type array_var = new type [size];
14. Find the average of given numbers in an array.
ANSWER:
Example:
class avg
{
public static void main (String args[]) {
double nums[ ]={ 10.1, 11.2, 12.3, 13.4, 14.5};
double average=0; int i ;
for(i =0; i<5; i++)
average=average+nums[i];
System.out.println(“Average is:”+average/5); }
}
15. What are the various types of arrays? How to declare the single dimensional array?
ANSWER:
Types of arrays are:
I) Single dimensional arrays
II) Multidimensional arrays
Declaring the single dimensional arrays:
I) type var_name [ ];
II) type array_var = new type [size];
UNIT - II
1. What is class? Give the general form of java class. And explain.
ANSWER:
A class is nothing but a template for creating different objects which defines its properties and
behaviors. A class can contain fields and methods to describe the behavior of an object.
General form of class:
class class_name
{
type instance_variable1;
type instance_variable2;
….. type instance_variableN;
type methodname1(parameter list) { // body of method }
….. type methodnameN(parameter list) { // body of method }
}
2. Explain reference and object with example.
ANSWER:
Reference is the instance of a specific class for which address space is not allocated in the memory.
Ex: BOX mybox;
Object is the instance of a specific class for which address is allocated in the memory.
Ex: BOX mybox = new BOX;
3. What is an object. How do you create object for a class in java.
ANSWER:
Object is the instance of a specific class for which address space is allocated in the memory.
Syntax: I) class_name object_name = new class_name ();
II) class_name object_name;
object_name = new class_name ();
Ex: BOX mybox = new BOX;
4. What is constructor?
ANSWER:
Constructor is a function with its name same as that of the class name. It is used to initialize the
class variables. It is called whenever the object of its class is created. It does it have a return type.
Constructor types: default, parameterized, copy
5. Differentiate default constructor with parameterized constructor.
ANSWER:
The main difference between them is that default constructor doesn’t have parameters and called
automatically when object is created, where as in case of parameterized constructor have
parameters list and we should also pass the values through the object created.
6. What is the use of this keyword?
ANSWER:
It is a keyword which refers to the current object. And it is used to invoke the current object.
7. What is mean by instance variable hiding?
ANSWER:
When both local variables and instance variables are same, local variables hides the instance
variables and this process is called instance variable hiding.
Box(double width, double height)
{
this.width=width;
this.height=height
}
Width and height associated ‘this’ keyword are instance variable. width and height declared as
argument of constructor are local variables. These local variables hide the instance variables.
This operation is called instance variable hiding.
8. Define Garbage collection.
ANSWER:
The process of deallocation the memory allocated by the variables automatically after the program
or the coding gets executed is known as the garbage collection.
9. Explain finalize () method.
ANSWER:
Sometimes an object will need to perform some action when it is destroyed. So, by using finalize ()
method we can define the actions that will occur when an object is just about to be reclaimed by the
garbage collector.
10. What is a command line argument?
ANSWER:
The arguments that are passed to the program only at run time (i.e during the execution of the
program) in the command prompt is called command line arguments.
11. Write a program to calculate “Area of a circle” using this operator.
class Circle
{
public static void main(String args[])
{
int radius = 3;
double area = Math.PI * (radius * radius);
System.out.println("The area of circle is: " + area);
}
}