0% found this document useful (0 votes)
3 views22 pages

Java 2 Marks

The document provides a comprehensive overview of Java programming concepts, including definitions of classes and objects, the nature of Java as a compiled and interpreted language, and the creation of variables and objects. It covers key features of Java such as method overriding, abstract classes, packages, streams, and exception handling, along with differences between various Java constructs like strings and string buffers, classes and interfaces, and local and remote applets. Additionally, it discusses advanced topics like multithreading, synchronization, the Java Virtual Machine (JVM), and the Java API.

Uploaded by

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

Java 2 Marks

The document provides a comprehensive overview of Java programming concepts, including definitions of classes and objects, the nature of Java as a compiled and interpreted language, and the creation of variables and objects. It covers key features of Java such as method overriding, abstract classes, packages, streams, and exception handling, along with differences between various Java constructs like strings and string buffers, classes and interfaces, and local and remote applets. Additionally, it discusses advanced topics like multithreading, synchronization, the Java Virtual Machine (JVM), and the Java API.

Uploaded by

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

JAVA MQP

[2 Marks]

1)Define class and object.

●​ Class: A blueprint or template for creating objects. It defines the attributes (properties)
and behaviors (methods) that objects of that class will have.
●​ Object: An instance of a class. It has actual values for the properties defined in the
class and can perform actions using the class methods

2)Why java is called compiled and interpreted language?

Java is both compiled and interpreted because:

1.​ Compiled: Java source code is first converted into bytecode by the Java compiler
(javac).
2.​ Interpreted: The JVM (Java Virtual Machine) then reads and executes the bytecode on
any system.

3)What is a variable? How to declare and initialize a variable?

A variable is a storage location in memory that holds data. It has a name, a data type, and a
value that can change during execution.

Declaration & Initialization:

int num = 10; // Declares and initializes 'num' with 10

4)How is an object created in java? Give an example.

In Java, an object is created using the new keyword, which allocates memory for the object and
calls the class constructor.

Steps to Create an Object:

1.​ Define a class.


2.​ Create an object using new.

Example:
class Car {
void display() {
System.out.println("This is a car.");
}
}

public class Main {


public static void main(String[] args) {
Car myCar = new Car(); // Object creation
myCar.display(); // Calling method
}
}

5)What is method overriding?

●​ Method overriding is a feature in Java where a subclass redefines a method that is


already defined in its parent class.
●​ This allows the subclass to provide a specific implementation for that method.

6)What is an abstract method and abstract class?

●​ An abstract class in Java is a class that cannot be instantiated and is meant to be a


blueprint for other classes.
●​ An abstract method in Java is a method that is declared without implementation (no
method body) in an abstract class.

7)What is a package in java?

●​ A package in Java is a collection of related classes and interfaces grouped together.


●​ It helps in organizing code, avoiding name conflicts, and improving maintainability.

8)What is a stream? How streams are classified in java?

●​ In Java, a stream is a sequence of data that flows from a source to a destination.


●​ It is used for input (reading data) and output (writing data), mainly for file handling and
I/O operations.

Classification of Streams in Java:

1.​ Byte Streams (for binary data):​

○​ Used to handle raw binary data like images, audio, and files.
○​ Examples: FileInputStream, FileOutputStream.
2.​ Character Streams (for text data):​

○​ Used for handling textual data, ensuring proper character encoding.


○​ Examples: FileReader, FileWriter.
3.​ Buffered Streams:​
○​ Improves efficiency by reading/writing data in chunks.
○​ Examples: BufferedReader, BufferedWriter.
4.​ Data Streams:​

○​ Used to read/write primitive data types.


○​ Examples: DataInputStream, DataOutputStream.

9)What is abstract window toolkit(AWT) in java?

●​ The Abstract Window Toolkit (AWT) in Java is a set of APIs used for creating
Graphical User Interfaces (GUIs) and handling user interactions.
●​ It is part of the Java Foundation Classes (JFC) and provides components like
windows, buttons, text fields, and menus.

10)What is an applet?

●​ An applet is a small Java program that runs inside a web browser or an applet viewer.
●​ It is used to create interactive web applications.

