You are on page 1of 9

Java 2 Marks

1. What is the significance between java and internet.

The first application program written in java was HotJava, a web browser to
run applets on internet. Internet users can use java to create applet programs
and run them locally using a java enabled web browser such as HotJava.

2. What are special operators supported by java

Java supports some special operators such as instanceof and member selection
(dot ) operator .

Instanceof: This operator allow us to determine whether the object belongs to


a particular class or not. For example: person instanceof student returns true
if the object person belongs to the class student otherwise false.

Dot(.) operator: It is used to access the instance variables and methods of class
objects. Example: person1.age it refers to the variable age

3. List out four mathematical functions supported by java

It is used to perform the numeric operations like square, square root, cube,
cube root, exponential operations.

Methods of lang.math class :

1. abs() : returns the absolute value of any type of argument passed.

2. asin() : method returns the arc sine value of the method argument
passed.

3. log() : returns the logarithmic value of the passed argument.

4. floor() : returns the floor value of an argument i.e. the closest integer
value which is either less or equal to the passed argument.
eg : 101.23 has floor value = 101

4. What is an object.

Objects are instances of the Class. Objects are important runtime entities in
object oriented programming. They may represent a location, a bank account,
and a table of data or any entry that the program must handle. Each object
holds data and code to operate the data. Ex: student object

5. What is the purpose of private and protected qualifier.

Private methods are accessible only with their own class (same class access
only). They can’t be inherited by subclasses and therefore can’t be accessed by
subclassess.

Protected: which lies between public and friendly access. That is, same
package access. Access if class is a subclass of, even if in another package

1. public - outside of package access.

2. [no keyword] - same package access only.

6. What is the advantage of a package.

Package in Java is a mechanism to encapsulate a group of classes, sub


packages and interfaces. Packages are used for:

 Preventing naming conflicts. For example there can be two classes with
name Employee in two packages, college.staff.cse.Employee and
college.staff.ee.Employee

 Providing controlled access: protected and default have package level


access control.

 Packages can be considered as data encapsulation (or data-hiding).

 Packages also provide a way for separating design from coding.

 packages can be provide reusability of code.

7. What is thread synchronization.


Multi-threaded programs may face a situation where multiple threads try to
access the same resources and finally produce erroneous results. So by the use
of synchronization method only one thread can access the resource at a given
point of time.

8. What is World Wide Web?

World Wide Web (www ) is an open-ended information retrieval system. This


system contains web pages that provides both information and controls.Web
pages contain HTML (Hyper Text Markup Language) tags that enable us to fine,
retrieve ,manipulate and display documents world wide. Java communicates
with a Web page through a special tag called <APPLET>.the Figure illustrates
the process. The user sends a request for an HTML document to the remote
computer’s Web server. The Web server is a program that accepts a request,
processes the request, and sends the request document

9. What is the use of type casting?

If the two types are compatible, then Java will perform the conversion
automatically (type conversion). For incompatible types we must use a cast.
The process of converting one data type to another is called casting.

Type variable1 = (type) variable2

int x = 10;

byte y = (byte)x;

Casting is an explicit conversion between incompatible types.

10. List the Relational Operators of Java.

When evaluation of two numbers is performed depending upon their relation,


assured decisions are made. The value of relational expression is either true or
false.
1) If 10 > 30 then result is false 2) If 40 > 17 then result is true 3) If 10 >= 300
then result is false 4) If 10 <= 10 then result is true

11. Define Loop. List out the types of Loop.

The process of repeatedly executing a statements is called as looping. The


statements may be executed multiple times. If a loop executing continuous
then it is called as Infinite loop. Looping is also called as iterations.

1. for loop (entry controlled loop. It means that it provide a more concious
loop control structure).

2. while loop (entry controlled loop statement. The condition is evaluated, if


the condition is true then the block of statements or statement block is
executed otherwise the block of statement is not executed.)

3. do-while loop (exit controlled loop. In do-while loop, first attempt of loop
execute then it check the condition.)

12. How can you define a Class in Java?

A class is a collection of objects of similar type. Classes are user defined data
types. A class is a set of objects with similar properties (attributes), common
behaviour (operations).

Class classname {

Class is a keyword . ex: class box // box is the name of the class

13. Write short on implementing interface.

The implements keyword is used by classes by inherit from interfaces.


Interfaces can never be extended by the classes. Interface is an outside view of
a class or object while hiding its structure.

Class classname implements interfacename

// body of classname
}

14. How will you add a class to a package?

It is simple to add a class to a package.

