You are on page 1of 5

java important questions 1st and 2 module

1) Explain the role of buffer classes in java programming

ans)

Almost all Java programs need to interact with the outside world for taking input and supplying
output. There could be three sources from where a program can receive input and send output to.
These sources are console IO, file IO, and network IO. In console IO end user usually supplies
input by keyboard and receives generated output on display screen. In file IO, input is supplied
from and output is redirected to a file stored on disk. In network IO, input comes from a
networked resource and output is sent to the networked resource over the network.
Java programs perform I/O through streams. A stream could be thought as a pipe which is linked
to a physical device at one end and to a Java program at another end by the Java I/O system.
There are following I/O streams supported by Java:
Byte Streams handle I/O of raw binary data and perform input and output of 8-bit bytes. All
byte stream classes are descended from InputStream and OutputStream.
Character Streams handle I/O of character data. The Java platform stores character values
using Unicode conventions. Character stream I/O automatically translates this internal format to
and from the local character set. A program that uses character streams in place of byte streams
automatically adapts to the local character set and is ready for internationalization - all without
extra effort by the programmer.
Buffered Streams optimize input and output by reducing the number of calls to the native API.
In Unbuffered I/O each read or write request is handled directly by the underlying OS. This can
make a program much less efficient, since each such request often triggers disk access, network
activity, or some other operation that is relatively expensive.
To reduce this kind of overhead, the Java platform implements buffered I/O streams. Buffered
input streams read data from a memory area known as a buffer; the native input API is called
only when the buffer is empty. Similarly, buffered output streams write data to a buffer, and the
native output API is called only when the buffer is full.
A program can convert an unbuffered stream into a buffered stream, where the unbuffered
stream object is passed to the constructor for a buffered stream class.
This article specially emphasizes on Buffered Streams. We will shortly discuss buffered
streams (BufferedReader class) in detail and their advantages over byte and character streams.
Data Streams handle binary I/O of primitive data type values (boolean, char, byte, short, int,
long, float, and double) as well as String values. All data streams implement either the DataInput
interface or the DataOutput interface.
Object Streams handle binary I/O of objects. Just as data streams support I/O of primitive data
types, object streams support I/O of objects. Most, but not all, standard classes support
serialization of their objects. Those that do implement the marker interface Serializable.
Programs Using Java.io.BufferedReader
A program can convert an unbuffered stream into a buffered stream by passing the unbuffered
stream object to the constructor for a buffered stream class. For example, In Java, console input
is accomplished by reading from System.in. To obtain a character based stream that is attached to
the console, wrap System.in in a BufferedReader object. BufferedReader supports a buffered
input stream. Its most commonly used constructor is shown here:
BufferedReader(Reader inputReader)
Here, inputReader is the stream that is linked to the instance of BufferedReader that is being
created. Reader is an abstract class. One of its concrete subclasses is InputStreamReader, which
converts bytes to characters. To obtain an InputStreamReader object that is linked to System.in,
use the following constructor:
InputStreamReader(InputStream inputStream)
Because System.in refers to an object of type InputStream, it can be used for inputStream.
Putting it all together, the following line of code creates a BufferedReader that is connected to
the keyboard:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
2)Write a program in java to find the factorial value of any given number
3) Write a program in java to find the Fibonacci sequence of any given number
5) explain the Wrapper Classes with example program
6) What is meant by string arrays and string methods? Discuss them with a sample Java Program
7) Discuss clearly about JVM, JDK and Java API
8)What is an anonymous array? Give an example

ans)n array in Java without any name is anonymous array. It is an array just for creating and
using instantly.

We can create an array without name, such type of nameless arrays are called anonymous
array.
The main purpose of anonymous array is just for instant use (just for one time usage) .
Anonymous array is passed as an argument of method

/ Java program to illustrate the


// concept of anonymous array
class Test {
public static void main(String[] args)
{
// anonymous array
sum(new int[]{ 1, 2, 3 });
}
public static void sum(int[] a)
{
int total = 0;

// using for-each loop


for (int i : a)
total = total + i;

System.out.println("The sum is:" + total);


}
}
9) What are unique advantages of an object-oriented programming paradigm?.
10)What is a vector? How is it different from an array?
11)Distinguish between applet programming and application programming
12) Write a java program to reverse any given number

Important questions in 3rd and 4th module


1) What is Exception? Write about exception handling in java
2) What is method overloading? Explain it with an example
3) Define a class. Describe in detail about the nested classes
4) What is a constructor? List and explain the properties of it.
Explain different types of constructors with example
5)Mention the advantages of packages over interfaces. Write a
program to illustrate working of packages

6. Explain in detail about the thread synchronization


7) What are different ways that a thread can be implemented?
Describe them in detail
7)Explain the importance of following in java programming
a) Static
b) Final Classes
c) Final Methods
d) Finally

8) Distinguish between static binding and late binding


9) Explain multi level, multiple and single inheritance with suitable
example programs
10)What is a thread? In how many ways a thread can be implemented.
Explain with suitable example program
11). Explain the role of interfaces in java programming
12) Write a program using java to display priority of threads
13) What is an exception? Explain the various key words used in
exception handling mechanism
14) What is constructors? How can we overload the constructors?
Explain

15) How can we implement Multiple inheritance using java?


Explain with example program
16) Give brief description about the user defined exceptions
17) Define a thread. Draw and explain the life cycle of a thread
18) Discuss in detail about the deadlocks
19) What is a package? Explain its importance in java programming
20) Explain how to achieve multithreaded programming using java
21) Distinguish between abstract methods and non-abstract methods
with an example
22) Implementing Runnable interface and extending thread, which
method you prefer for multithreading and why

23) Discuss with a sample program how to extend interface


24) What is meant by Exception? Discuss various types of errors with
suitable examples
25) What is meant by thread priority? With a sample Java Program
explain how priority can be assigned to threads

26) What is the major difference between interfaces and classes?

java imporatnt questions in 5th module


1) Draw and explain the life cycle of an applet
2) Explain how parameters are passed to an applet
3) Discuss in detail about the different layout managers with suitable
example programs
4) Define event driven programming(event delegation model). Give brief description about it
5) Write short notes on inet address
6)Explain following awt components

a) text field

b)Menubar

7) Discuss various user interface components

8) Write the steps to convert an application program into applet


program
9) Explain how an applet differs from Swing GUI

10). What is a socket? How can we read and write information into
the socket? Explain
11) Give brief description about canvases and text areas

You might also like