11)What is object oriented programming?

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of


objects, which contain data (attributes) and methods (functions).

●​ Encapsulation: Data is bundled within objects.


●​ Inheritance: One class can inherit properties from another.
●​ Polymorphism: Objects can take multiple forms.
●​ Abstraction: Hides implementation details and shows only essential features.

12)What is byte code?

●​ Bytecode is an intermediate representation of Java code that is generated after


compilation.
●​ Java source code (.java file) is compiled into bytecode (.class file) using the Java
Compiler (javac).

13)Mention the different types of control structures in java.

1.​ Sequential Control:​

2.​ Selection Control (Decision-Making Statements):​

3.​ Iteration Control (Looping Statements):​

4.​ Jump Control (Branching Statements):​


14)What is the general syntax for defining a class?
class ClassName {
// Instance variables (attributes)
DataType variableName;

// Constructor
ClassName() {
// Initialization code
}

// Methods (functions)
void methodName() {
// Method logic
}
}

15)What is the difference between string and string buffer?


Feature String StringBuffer

Mutability Immutable (cannot be changed after Mutable (can be modified)


creation)

Performance Slower for multiple modifications Faster for string manipulations

Thread Safety Not thread-safe Thread-safe (synchronized methods)

Memory Creates new objects for Uses the same object, reducing
Usage modifications memory usage

Usage Best for fixed text values Best for dynamic string modifications

16)What is method overloading?

●​ Method overloading in Java allows multiple methods in the same class to have the
same name but different parameter lists (number, type, or order of parameters).
●​ It helps improve code readability and reusability.

17)What is an interface in java?

●​ An interface in Java is a blueprint for a class that defines a set of methods without
implementation.
●​ It is used to achieve abstraction and multiple inheritance.

18)What is the difference between character and byte streams?


Feature Character Stream Byte Stream

Data Type Handles text data Handles binary data (bytes)


(characters)

Classes Used Reader, Writer InputStream, OutputStream

Encoding Uses Unicode (16-bit) Uses 8-bit binary data

Usage Best for text files Best for images, audio, video

Example FileReader, FileInputStream,


Classes BufferedReader BufferedInputStream

19)What is a panel and frame in AWT?

Panel:

●​ A Panel in Java AWT is a container that groups multiple components together.


●​ It cannot exist independently; it must be added to a Frame or another container.

Frame:

●​ A Frame is a top-level window that can exist independently.


●​ It is used to create main application windows.

20)What is multithreading?

●​ Multithreading in Java allows multiple threads to run concurrently, improving


performance and resource utilization.
●​ Implemented using Thread class or Runnable interface.

21)Why java is called as platform independent?

●​ Java is called platform-independent because it can run on any operating system


without modification.
●​ This is achieved through Java Bytecode and the Java Virtual Machine (JVM).

22)Define encapsulation and inheritance.

●​ Encapsulation: Encapsulation is the hiding of data within a class and allowing access
only through getter and setter methods.
●​ Inheritance: Inheritance allows a child class to inherit properties and methods from a
parent class.

23)What is a constructor in java?

●​ A constructor is a special method in Java used to initialize objects when they are
created.
●​ Has the same name as the class.

24)What is an array? How is it created in java?

An array in Java is a collection of elements of the same data type, stored in contiguous
memory locations.

Creating an Array in Java:

Declaration:

int[] numbers; // Declares an array of integers

Initialization:

numbers = new int[5]; // Allocates memory for 5 integers

Declaration & Initialization Together:

int[] numbers = {10, 20, 30, 40, 50}; // Direct initialization

25)What are wrapper classes? Give an example.

Wrapper classes in Java provide a way to use primitive data types (int, char, boolean,
etc.) as objects.

Example:

int num = 10; // Primitive type


Integer obj = Integer.valueOf(num); // Wrapper class object

System.out.println(obj); // Outputs: 10

26)What are final methods and final classes?


Final Methods:

●​ A method declared as final cannot be overridden by subclasses.


●​ Ensures consistent behavior across all inherited classes.

Final Classes:

●​ A class declared as final cannot be extended.