package p1 {

public Class A {

//body of A

15. What is error? List out the types of errors.

An error may produce an incorrect output or may terminate the execution of


programs or even may cause the program to crash.

Compile time errors: All syntax errors can be detected by java compiler. If error
occurs then It will not create the .class file. Ex: 1. Missing semicolons 2.
Missing double quotes 3. Missing brackets

Run time errors: Sometimes a program compile successfully but may not run
properly. Programs produce wrong results due to wrong logic. Ex: 1. Dividing
an integer by zero , 2. Conversion of invalid string to number

16. How applets differ from applications?

The main difference between Applet and Application is that the applet is a
small java program that can be executed by a Java-compatible web browser
while the application is a standalone program that can directly run on the
machine.

17. State the purpose of Graphic Class.

The Graphics class is the abstract base class for all graphics contexts that allow
an application to draw onto components that are realized on various devices,
as well as onto off-screen images.

Public void paint(Graphics g)

{
}

18. What is a Browser?

A web browser is a software program that allows a user to locate, access, and
display web pages. Common web browsers include Microsoft Internet
Explorer, Google Chrome, Mozilla Firefox

19. What is JVM?

all programming language compilers convert the source code to machine


code.Same job done by Java Compiler to run a Java program, but the
difference is that Java compiler convert the source code into Intermediate
code is called as bytecode. This machine is called the Java Virtual machine and
it exits only inside the computer memory.

20. What do you mean by operator precedence?

An arithmetic expression without any parentheses will be calculated from left


to right using the rules of precedence of operators.

There are two priority levels of arithmetic operators are as follows: (a) High
priority (* / %) (b) Low priority (+ -)

The evaluation process includes two left to right passes through the
expression. During the first pass, the high priority operators are applied as they
are encountered. During the second pass, the low priority operators are
applied as they are encountered.

21. What are the bitwise operators available in java?

Bit wise operator execute single bit of their operands.


22. What is a Constructor?

Constructors are used to initialize the object’s state. Like methods, a


constructor also contains collection of statements(i.e. instructions) that are
executed at time of Object creation

23. What do you mean by Method Overriding?

When a method in a class having the same method name with different
arguments is said to be method overloading. Method overriding : When a
method in a class having the same method name with same arguments is said
to be method overriding.

24. Define package.

A Package is a collection of related classes. It helps organize your classes into a


folder structure and make it easy to locate and use them. More importantly, it
helps improve re-usability.

25. What are the advantages of Thread?

A thread is similar to a program that has a single flow of control.


Multithreading enables the programmers to do multiple things at one time.
They can divide the long program into threads and execute them into parallel.
Thus improved throughput and concurrency, response time.

26. What is an Applet?

An Applet is a small Internet-based program that has the Graphical User


Interface (GUI), written in the Java programming language.

Applets are designed to run inside a web browser or in applet viewer to


facilitate the user to animate the graphics, play sound, and design the GUI
components.

27. Write the syntax of the method which is used to draw an arc.

An arc can be drawn using the drawArc () method.

void drawArc (int a1, int b1, int w, int h, int strt_angle, int sweep_angle)

where,
a1, b1 is the coordinate of the top left comer of the bounding rectangle

w is the width of the bounding rectangle

h is the height of the bounding rectangle

strt _angle is the starting angle of the arc (in degrees)

sweep_angle is the number of degrees (angular distance)

28. Write the syntax for simple if statement.

If (condition)

Statement block;

Statement-a;

In statement block, there may be single statement or multiple statements. If


the condition is true then statement block will be executed. If the condition is
false then statement block will omit and statement-a will be executed

29. What is an Array?

An array is a container object that holds a fixed number of values of a single


type. The length of an array is established when the array is created. After
creation, its length is fixed.

int[] intArray = new int[20];

30. What is a Thread?

A thread is a single flow of execution within a program. Many threads can run
concurrently within a program. Every thread in Java is created and controlled
by the java.lang.Thread class. Thread is a light weight process.

31. Define Constant and Variable.

Constant means fixed value which is not change at the time of execution of
program. In Java, there are two types of constant as follows: 1. Numeric
Constants  Integer constant  Real constant2. Character Constants 
Character constant  String constant.

Variables: Variables are labels that express a particular position in memory and
connect it with a data type. The first way to declare a variable: This specifies its
data type, and reserves memory for it.

int d=50; //Here d is variable

32. Define Exception.

An exception is an event, which occurs during the execution of the program,


that interrupt the normal flow of the program’s instruction. In other words,
Exceptions are generated when a recognized condition, usually an error
condition, arises during the execution of a method.

You might also like