0% found this document useful (0 votes)
6 views

paper 3 java

Uploaded by

pakijabangles786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

paper 3 java

Uploaded by

pakijabangles786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

what is the java program structure?

Package Declaration (Optional)

Import Statements (Optional)

Class Declaration (Mandatory)

Fields and Methods

The Main Method

Define this keyword?

· this refers to the current object.


· It helps separate variables from parameters with the same name.
· It can be used to call other constructors in the same class.
· It is used to access variables and methods of the current object.

Define interface?

An interface is a blueprint for a class. It is used to define a set of methods that a class
must implement, but it does not provide any implementation for those methods.

Key Points:

1. Defined using the interface keyword.


2. Contains only abstract methods (methods without a body) and constants (variables declared
as final and static).
3. A class implements an interface using the implements keyword.

Use of reader and writer in java

· Reader is for reading text from files or other sources.


· Common types:

 FileReader: Reads text from a file.


 BufferedReader: Reads text efficiently.

· Writer is for writing text to files or other destinations.


· Common types:

 FileWriter: Writes text to a file.


 BufferedWriter: Writes text efficiently.
which methodis use to specift container layout with syntax

In Java, the setLayout() method is used to specify the layout for a


container.

Syntax:

container.setLayout(LayoutManager layout);

Common layout manager:

Flowlayout

Gridlayout

Borderlayout

what is the default layout of frame and panel

Frame (JFrame)

 Default Layout: BorderLayout


 This layout divides the container into five regions:
o NORTH, SOUTH, EAST, WEST, and CENTER.

Panel (JPanel)

 Default Layout: FlowLayout


 This layout arranges components in a row, one after another, wrapping to the next row if
needed.

Explain modifiers and access control in java

Access Modifiers:

1. private: Accessible only within the same class.


2. default: Accessible within the same package.
3. protected: Accessible within the same package and by subclasses.
4. public: Accessible from anywhere.

List and explain any 2 built in excpetion

IOException: Signals that an I/O operation has failed or been


interrupted.
ArithmeticException: Raised when there’s an error in mathematical
calculations (e.g., dividing by zero).

StackOverflowError: Occurs when the call stack overflows,


typically due to excessive recursion.

explain the use of GetContentPane()


· Purpose: Retrieves the content pane of the frame, allowing components to be added and
arranged.
· Syntax: Container contentPane = frame.getContentPane();
· Usage: Used to set the layout and add components to the frame

Difference between interface and abstrace class

Explain the types of stream?Explain in detail?

Byte Streams
 Purpose: Used to handle raw binary data (8-bit byte data). They are suitable for reading and
writing all types of I/O, such as image files, audio files, etc.
 Classes: These are based on InputStream and OutputStream classes.

Common Byte Stream Classes:

 FileInputStream: Reads bytes from a file.


 FileOutputStream: Writes bytes to a file.
 BufferedInputStream: Reads data in chunks for efficient reading.
 BufferedOutputStream: Writes data in chunks for efficient writing.

2. Character Streams
 Purpose: Used to handle characters (16-bit Unicode data). They are suitable for reading and
writing text files (e.g., .txt, .csv, etc.) with proper encoding and decoding.
 Classes: These are based on Reader and Writer classes.

Common Character Stream Classes:

 FileReader: Reads characters from a file.


 FileWriter: Writes characters to a file.
 BufferedReader: Reads text efficiently by buffering characters.
 BufferedWriter: Writes text efficiently by buffering characters.

Explain the collection?Explain collection framework?

In Java, the Collection Framework provides a set of classes and interfaces to store and
manipulate groups of data. It is part of the `java.util` package and includes the
following main components:

1. Interfaces:
- List: An ordered collection (also known as a sequence). It allows duplicate
elements and provides positional access (e.g., `ArrayList`, `LinkedList`).
- Set: A collection that doesn't allow duplicate elements (e.g., `HashSet`,
`LinkedHashSet`).

2. Classes:
- ArrayList: A dynamic array that grows as needed. It implements the List interface
and allows random access.
- LinkedList: A doubly linked list that implements both List and Deque interfaces,
allowing more efficient insertions and deletions.

These components help with data manipulation, offering flexibility in terms of


performance, ordering, and access patterns.

Difference between awt and swing

Finalize Keywoard

· The finalize method is called by the garbage collector before deleting an object.
· It is used to clean up resources like files or database connections.
· The garbage collector calls finalize when the object is no longer needed.
Example:

class MyClass {

// Override finalize method to clean up resources

protected void finalize() {

System.out.println("Cleaning up resources before object is destroyed.");

public class Main {

public static void main(String[] args) {

MyClass obj = new MyClass(); // Create an object of MyClass

obj = null; // Make the object eligible for garbage collection

// Request garbage collection (not guaranteed)

System.gc();

You might also like