- What is bytecode?
Bytecode 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 is an
interpreter for bytecode.
- What is a Literal?
What are the different types of literals?
A Literal represents a value of a certain
type where the type describes the behaviors of the value. The different types
of literals are:
- Number literals
- Character literals
- Boolean literals
- String literals
- What is a Number
literals?
There are
several integer literals as int, long, octal, hexadecimal etc. 10 is an example
of a decimal integer literal of type int.
If a decimal integer literal is larger that the int, it is declared to be of
type long. A number can be made long
by appending L or 1 to it. Negative
integers are preceded by the minus sign. These integers can also be expressed
as octal or hexadecimal. A leading 0 to the integer indicate that the number is
an octal integer. For example, 0987 is an octal integer. A leading 0x to the
integer indicate that the number is a hexadecimal integer, example 0xaf94 is a
hexadecimal number.
- What is a Character
literals?
Character
literals are expressed by a single character enclosed within single quotes.
Characters are stored as Unicode characters.
Escape
|
Meaning
|
\n
\t
\b
\r
\f
\\
|
Newline
Tab
Backspace
Carriage return
Form feed
Backslash
|
- What is a String
literals?
A string is a
combination of characters. string literals are a set of characters that are
enclosed within double quotes. As they are real objects, it is possible to
concatenate, modify and test them. For example, “This is a test string”
represents a string. Strings can contain character constants and Unicode
characters.
- What are token in
Java?
Token means, the smallest individual units of program.
In Java the following token are available.
White space
Identifiers
Literals
Comments
Separators
Keywords
- What is a variable?
How to declare variable in java?
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 initialize. All variables
must be declared before they can be used. The basic form of a variable
declaration is shown have
Type
identifier [= value],[,identifier [=value]]
The type in one of java’s atomic types. The
identifier is the name of the variable. For example
int a,b,c;
int d=3,c=5;
- What is a variable?
What are the different types of variables?
Variable are locations in the
memory that can hold values. Java has three kinds of variable namely,
- Instance variable
- Local variable
- Class variable
Local variables
are used inside blocks as counts or in methods as temporary variables. Once the
block or the method is executed, the variable ceases to exist. Instance
variable are used to define attributes or the state of a particular object.
These are used to store information needed by multiple methods in the objects.
- Write a note on
integer data types in Java.
Integers are
used for storing integer values. There are four kinds of integer types in Java.
Each of these can hold a different range of values. The values can either be
positive or negative
Type
|
Size
|
byte
short
int
long
|
8 bits
16 bits
32 bits
64 bits
|
- Write a note on float
data types in Java.
Float is used to
store numbers with decimal part. There are two floating point data types in
Java namely, the float and the double
Type
|
Size
|
float
double
|
32 bits
64 bits
|
- What are the
difference between static variable and instance variable?
The data or
variables, defined within a class are called instance variables.
Instance
variables declared as static are, essentially, global variables. When objects
of its class are declared, no copy of a static variable is made.
- Define Array? How to
declare an array?
An array is an
object that stores a list of items. Each slot in an array holds individual
elements. An array should be of a single type, comprising of integers, strings
and so on. To create an array, a variable to hold the array is declared, and a
new object is created and assigned to it.
- Write a note on
conditional operator in Java.
The conditional
operator is otherwise known as the ternary operator and is considered to be an
alternative to the if else construct. It returns a value and the syntax is:
<test> ? <pass> :
<fail>
Where,<test> is the condition to be
tested. If the condition returns true then the statement given in <pass>
will be executed. Otherwise, the statement given in <fail> will be
executed.
- List out the operator
in Java
§ Arithmetic Operators
§ Increment and Decrement Operators
§ Bitewise Operators
§ Relational Operators
§ Logical Operators
§ Assignment Operators
- What are jump
statements in Java?
In java have
three jump statements
§ return
§ continue
§ break
- Differentiable
between break and continue statements?
The break
keyword halts the execution of the current loop and forces control out of the
loop. The term break refers to the act of breaking out of a b lock of code.
Continue is similar to break, except that instead of halting the execution of
the loop, it starts the next iteration.
- What is means by
Garbage Collection?
In certain
languages like C++, dynamically allocated objects must be manually released by
use of a delete operator. In Java deallocation happens automatically. The
technique that accomplishes this is called garbage collection.
- Write any three OOP
principal?
§ Encapsulation
§ Inheritance
§ Polymorphism
- What is a class? Give
an example?
A class defines the shape and behavior of an object and is a
template for multiple objects with similar features.
(OR)
A class is a new data type. Once
defined, this new type can be used to create objects of that type. Thus, a
class is a template for an object, and an object is an instance of a class
- Distinguish between a
class and an object?
A class is a
template for an object, and an object is an instance of a class
- Define abstract
class?
Abstract classes
are classes from which instances are usually not created. It is basically used
to contain common characteristics of its derived classes. Abstract classes are
generally higher up the hierarchy and act as super classes. Methods can also be
declared as abstract. This implies that non-abstract classes must implement
these methods
- Define Inner Class ?
An inner class
is a nested class whose instance exists within an instance of its enclosing
class and has direct access to the instance members of its enclosing instance
- What are classes in
Java?
- What is meant by an
innerclass?
An inner class is a nested class whose instance exists
within an instance of its enclosing class and has direct access to the instance
members of its enclosing instance
class <EnclosingClass>
{
class <InnerClass>
{
}
}
- What are
constructors?
A constructor initializes an object immediately upon
creation. It has the same name as the class in which it resides and is
syntactically similar to a method. Once defined, the constructor is
automatically called immediately after the object is created, before the new operator
completes.
- Define method
overloading?
In Java it is possible to define two or more methods
within the same class that share the same name, as long as their parameter
declarations are different. When this is the case, the methods are said to be overload, and the process is referred to
as method overloading.
- Define method?
Methods are functions that operates on instances of
classes in which they are defined. Objects can communicate with each other
using methods and can call methods in other classes. Just as there are class
and instance variable, there are class and instance methods. Instance methods apply
and operate on an instance of the class while class methods operate on the
class.
- What are the uses of
the keyword ‘final’?
§ The class can be declared as final, if instances or subclasses are
not to be created.
§ The variables are declared as final, value of the variable must be
provided at the time of declaration.
§ The Method can be declared as final indicating that they cannot be
overridden by subclasses.
- What are static
methods?
Static methods
and variables can be used independently of any object. To do so, you need only
specify the name of their class following by the dot operator.
- What is inheritance?
In Object-Oriented programming, inheritance refers to the properties
of a class being available to many other classes. A derived class / sub class
is one that has been created from an existing class. Inheritance is the process
of deriving a class from a super class or a base class. No changes are made to
the base class. The derived class has a larger set of properties that its base
class. Inheritance has two advantages
a) Reusability of code
b) Data and methods of a
super class are physically available to its subclasses
- What is a package?
Packages contain a set of classes in order to ensure that class
names are unique. Packages are containers for classes that are used to
compartmentalize the class name space. Packages are stored in a hierarchical
manner and are explicitly imported into new class definition. A period is used
as separator to enable this.
- Write a note on
import statement?
Classes external
to a program be imported before they can be used. To import a class the import keyword should be used as given
below
import <classname>
The classes in Java are arranged in
hierarchical order. The Java library consists of a number of package. These
package contain a set of related classes. The whole path of the class must be
specified to import a class from the Java library, For instance, to import the
Data class from the util package use
the following code.
import java.util.Date;
It is also
possible to import all classes that belong to a package using the * symbol.
- Define interface?
An interface is a collection of abstract behavior that
individual classes can implement. It is defined like a class. An interface
consists of a set of method definition. Any class implementing it should
provide code for all its methods
- Define an exception
An exception is an abnormal condition, which occurs during the
execution of a program Exceptions are erroneous events like division by zero, opening
of a file that does not exist, etc. A java execution is an object, which
describes the error condition that has materialized in the program.
- Explain the usage of
try and catch clause
The try and
catch clause is used to handle an exception explicitly. The advantages of using
the try and catch clause are that, it fixes the error and prevents the program
from terminating abruptly.
- What is use of ‘throw
statement’ give an example? (or) state the purpose of the throw statement.
Whenever a program does not want to handle exception using the try
block, it can use the throws clause. The throws clause is responsible to handle
the different types of exceptions generated by the program. This clause usually
contains a list of the various types of exception that are likely to occur in
the program.
- List any three common
run time errors.
Exception
|
Meaning
|
ArithmeticException
ArrayIndexOutOfBoundsException
IllegalThreadStateException
|
Arithmetic error, such as divide-by-zero
Array index is out-of-bounds
Requested operation not compatible with
current thread state
|
- Define deadlock?
This occurs when two threads have a circular dependency on a pair of
synchronized objects. For example, suppose one thread enters the monitor on
object X and another thread enters the monitor on object Y. If the thread in X
tries to call any synchronized method on Y, it will block as expected. However,
if the thread in Y, in turn, tries to call any synchronized method on X, the
thread waits forever, because to access X, it would have to release its own
lock on Y so that the first thread could complete.
- Define
multithreading?
A thread is a
line of execution. It is the smallest unit of code that is dispatched by the
scheduler. Thus, a process can contain multiple threads to execute its
different sections. This is called multithread.
- List out the
advantages of multithreading.
The advantages
are as follows
- Can be created faster
- Requires less overheads
- Inter-process communication is faster
- Context switching is faster
- Maximum use of CPU time
- Define the term
thread.
A thread is a line of execution. It is the smallest unit of code
that is dispatched by the scheduler. Thus, a process can contain multiple
threads to execute its different sections. This is called multithread.
- List the several
states of ‘Thread’ in Java.
There are four
states associated with a thread namely – new, runnable, dead, blocked
- What is
synchronization? Briefly explain.
Two or more
threads accessing the same data simultaneously may lead to loss of data
integrity. For example, when two people access a savings account, it is
possible that one person may overdraw and the cheque may bounce. The importance
of updating of the pass book can be well understood in this case.
- What is the use of
‘Super’ Keyword? Give an example.
Usage of ‘super’
keyword’
1.
The first calls the superclass
constructor
2.
To access a member of the
superclass that has been hidden by a member of a subclass
- What are applets?
An applet is a
dynamic and interactive program that runs inside a web page displayed by a Java
capable browser. This can also be executed using the appletviewer.
- What are Byte Stream
in Java?
The byte stream
classes provide a rich environment for handling byte-oriented I/O.
List of Byte
Stream classes
§ ByteArrayInputStream
§ ByteArrayOutputStream
§ FilteredByteStreams
§ BufferedByteStreams
- What are Character
Stream in Java?
The Character
Stream classes provide a rich environment for handling character- oriented I/O.
List of
Character Stream classes
§ FileReader
§ FileWriter
§ CharArrayReader
§ CharArrayWriter
- Write a note on char
Array Reader
The
CharArrayReader allows the usage of a character array as an InputStream. The
usage of CharArrayReader class is similar to ByteArrayInputStream. The constructor
is given below:
public CharArrayReader(char c[ ])
- How will you find out
the length of a string in java? Give an example?
length( ) method
is used to number of characters is string. For example,
String
str=”Hello”;
System.out.println(“Length
of string is “+str.length( ));
- Name any three tags
used in Java Doc Comment
Java supports three types of comments. The first two are the // and
the /*. The third type is called a documentation comment. It begins with the
character sequence /**. It ends with*/.
In Java have
javadoc tags
Tag Meaning
@author Identifies the author of a class
@deprecated Specifies that a class or member
is deprecated
@param Documents
a method’s parameter
@return Documents a method’s
return value
- What is an internet
Address?
Every computer connected to a network has a unique IP address. An IP
address is a 32-bit number which has four numbers separated by periods. It is
possible to connect to the Internet either directly or by using Internet Service
Provider. By connecting directly to the Internet, the computer is assigned with
a permanent IP address. In case connection is made using ISP, it assigns a
temporary IP address for each session. A simple IP address is given below
80.0.0.78
- Define the role of
the type modifiers transient and volatile?
When an instance
variable is declared as transient, then its value need not persist when an
object is stored.
The volatile
modifier tells the compiler that the variable modified by volatile can be
changed unexpectedly by other parts of your program.
- What are datagram?
Datagram is a type of packet that represents an entire
communication. There is no necessity to have connection or disconnection stages
when communicating using datagram. This is less reliable than communication
using TCP/IP.
- Define Proxy Server.
A proxy server speaks the client side of a protocol to another
server. This is often required when clients have certain restrictions on which
servers they can connect to. Thus, a client would connect to a proxy server,
which did not have such restrictions, and the proxy server would in turn
communicate for the client. A proxy server has the additional ability to filter
certain requests or cache the results of those requests for future use.
- What is the use of
URL class in Java? Name any two methods in it.
URL stands for uniform
Resource Locator and it points to resource files on the Internet. The URL has
four components – the protocol, IP address or the hostname, port number
and actual file path
Methods
getPort( ) à get
the port number
getHost( ) à get the host name specified in URL
getFile( ) à get the file name
- List the AWT
controls?
§ Label
§ Button
§ Checkbox
§ TextComponent
§ Choice
§ List
§ Scrollbar
- Write a note on push
Button Control?
A push button is
a component that contains a label and that generates as event when it is
pressed. Push buttons are objects of type Button. Button defines these two
constructors.
Button( )
Button( String str)
The first
version creates an empty button. The second creates a button that contains str
as a label.
- Write a note on Borderlayout?
The BorderLayout
class implements a common layout style for top-level windows. It has four
narrow, fixed-width components at the edges and one large area in the center.
The four sides are referred to as north, south, east, and west. The middles
area is called the center. Here are the constructors defined by BorderLayout
BorderLayout( )
BorderLayout(int horz, int vert)
- Write a note on check
box control in Java?
A check box is a
control that is used to turn an option on or off. It consists of a small box
that can either contain a check mark or not. There is a label associated with
each check box that describes what option the box represents. You change the
state of a check box by clicking on it. Check boxes can be used individually or
as part of a group. Check boxes are objects of the Checkbox class.
Checkbox( )
Checkbox( String str)
Checkbox( String str, Boolean on)
Checkbox( String str, Boolean on,
CheckboxGroup cbGroup)
- Distinguish between
component and container
Component is an
abstract class that encapsulates all of the attributes of a visual component.
All user interface elements that are displayed on the screen and that interact
with the user are subclasses of Component.
The container
class is a subclass of Component. It has additional methods that allow other
Component objects to be nested within it. Other Container objects can be stored
inside of a container.
No comments:
Post a Comment