0% found this document useful (0 votes)
5 views3 pages

Questions

The document outlines key attributes of Object-Oriented Programming (OOP) in Java, including encapsulation, inheritance, polymorphism, abstraction, and classes. It also provides a Java code example for implementing a dynamic stack using an interface and discusses exception handling in Java, including custom exceptions. Additionally, it describes the servlet life cycle phases and the functionality of JavaServer Pages (JSP) for creating dynamic web applications.

Uploaded by

white Devil
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)
5 views3 pages

Questions

The document outlines key attributes of Object-Oriented Programming (OOP) in Java, including encapsulation, inheritance, polymorphism, abstraction, and classes. It also provides a Java code example for implementing a dynamic stack using an interface and discusses exception handling in Java, including custom exceptions. Additionally, it describes the servlet life cycle phases and the functionality of JavaServer Pages (JSP) for creating dynamic web applications.

Uploaded by

white Devil
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/ 3

ention and explain key attributes of Object-Oriented Programming (OOP) along with java

buzzwords.
Ans:
1. **Encapsulation:**
- **Java Buzzword: "private," "public," "protected"**
- Explanation: Encapsulation refers to the bundling of data and methods that
operate on that data within a single unit
2. **Inheritance:**
- **Java Buzzword: "extends," "super"**
- Explanation: Inheritance is the mechanism that allows a new class (subclass or
derived class) to inherit properties and behaviors from an existing class (superclass or
base class
3. **Polymorphism:**
- **Java Buzzword: "overloading," "overriding"**
- Explanation: Polymorphism allows objects of different types to be treated as
objects of a common type. In Java, polymorphism is achieved through method
overloading and method overriding. Method overloading involves defining multiple
methods with the same name in the same class but with different parameter lists.
Method overriding occurs when a subclass provides a specific implementation for a
method that is already defined in its superclass.
4. **Abstraction:**
- **Java Buzzword: "abstract," "interface"**
- Explanation: Abstraction involves hiding the complex implementation details and
showing only the essential features of an object. In Java, abstraction is achieved using
abstract classes and interfaces.
5.Class:
Java Buzzword: "Class"
Explanation: A class is a blueprint for creating objects. It defines the properties
(attributes) and behaviors (methods) that the objects will have. Objects are instances
of classes.
========================================================================================================================================================

2. Define interface . Build java code to implement stack operation for dynamic
stack using interface
public interface Stack {
void push(int value);
int pop();
}
public class DynamicStack implements Stack {
private int[] stack;
private int top;
public DynamicStack(int size) {
stack = new int[size];
top = -1;
}
public void push(int value) {
if (top >= stack.length - 1) {
return false;
}
stack[++top] = value;
return true;
}
public int pop() {
if (isEmpty()) {
throw new RuntimeException("Stack is empty");
}
return stack[top--];
}}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
3.Exception Handling in Java:
Exceptions are events that occur during the execution of a program that disrupt the
normal flow of instructions. They can be of two types: Checked Exceptions (which are
checked at compile time) and Unchecked Exceptions (which are not checked at compile
time).
Handling Exceptions in Java:
1. try-catch block: This block is used to catch and handle exceptions. The code inside the
'try' block may throw an exception, which is caught in the 'catch' block.
2. throws keyword: This keyword is used to declare exceptions. It specifies that the method
does not want to handle the exception, instead it is passed to the method that called it.
3. finally block: This block is executed whether an exception is thrown or not.
Java code to demonstrate user defined /Custom Exception class
package exceptiondemo;
public class ExceptionDemo {
public static void main(String[] args) {
try {
int a=args.length;
System.out.println("number of arguments=" +a);
int b=42/a;
if(args.length==1) {
int c[]={1};
c[42]=99;
}
else {
int a1=Integer.parseInt(args[0]);
int a2=Integer.parseInt(args[1]);
System.out.println("Given arguments" +a1 +"and" +a2); }
}
catch(ArithmeticException e) {
System.out.println("Divide by 0" +e);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println("Array index oob" +e);
}
catch(NumberFormatException e) {
System.out.println("Improper input" +e);
}
System.out.println("After try catch block");
}}
----------------------------------------------------------------------------------------------------------------
5.Abstract Classes: An abstract class is a class that cannot be instantiated, and it is
meant to be subclassed by other classes. Abstract classes can have abstract methods
and non-abstract methods.
=====================================================
============

6.Servlet life cycle phases include initialization, service, and destruction.

->The initialization phase is when the servlet is loaded into memory and any one-time
initializations are performed.

->The service phase involves processing requests and generating responses.

->The destruction phase is when the servlet is removed from memory and any
resources it was using are released.

Servlet can read four specific request headers, including "Host", "User-Agent",
"Accept", and "Accept-Language".

->The "Host" header indicates the domain name of the server,

-> the "User-Agent" header specifies information about the client software,

->the "Accept" header describes the types of data formats the client can understand,
and

->the "Accept-Language" header specifies the client's preferred natural language.


=====================================================
============

7.JavaServer Pages (JSP) is a technology that helps developers create dynamic, platform-
independent web applications. JSP includes scripting elements like expressions, scriptlets, and
declarations.
• JSP technically can do anything that servlets do.
• The process of making JavaServer Pages accessible on the Web is much simpler
than that for servlets
• Separates the (Java) code that creates the content from the (HTML) code that
presents it.

You might also like