●​ Used to create immutable classes like String.

27)How does an interface differ from an abstract class?

Feature Abstract Class Interface

Implementation Can have both abstract and Only abstract methods (until Java 8,
concrete methods which introduced default methods)

Inheritance Supports single inheritance Supports multiple inheritance

Access Can have private, protected, Methods are public by default


Modifiers and public methods

Variables Can have instance variables Only public, static, and final variables

Constructors Can have constructors Cannot have constructors

28)What are layout managers? What is the use of layout managers in java?

●​ Layout Managers in Java are used to arrange components within a container,


ensuring proper alignment and resizing.
●​ They help in designing responsive and flexible user interfaces.

29) What Are Local and Remote Applets?

●​ A local applet is a Java applet that is stored on the user's computer and does not
require an internet connection to run.
●​ A remote applet is a Java applet that is stored on a remote server and downloaded via
the internet when accessed by a web browser.

30) What Is an Exception?

An exception in Java is an unexpected event that occurs during program execution, disrupting
the normal flow.

Types of Exceptions:

1.​ Checked Exceptions .


2.​ Unchecked Exceptions.
3.​ Errors .

31)Mention any 4 features of java.

●​ Platform Independence
●​ Object-Oriented
●​ Simple & Easy to Learn
●​ Secure.
●​ Robust
●​ Interpreted & Compiled

32)What is polymorphism? List the types of polymorphism.


Polymorphism allows objects to take multiple forms, meaning the same method or object can
behave differently depending on the context.

Types of polymorphism:

●​ Compile-time polymorphism (Static polymorphism)


●​ Runtime polymorphism (Dynamic polymorphism)

33)What are instance variables? How are they different from class variables?

●​ Instance Variables: These are variables that belong to an individual object of a class.
Each object has its own copy of instance variables, meaning changes to one object’s
instance variable do not affect others. They are declared inside a class but outside any
method and do not use the static keyword.
●​ Class Variables (Static Variables): These are shared across all instances of a class.
They are declared using the static keyword, meaning they belong to the class itself
rather than any specific object. Any change to a class variable affects all instances of the
class.

34)What is the purpose of this and super keyword in java?


●​ this keyword refers to the current instance of a class. It is used to differentiate
instance variables from parameters, invoke constructors, and pass the current object as
an argument.
●​ super keyword refers to the parent class and is used to access superclass methods,
constructors, and instance variables.

35)What is compile time and runtime polymorphism?


Compile-time polymorphism (Static binding) – This occurs when the method to be executed
is determined at compile time. It is achieved through method overloading, where multiple
methods share the same name but have different parameters.
Runtime polymorphism (Dynamic binding) – This occurs when the method to be executed is
determined at runtime. It is achieved through method overriding, where a subclass provides a
specific implementation of a method already defined in its parent class.

36)What is the difference between a class and an interface?


Feature Class Interface

Definition Blueprint for creating Defines a contract that classes must follow
objects

Methods Can have both concrete Only abstract methods (before Java 8), can
and abstract methods have default/static methods (Java 8+)

Variables Instance or static variables Only static and final variables

Inheritance Supports single inheritance Supports multiple inheritance


(extends) (implements)

Access Can have public, Methods are public by default


Modifiers private, protected
methods

Constructors Can have constructors Cannot have constructors

Implementation Instantiated using new Cannot be instantiated directly, must be


keyword implemented by a class

Use Case Defines behavior and Provides a standard structure for classes to
properties of objects follow

37)What is serialization and deserialization?

Serialization
Serialization is the process of converting an object into a byte stream so that it can be saved to
a file, sent over a network, or stored in a database. This allows objects to be persisted and
transferred across different environments.

Deserialization

Deserialization is the reverse process—converting a byte stream back into an object. This
allows previously stored objects to be reconstructed.

38)What is an event and event handling in java?

Event:

In Java, an event is an action or occurrence that happens within a program, typically triggered
by user interactions or system-generated changes. Examples include clicking a button, pressing
a key, moving the mouse, or resizing a window.

Event Handling

Event handling is the mechanism that allows Java programs to respond to events. Java follows
the Delegation Event Model, where:

