1. What IS Java Byte Code?

IPE MARCH 2015

OOPS & JAVA

1.  What IS Java byte code?

A) Java Bytecode: Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode opcode is one byte in length, although some require parameters, resulting in some multi-byte instructions.

2.  What is a class?

A)  Class: A class is a collection of objects of similar type. It is a template from which objects are created.

3.  What is an array?

A) Array: An array is a collection of similar type of data elements which are stored in consecutive memory locations under a common variable name.

4.  What is Inheritance?

A) Inheritance: Inheritance is the process by which objects of one class acquire the properties of objects of another class. Inheritance supports the concept of hierarchical classification. Inheritance provides the idea of reusability.

5.  Write any four Java API Packages?

A) 

Package / Purpose
java.lang / It includes classes for primitive types, strings, math functions, threads and exceptions.
java.util / Language utility classes such as vectors, hash tables, random numbers, date etc.,
java.applet / Classes for creating and implementing applets.
java.awt / Includes classes for windows, buttons, list, menus and so on.
java.io / Input or output support classes.

6.  What is logical error?

A) Logical Errors: The programmer might be using a wrong formula or the design of the program itself is wrong. Logical errors are not detected either by Java compiler or JVM. The programmer solely responsible for them.

7.  What is Multitasking?

A) Multitasking: It is an operating system concept in which multiple tasks are performed simultaneously.

8.  What are the methods of applet class?

A)

A)  init

B)  start

C)  stop

D)  destroy

E)  paint

9.  What is AWT?

A) AWT: AWT stands for Abstract Window Tool Kit. It is a portable GUI library among various operating systems for stand-alone applications.

10.  What are the classes involved in event handling?

A) Event handling involves four types of classes

1.  Event Sources

2.  Event classes

3.  Event Listeners

4.  Event Adapters

11.  Write about main features of Java.

A) Features of Java:

1. Object Oriented: In java everything is an Object. Java can be easily extended since it is based on the Object Model.

2. Platform Independent: Platform means an operating system such as windows, Unix, linux,etc., If a java program is compiled, it is compiled into platform independent byte code. This byte code can run on any platform. Hence we can say that the java is platform independent.

3. Simple: Java is designed to be easy to learn. If we understand the basic concept of OOP java would be easy to master.

4. Secure: With java’s secure feature it enables to develop virus – free, tamper – free systems. Authentication techniques are based on public – key encryption.

5. Architetural – Neutral: Java compiler generates an architecture – neutral object file format which makes the compiled code to be executable on many processors with the presence Java runtime system.

6. Portable: We may carry the java byte code to any platform.

7. Robust: Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.

8. Multi – threaded: With java’s multi-threaded feature it is possible to write programs that can do many tasks simultaneously. This design feature allows developers to construct smoothly running interactive applications.

9.. Interpreted: Java byte code is translated on the fly to native machine instructions and is not stored any where. The development process is more rapid and analytical since the linking is an incremental and light weigh process.

10. High Performance: With the use of Just – In – Time compilers Java enables high performance.

11. Distributed: Java is designed for the distributed environment of the internet.

12. Dynamic: Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run – time.

12.  Write about various operators in Java.

A) Arithmetic Operators: Arithmetic Operators are used to perform arithmetic operations on two operands.

Ex: a and b are integer variables and assigned a=5 and b=3 then

Operator / Purpose / Arithmetic
Expression / Result
+ / Addition / a+b / 8
- / Subtraction / a-b / 2
* / Multiplication / a*b / 15
/ / Division / a / b / 1
% / Remainder after
integer division / a%b / 2

Relational Operators: Relational Operators: There are six relational operators supported by Java language. These returns result in the form of ‘true’ or ‘false’.

Ex: a, b and c are integer variables and assigned 3, 5 and 10 respectively.