●​ Event Source: The component that generates an event (e.g., a button).


●​ Event Listener: The object that listens for and responds to the event

39)What is a label and button in AWT?

Label in AWT

A Label is a passive control used to display text or images in a GUI. It does not support user
interaction.

●​ It is part of the java.awt.Label class.


●​ Used to display static text.
●​ Cannot be edited by the user.

Button in AWT

A Button is an interactive component that triggers an action when clicked.

●​ It is part of the java.awt.Button class.


●​ Used to perform actions when clicked.
●​ Generates an ActionEvent when pressed

40)What is thread synchronization? How it is achieved in java?


Thread synchronization is a mechanism that ensures multiple threads do not interfere with each
other when accessing shared resources. It helps prevent race conditions and data
inconsistency in multithreading environments.

How Synchronization is Achieved in Java

Java provides several ways to achieve synchronization:

1.​ Synchronized Methods


○​ Declaring a method as synchronized ensures that only one thread can
execute it at a time.
2.​ Synchronized Blocks
○​ Instead of synchronizing an entire method, you can synchronize a specific block
of code.
3.​ Locks (ReentrantLock)
○​ Java provides explicit locks via the java.util.concurrent.locks package.

4. Volatile Keyword

○​ Ensures visibility of changes to variables across threads.

5.Atomic Variables (AtomicInteger)

○​ Provides thread-safe operations without explicit synchronization.

41)What is JVM? Explain various parts of JVM.

The Java Virtual Machine (JVM) is an essential part of the Java Runtime Environment (JRE)
that executes Java programs by converting bytecode into machine code. It enables Java's
platform independence, allowing programs to run on any system with a JVM.

Key Components of JVM


Component Description

Class Loader Loads Java classes dynamically at runtime.

Method Area Stores class-level data like method definitions and constants.

Heap Memory Allocates memory for objects and class instances.

Stack Memory Stores method calls and local variables for each thread.

Execution Engine Converts bytecode into machine code using the JIT Compiler.

Garbage Collector Automatically manages memory by removing unused objects.


Native Interface Enables interaction with native libraries (JNI).

42)Define java API.

●​ A Java API (Application Programming Interface) is a collection of predefined classes,


interfaces, and methods that allow developers to interact with Java's built-in
functionalities.
●​ It provides a structured way to perform various tasks like file handling, networking,
database access, and GUI development.

43)What is JIT compiler?

The Just-In-Time (JIT) compiler is a part of the Java Runtime Environment (JRE) that
improves the performance of Java applications by compiling bytecode into native machine code
at runtime.

44)What is an identifier?

An identifier in Java is the name used to identify variables, methods, classes, interfaces, and
other programming elements. It must be unique and follow specific naming rules.

Examples

myVariable, _count, $price, sumOfNumbers​

45)Write syntax to create class and object.

Class Syntax
class ClassName {
// Instance variables
int variable;

// Constructor
ClassName() {
variable = 10;
}

// Method
void display() {
System.out.println("Variable: " + variable);
}
}

Object Creation Syntax


public class Main {
public static void main(String[] args) {
// Creating an object of the class
ClassName obj = new ClassName();
obj.display(); // Calling the method
}
}

46)What is keyword? List some of the keywords in java.

●​ A keyword in Java is a reserved word that has a predefined meaning in the language.
●​ These words cannot be used as identifiers (such as variable names, method names, or
class names).

Common Java Keywords


Keyword Description

class Defines a class

public Access modifier allowing visibility everywhere

static Defines a static method or variable

void Specifies that a method does not return a value

if Used for conditional statements

else Specifies an alternative block in an if statement

for Used to create a loop

while Defines a loop that runs while a condition is true

try Starts a block to handle exceptions

catch Handles exceptions thrown in a try block

return Exits from a method and optionally returns a value

new Creates new objects

extends Indicates inheritance from a superclass

implemen Specifies that a class implements an interface


ts
47)What is null, true and false in java?
Literal Description

null Represents the absence of a value or reference. Used for objects but not
primitives.
true Boolean literal indicating a positive condition (boolean flag = true;).

false Boolean literal indicating a negative condition (boolean flag = false;).

48)Define event and the types.

An event in Java is an action or occurrence that happens within a program, typically triggered
by user interactions or system-generated changes. Examples include clicking a button, pressing
a key, or resizing a window.

Types of Events in Java


Events in Java can be broadly classified into two categories:

Event Type Description

Foreground Require user interaction to generate (e.g., button clicks, mouse


Events movements, key presses)

Background Do not require user interaction (e.g., system interrupts, operation


Events completion)

49)List the types of separators in java.

Separator Symbol Usage

Parenthese () Used in method definitions, control statements, and type casting


s

Braces {} Defines blocks of code for classes, methods, and loops

Brackets [] Used for array declarations and indexing

Semicolon ; Terminates statements

Comma , Separates variables in declarations and arguments in method


calls

Period . Used for package access and method invocation

Colon : Used in labels and enhanced for loops


50)Define multi-tasking.

●​ Multitasking refers to the ability of a system to execute multiple tasks simultaneously.


●​ In Java, multitasking is achieved through multithreading, where multiple threads run
concurrently to improve performance and resource utilization.

51)List the different types of comments in java.


Comment Type Description Syntax

Single-line Comment Used for brief explanations within a // This is a


single line single-line comment

Multi-line Comment Used for longer explanations /* This is a


spanning multiple lines multi-line comment */

Documentation Used for generating API /** This is a


Comment documentation using Javadoc documentation comment
*/
52)What is java bean?

A JavaBean is a reusable software component in Java that follows specific conventions to


ensure easy manipulation and integration in applications.

Key Features of JavaBeans

●​ Encapsulation: All properties are private and accessed via public getter and setter
methods.
●​ No-Argument Constructor: Must have a public no-arg constructor for easy
instantiation.

53)What is unicode character?

●​ A Unicode character is a standardized way of representing characters from different


languages, symbols, and scripts across various platforms.
●​ Java uses Unicode to support internationalization, allowing developers to work with
characters beyond ASCII.

54)What is swing in java?

●​ Swing is a GUI (Graphical User Interface) toolkit in Java that provides a rich set of
components for building desktop applications.
●​ It is part of the Java Foundation Classes (JFC) and is an extension of AWT (Abstract
Window Toolkit), offering more flexibility and functionality.

55)Write the general syntax to define a class.


access_modifier class ClassName {
// Instance variables
DataType variableName;

// Constructor
ClassName() {
// Initialization code
}

// Methods
returnType methodName(parameters) {
// Method body
}
}

56)What is dynamic loading?

●​ Dynamic loading in Java refers to the process of loading classes at runtime rather than
at compile time.
●​ This allows programs to load and use classes only when needed, improving flexibility
and efficiency

57)What is type casting?


●​ In Java, type casting is a method or process that converts a data type into
another data type in both ways manually and automatically.
●​ The automatic conversion is done by the compiler and manual conversion
performed by the programmer.

58)What is the use of import keyword?


●​ The use of keyword 'import' in Java programming is used to import the built-in
and user-defined packages, class or interface in Java programming.
●​ When a package has imported, we can refer to all the classes of that package
using their name directly.
●​ The import statement must be after the package statement, and before any other
statement.

59)What is meant by unchecked exception in java?


●​ An unchecked exception is the one which occurs at the time of execution. These
are also called as Runtime Exceptions.
●​ These include programming bugs, such as logic errors or improper use of an
API.
●​ Runtime exceptions are ignored at the time of compilation.

60)Mention the attributes of PARAM tag?


HTML <param> Tag
The <param> tag in HTML is used to define a parameter for plug-ins which is
associated with <object> element. It does not contain the end tag.
Syntax: <param name="" value="">

61)Name the byte stream classes in java.

In Java, byte stream classes are used for handling input and output operations with 8-bit
bytes. These classes are part of the java.io package and are mainly divided into two
categories:

1. Input Stream Classes


Class Description

FileInputStream Reads data from a file as a stream of bytes

ByteArrayInputSt Reads data from a byte array


ream