Operator / Purpose / Relational Expression / Result
= = / is Equal to / c = = 10 / False
! = / is Not equal to / a != b / True
is Greater than / a>b / False
is Less than / (a+b)<c / True
> = / is Greater than or equal to / a>=3 / True
< = / is Less than or equal to / b < = a / False

13.  Explain different data types in java.

A). Java has four main primitive data types built into the language. We can also create our own data types.

 Integer: byte, short, int, and long.

 Floating Point: float and double

 Character: char

 Boolean: variable with a value of true or false.

The following chart summarizes the default values for the java built in data types.

Type / Size in Bytes / Range
byte / 1 byte / -128 to 127
short / 2 bytes / -32,768 to 32,767
int / 4 bytes / -2,147,483,648 to 2,147,483, 647
long / 8 bytes / -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
float / 4 bytes / approximately ±3.40282347E+38F
(6-7 significant decimal digits)
Java implements IEEE 754 standard
double / 8 bytes / approximately ±1.79769313486231570E+308
(15 significant decimal digits)
char / 2 byte / 0 to 65,536 (unsigned)
boolean / not precisely defined* / true or false
Data Type / Default Value (for fields) / Range
Byte / 0 / -127 to +128

14.  Discuss briefly about decision – making statements in Java.

A) if statement: if statement is used to control the flow of execution of statements.

Syntax: if (test expression)

{

Statement _block;

}

statement x;

The statement _block may be a single statement or multiple statements. If the test expression is ‘true’, the statement_block will be executed, otherwise the statement block will be skipped and the control flows to the immediately following the statement block.

Ex: if (a>b) big = a;

if …… else statement: The if…..else statement is an extension of the simple if statement. If the test expression is true then statements under if will be executed else statements under else will be executed.

Syntax: if (test expression)

{

true block statements;

}

else

{

false block statements;

}

Ex: if (a>b) big = a; else big = b;

Switch Statement: The switch statement tests the value of a given variable against a list of value and when a match is found, corresponding block of statements associated with the case will be executed. If none is matched ‘default’ block will be executed. The ‘break’ statement at the end of each block signals the end of a particular case causes an exit from the switch statement, transferring the control to the statement immediately following the switch.

Syntax: switch(expression)

{

case value: block1;

break;

case value: block2;

break;

case value: block3;

break;

------

------

default: default block;

break;

}

15.  Write a program to find factorial of a given number.

A) //to find the factorial by using while loop

import java.util.Scanner;

class Factoria{

public static void main(String args[]){

int i,f=1,n;

System.out.println("Enter an Integer:");

Scanner in = new Scanner(System.in);

n = in.nextInt();

i = 1;

while(i<=n){

f*=i;

++i;

}

System.out.println("Factorial of"+n+"is" +f);

}}

Output:

Enter an Integer:

5

Factorial of 5 is 120

16.  Explain the polymorphism with an example.

A)  Polymorphism: Polymorphism means the ability to take more than one form is called Polymorphism.

We can store all the objects of extended classes in to variable of parent class. The only possible way to access an object is through a reference variable. A reference variable can be only one type. Once declared the type of reference variable cannot be changed.

The reference variable can be reassigned to other objects provided that it is not declared final. The type of the reference variable would determine the methods that it can invoke on the object.

A reference variable can refer to any object of its declared type or any subtype of its declared type. A reference variable can be declared as a class or interface type.

Ex: class Box{

int w,h;

void info( ){

System.out.println("This is a simple box");

System.out.println("width = "+w+"height="+h);

}}

class woodenBox extends Box{

int life;

void info( ){

System.out.println("This is a wooden box");

}}

class SteelBox extends Box{

int wg;

void info( ){

System.out.println("This is a steel box");

}}

class LargewoodenBox extends woodenBox{

void info( ){

System.out.println("This is a Huge wooden Box");

}}