DataInputStream Reads primitive data types from an input


stream

BufferedInputStr Improves performance by buffering input data


eam

ObjectInputStrea Reads objects from an input stream


m

2. Output Stream Classes


Class Description

FileOutputStream Writes data to a file as a stream of bytes

ByteArrayOutputSt Writes data to a byte array


ream

DataOutputStream Writes primitive data types to an output stream

BufferedOutputStr Improves performance by buffering output data


eam

ObjectOutputStrea Writes objects to an output stream


m
62)What is the method used to flush a stream?
The flush() method of OutputStream class is used to flush the content of the buffer to
the output stream. A buffer is a portion in memory that is used to store a stream of
data(characters). That data sometimes will only get sent to an output device, when the
buffer is full.
Syntax: public void flush() throws IOException

63)Mention two ways to create a thread.


There are two ways to create a thread:
1. By extending Thread class
2. By implementing Runnable interface.
Thread class:
Thread class provide constructors and methods to create and perform operations on a
thread. Thread
class extends Object class and implements Runnable interface.
Runnable interface:
The Runnable interface should be implemented by any class whose instances are
intended to be executed
by a thread. Runnable interface have only one method named run().

64)What do you mean by command line arguments?


●​ Command-line arguments are simple parameters that are given on the system's
command line, and the values of these arguments are passed on to your
program during program execution.
●​ When a program starts execution without user interaction, command-line
arguments are used to pass values or files to it.

65)Differentiate between break and continue statement.


Feature Break Statement Continue Statement

Functionality Terminates the loop entirely Skips the current iteration and
moves to the next one

Execution Exits the loop immediately Continues with the next iteration
Flow of the loop

Usage Used to stop execution when a Used to skip certain iterations


condition is met based on a condition

Compatibility Works with loops (for, while, Works only with loops (for,
do-while) and switch statements while, do-while)

Example if (x == 5) break; if (x == 5) continue;


66)What is static data member and static member function?
Static Data Member
A static data member in C++ is a data member defined in a class that is not instantiated
with each object created of the class. Data members defined in a class are usually
instantiated with every object created of the class.
Syntax: Declaration within the class definition is done by using the keyword-
static.
class scaler{
static int number;
};
Static Member Functions
Static member functions in C++ are the functions that can access only the static data
members. These static data members share a single copy of themselves with the
different objects of the same class. A function can be made static by using the keyword
static before the function name while defining a class.
Syntax:
static returntype function_name(){
}

67)Differentiate between checked and unchecked exceptions.


Feature Checked Exception Unchecked Exception

Occurrence At compile time At runtime

Base Class Derived from Exception Derived from RuntimeException


(except RuntimeException)

Handling Must be handled using No mandatory handling required


Requirement try-catch or declared with
throws

Cause External factors (e.g., file I/O, Programming errors (e.g., null references,
database issues) array index out of bounds)

Examples IOException, NullPointerException,


SQLException, ArithmeticException,
FileNotFoundException ArrayIndexOutOfBoundsException
68)What is meant by controls and what are the different types of controls in AWT?
Controls are components that allow a user to interact with your application and SWT /
AWT supports the following types of controls: Labels, Push Buttons, Check Boxes,
Choice Lists, Lists, Scrollbars, Text Components.

69)What is a vector? How is it different from an array?


A vector is similar to a dynamic array whose size can be increased or decreased. Unlike
arrays, it has no size limit and can store any number of elements. Since Java 1.2, it has
been a part of the Java Collection framework.
Vector is different from an array:
Vectors are the dynamic arrays that are used to store data. It is different from arrays
which store sequential data and are static in nature, Vectors provide more flexibility to
the program. Vectors can adjust their size automatically when an element is inserted or
deleted from it.

70)How can you create an instance of a class in java?


Instantiating a Class
●​ When you create an object, you are creating an instance of a class, therefore
"instantiating" a class.
●​ The new operator requires a single, postfix argument: a call to a constructor.
●​ The name of the constructor provides the name of the class to instantiate.

71)What is java API?


●​ API (Application Programming Interface) in Java is a set of predefined rules and
specifications for accessing a web-based software application or web tool.
●​ It offers a way for developers to interact or integrate two different systems,
allowing for easy exchange of data and communication.

72)What is System.in and System.out?


●​ In Java, System.in is the standard, universally accessible InputStream that
developers use to read input from the terminal window. However, Java's
System.in does not work alone. To read user input with System.in, you must pass
it as an argument to either: The constructor of the Scanner class.
●​ System. out is a method in Java that prints a message to the standard output
(typically the console) and appends a newline character. It's widely used to
display messages, data, and the results of operations during the execution of a
program.

73)Write 2 differences between class and java.


Feature Class Java

Definition Blueprint for creating objects Programming language used to define classes

Usage Defines properties and Provides the environment to execute


behaviors of objects programs

Instantiation Can be instantiated using Cannot be instantiated, it's a language


new

Inheritance Supports single inheritance Supports object-oriented programming


(extends) concepts

Example class Student { public class Main { public static


String name; } void main(String[] args) { } }
74)How do we declare a method as final in java?
We can declare a method as final in java using the final keyword in a method
declaration to indicate that the method cannot be overridden by subclasses.
Example:
class ChessAlgorithm {
enum ChessPlayer { WHITE, BLACK }
...
final ChessPlayer getFirstPlayer() {
return ChessPlayer.WHITE;
}
...
}

75)What are the data types used in java?


Type Size Example

boole 1 byte true or false


an

byte 1 byte byte x = 100;

char 2 char letter = 'A';


bytes

short 2 short num = 5000;


bytes

int 4 int age = 25;


bytes

long 8 long bigNum =


bytes 100000L;

float 4 float price =


bytes 10.99f;

doubl 8 double value =


e bytes 3.14;

Strin Varies String name =


g "Riya";

Array Varies int[] numbers =


{1,2,3};
76)What is default constructor and parameterized constructor?
●​ A constructor which takes no arguments is known as the default constructor.
●​ A constructor which takes one or more arguments is known as parameterized
constructor.

77)Mention the ways of implementing multithreading in java.


There are two ways to implement multithreading in Java is:
1. By extending Thread class
2. By implementing Runnable interface.
Thread class:
Thread class provide constructors and methods to create and perform operations on a
thread. Thread class extends Object class and implements Runnable interface.
Runnable interface:
The Runnable interface should be implemented by any class whose instances are
intended to be executed by a thread. Runnable interface have only one method named
run().

78)Mention any 4 thread methods.


Thread Methods:

●​ start() – Starts the thread.


●​ getState() – It returns the state of the thread.
●​ getName() – It returns the name of the thread.
●​ getPriority() – It returns the priority of the thread.
●​ sleep() – Stop the thread for the specified time.
●​ Join() – Stop the current thread until the called thread gets terminated.
79)Mention any four classes in AWT package.
Class Description

Frame Creates a window with title, buttons, and other


components.

Button Represents a clickable button in a GUI.

Label Displays a text label in a GUI.

TextFi Allows users to enter and edit text.


eld

80)What is JDK?
●​ The Java Development Kit (JDK) is a cross-platformed software development
environment that offers a collection of tools and libraries necessary for
developing Java-based software applications and applets.
●​ It is a core package used in Java, along with the JVM (Java Virtual Machine)
and the JRE (Java Runtime Environment).

81)What is runtime exception?

●​ A Runtime Exception in Java is an unchecked exception that occurs during program


execution.
●​ These exceptions are not checked at compile time, meaning the compiler does not force
the programmer to handle them.

82)What are string literals?


●​ A string literal is a sequence of characters enclosed in single quotes('') or double
quotes("").
●​ For example, 'Hello World' is a string literal and can be written as "Hello World" or
'Hello World'.

83)What does static keyword do in a class?


●​ The static keyword in Java is mainly used for memory management.
●​ The static keyword in Java is used to share the same variable or method of a
given class.

84)What is the need for ‘applet viewer’?


●​ Applet Viewer is a standalone command-line program from Sun to run Java
applets.
●​ Applet viewer is generally used by developers for testing their applets before
deploying them to a website.

You might also like