class BoxDemo{

public static void main(String ary[ ]){

Box x;

Box b1= new Box( );

woodenBox wb=new woodenBox( );

SteelBox s1=new SteelBox( );

LargewoodenBox p1=new LargewoodenBox( );

b1.info( );

wb.info( );

s1.info( );

p1.info( );

}}

Output:

This is a simplebox

Width=0 hieght=0

This is a wooden box

This is a steel box

This is a Huge wooden Box

17.  Discuss briefly about Packages and Interfaces.

A) Interfaces Vs Packages

A package is just a mechanism for grouping objects, it is very similar to grouping items within a folder or directory on a file system. A class is found with in a package, but this does not have an impact on the class behavior.

An Interface, however, is a.java file that is used (implemented) by another class to tell the outside world that it conforms to a certain specification.

Interfaces have more in common with abstract classes than they do with packages. An Interface, by definition, cannot have any implemented methods.

An abstract class can define some methods and leave some methods to implemented by a subclass.

A class can implement many interfaces, but can only extend one (abstract) class.

18.  Write about methods of Applet Class.

A) Methods Of Applet Class (Life Cycle of an applet): Four methods give us the framework on which we build an applet.

1.  init : This method is intended for whatever initialization is needed for our applet. It is called after the param tags inside the applet tag have been processed.

2.  Start: This method is automatically called after the browser calls the init method. It is also called whenever the user returns to the page containing the applet after having gone off to other pages.

3.  Stop: This method is automatically called when the user moves off the page on which the applet sits. It can, therefore, be called repeatedly in the same applet.

4.  Destroy: This method is only called when the browser shuts down normally

5.  Paint: Invoked immediately after the start() method and also any time the applet needs to repaint itself in the browser. The paint() method is actually inherited from the java awt.

RDBMS

1.  What is DBMS?

A)  A database management system (DBMS) can be defined as a collection of software packages for processing the database.

2.  What is a Domain?

A) Domain: Domain is a pool of values of a specific attribute. Separate domains for separate attributes.

3.  What is Tuple?

A. Tuple is a row(record) of a table .

4.  What are the Formal Query Languages?

A. Formal Query Languages are formal in the sense that they are lack of ‘syntactic behavior ‘of commercial query languages.

Some of the formal Query Languages are listed below:

- The Relational Algebra

- Tuple Relational Calculus

- Domain Relational Calculus

5.  What is Degree of Table in Relational Model?

A)  Number of attributes is called degree.

6.  Write the Internal Datatypes in SQL.

A) varchar , varchar2 , numb, long, date ,etc

7.  What is Sub – query?

A. Nesting of queries, one within another, is termed as subquery.

8.  Wha is a Database Trigger?

A) Database Trigger: A database trigger is a stored procedure that will be executed when an event is occurred i.e., insert, update, delete statement is issued against the associated table.

9.  Define system and Sub-system.

A. System: System is an orderly grouping of interdependent components linked together to approach a Specific object or goal. Ex: Railway reservation system , Net banking system.

Sub System: One of the number of component parts of a system. All the subsystems must function together in an integrated manner for the system to operate as designed.

10.  Define Data Dictionary?

A.  Data Dictionary: Data Dictionary is a repository that contains descriptions of all data objects produced by the software.

11.  Explain different Data Models.

A. Different data models are

1.  Object based data models

2.  Record – based data models

3.  Physical data models

1. Object base data models: Object-based logical models are used in describing data at logical and view levels. They are characterized by the fact they provide flexible structuring capabilities and allow data constraints to be specified explicitly. There are many different data models, some of them are

i. The Entity-relationship model

ii. The Object-oriented model

iii. The semantic data model

iv. The Functional data model

2. Record based data models: In Record based data models; the database is structured in fixed formats records of several types. Each record defines fixed number of fields (attributes) and each field is fixed length. These models are used to specify the overall logical structure of the database and are used in describing the database at conceptual level.

The three widely accepted record – based data models are:

a)  Relational model

b)  Network model

c)  Hierarchical model