KEMBAR78
Questions | PDF | Method (Computer Programming) | Class (Computer Programming)
0% found this document useful (0 votes)
5 views25 pages

Questions

Uploaded by

praashant1777
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)
5 views25 pages

Questions

Uploaded by

praashant1777
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/ 25

Q1. Explain the structure of an HTML document with a neat diagram.

Q2. Differentiate between HTML4 and HTML5 with appropriate examples.

Q3. Explain the concept and uses of semantic tags in HTML5. Provide examples.

Q4. Discuss various types of lists in HTML with examples and appropriate tables.

Q5. Explain different types of CSS (Inline, Internal, External) with syntax and examples.

Q6. What is the Box Model in CSS? Explain with diagram and code example.

Q7. Differentiate between ID and Class selectors with examples.

Q8. Explain Flexbox layout in CSS with a diagram and real-world use cases

Q9. Explain JavaScript variable scoping (var, let, const) with examples and comparison
table.

Q10. Differentiate between synchronous and asynchronous JavaScript with examples.

Q11. Explain DOM manipulation with examples and diagram.

Q12. What are JavaScript events? Explain event handling with examples.

Q13. Explain the concept of closures in JavaScript with real-world examples.

Q14. Differentiate between == and === in JavaScript with examples.

Q15. Explain functions, function expressions, and arrow functions with examples.

Q16. Explain promises in JavaScript with syntax, diagram, and example.

Q17. What is event bubbling and event capturing? Explain with diagram.

Q18. Explain JSON and its uses in JavaScript with examples.

Q19. Explain error handling (try-catch-finally) in JavaScript with example.

Q20. Explain OOP principles (Inheritance, Encapsulation, Polymorphism, Abstraction) with


diagrams.

Q21. Differentiate between method overloading and method overriding with examples.

Q22. Explain exception handling in Java with try-catch-finally block and examples.

Q23. What is JDBC? Explain steps to connect Java with database using JDBC with diagram.
Q24. Explain Java Collections framework with examples and diagrams.

Q25. Differentiate between ArrayList and LinkedList with examples and table.

Q26. Explain multithreading in Java with Thread class and Runnable interface.

Q27. What is interface and abstract class in Java? Compare with examples.

Q28. Explain the concept of packages and access specifiers in Java with examples.

Q29. Discuss Java Applets and how they differ from Java Applications. Provide lifecycle
diagram.

Q30. Explain serialization and deserialization in Java with code example.

Q1. Explain the structure of an HTML document with a neat diagram.

An HTML document follows a defined structure that helps browsers interpret and display
web content correctly. It consists of elements wrapped in tags that denote document
metadata and visible content.

Basic structure:

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>

<h1>Heading</h1>

<p>Paragraph</p>

</body>

</html>
Diagram:

<!DOCTYPE html> — Document type declaration

└── <html> — Root element

├── <head> — Metadata

│ └── <title> — Page title

└── <body> — Visible content

├── <h1> — Heading

└── <p> — Paragraph

Explanation of parts:

 <!DOCTYPE html> — Informs the browser about HTML5 version

 <html> — Root container

 <head> — Metadata (title, CSS, scripts)

 <body> — All content visible to users

Q2. Differentiate between HTML4 and HTML5 with appropriate examples.

Feature HTML4 HTML5

Doctype <!DOCTYPE HTML PUBLIC...> <!DOCTYPE html>

Multimedia Support Requires plugins (Flash) Native <audio> and <video> tags

New Elements Not available <article>, <section>, <nav>

Form Enhancements Limited input types email, date, url, range

APIs Not supported Geolocation, Web Storage

Example (HTML5 video):

<video controls>

<source src="movie.mp4" type="video/mp4">

</video>

Q3. Explain the concept and uses of semantic tags in HTML5. Provide examples.
Semantic tags clearly define the purpose of an element, improving readability, SEO, and
accessibility.

Examples of semantic tags:

 <header> — Page header

 <nav> — Navigation links

 <article> — Independent content

 <section> — Document section

 <footer> — Page footer

Example code:

<article>

<h2>News Article</h2>

<p>This is a sample article.</p>

</article>

Advantages:

 Improves SEO (search engines understand structure)

 Enhances accessibility (screen readers navigate better)

 Makes code readable and maintainable

Q4. Discuss various types of lists in HTML with examples and appropriate tables.

HTML provides 3 main types of lists:

Type Tag Description Example

Ordered List <ol> Numbered list <ol><li>One</li></ol>

Unordered List <ul> Bulleted list <ul><li>Item</li></ul>

Definition List <dl> Terms & descriptions <dl><dt>Term</dt><dd>Def</dd></dl>

Example code:
<ul>

<li>HTML</li>

<li>CSS</li>

<li>JavaScript</li>

</ul>

Diagram:

css

<ul>

└── <li> Item 1

└── <li> Item 2

Q6. What is the Box Model in CSS? Explain with diagram and code example.

The CSS Box Model describes how elements are displayed and how space is calculated.

Components:

+-----------------------------+

| Margin |

| +---------------------+ |

| | Border | |

| | +-------------+ | |

| | | Padding | | |

| | | +-------+ | | |

| | | |Content| | | |

| | | +-------+ | | |
| | +-------------+ | |

| +---------------------+ |

+-----------------------------+

Example CSS:

div {

width: 200px;

padding: 20px;

border: 5px solid black;

margin: 15px;

Q7. Differentiate between ID and Class selectors with examples.

Feature ID Selector Class Selector

Symbol #idname .classname

Usage Unique element Multiple elements

Syntax #header { color: red; } .menu { color: blue; }

HTML <div id="header"> <div class="menu">

Example:

#header {

background: yellow;

.menu {

color: blue;

Q8. Explain Flexbox layout in CSS with a diagram and real-world use cases.

CSS Flexbox is used to create flexible and responsive layouts easily.


Diagram:

Container (display: flex)

├── Item 1

├── Item 2

└── Item 3

Example CSS:

.container {

display: flex;

justify-content: space-between;

Real-world use cases:

 Navbars

 Card layouts

 Centering content both vertically and horizontally

Advantages:

 Automatically adjusts spacing

 Handles dynamic content

 Simplifies responsive design

Q9. Explain JavaScript variable scoping (var, let, const) with examples and comparison
table.

In JavaScript, var, let, and const are used to declare variables, but they differ in scope and
behavior.

Feature var let const

Scope Function-scoped Block-scoped Block-scoped

Redeclaration Allowed Not allowed Not allowed

Reassignment Allowed Allowed Not allowed


Feature var let const

Yes (initialized as Yes (temporal dead Yes (temporal dead


Hoisting
undefined) zone) zone)

Example:

if (true) {

var a = 10;

let b = 20;

const c = 30;

console.log(a); // 10

// console.log(b); // Error

// console.log(c); // Error

Q10. Differentiate between synchronous and asynchronous JavaScript with examples.

Feature Synchronous Asynchronous

Execution Line-by-line (blocking) Non-blocking

Example Loops, function calls setTimeout, Promises

Blocking Yes No

Example (Async):

console.log("Start");

setTimeout(() => console.log("Async"), 1000);

console.log("End");
Output:

Start

End

Async

Advantages of Asynchronous:

 Better user experience (non-freezing UI)

 Enables API calls, animations, etc.

Q11. Explain DOM manipulation with examples and diagram.

The Document Object Model (DOM) represents HTML as a tree of nodes that can be
manipulated using JavaScript.

Diagram (simplified):

document

└── html

├── head

└── body

├── h1

└── p

Example:

document.getElementById("demo").innerHTML = "Hello!";

Common Methods:

 getElementById()

 querySelector()

 createElement()

Advantages:

 Dynamically change content

 React to user actions


Q12. What are JavaScript events? Explain event handling with examples.

Events are actions that occur in the browser (click, keypress, load, etc.). JavaScript can
handle these events to make pages interactive.

Example:

<button onclick="alert('Clicked!')">Click Me</button>

Common Event Types:

 Mouse: click, dblclick, mouseover

 Keyboard: keydown, keyup

 Form: submit, change

Example (addEventListener):

javascript

CopyEdit

document.getElementById("btn").addEventListener("click", () => {

alert("Button clicked!");

});

Advantages:

 Enhances interactivity

 Handles user input and navigation

Q13. Explain the concept of closures in JavaScript with real-world examples.

A closure is a function that remembers its lexical scope even when executed outside of that
scope.

Example:

function outer() {

let count = 0;

return function inner() {

count++;

console.log(count);

};
}

const counter = outer();

counter(); // 1

counter(); // 2

Real-world use:

 Data encapsulation

 Private variables

Advantages:

 Avoids global scope pollution

 Maintains state between function calls

Q14. What are JavaScript functions? Explain different types of functions with examples.

Functions are reusable blocks of code that perform specific tasks.

Types of functions:

Type Example Notes

Function Declaration function add() {} Hoisted

Function Expression const add = function() {} Not hoisted

Arrow Function const add = () => {} Short syntax

Anonymous Function function() {} No name

Immediately Invoked Function (IIFE) (function() {})(); Runs immediately

Example:

javascript

CopyEdit

function greet(name) {

return "Hello " + name;

console.log(greet("Alice"));

Advantages:
 Code reusability

 Modular code

Q15. Explain JavaScript arrays and their methods with suitable examples and a table.

Arrays are used to store multiple values in a single variable.

Example:

let fruits = ["Apple", "Banana", "Cherry"];

Method Usage Example

push() Add to end fruits.push("Mango")

pop() Remove from end fruits.pop()

shift() Remove from start fruits.shift()

unshift() Add to start fruits.unshift("Lemon")

map() Transform array fruits.map(f => f.toUpperCase())

filter() Filter elements fruits.filter(f => f.startsWith("A"))

Advantages:

 Store multiple items

 Powerful built-in methods

Q16. Differentiate between == and === operators in JavaScript with examples.

Operator Name Checks Example Result

== Equality Value only (type coercion) 5 == "5" true

=== Strict equality Value + Type 5 === "5" false

Example:

console.log(5 == '5'); // true

console.log(5 === '5'); // false

Recommendation: Always use === to avoid unexpected results.


Q17. What is the difference between null and undefined in JavaScript?

Feature null undefined

Type Object Undefined

Meaning Empty / intentional absence Not assigned

Example let a = null; let b; (b is undefined)

Equality null == undefined (true)

Example:

let a = null;

let b;

console.log(a); // null

console.log(b); // undefined

Q18. Explain JavaScript objects and how to create and access them with examples.

Objects store key-value pairs.

Example (object literal):

let person = {

name: "SPPU",

age: 12

};

console.log(person.name); // SPPU

Ways to create objects:

 Object literal ({})

 new Object()

 Object.create()`

Access methods:

 Dot notation: person.name

 Bracket notation: person['name']


Advantages:

 Model real-world entities

 Flexible and extensible

Q19. What is event bubbling and event capturing in JavaScript? Explain with diagram and
examples.

Events propagate in 2 phases:

Phase Description Example

Capturing Outer → Inner Less common

Bubbling Inner → Outer Default

Diagram:

<html>

└── <body>

└── <div>

└── <button>Click</button>

Example:

button.addEventListener('click', () => alert('Button'), false); // bubbling

div.addEventListener('click', () => alert('Div'), true); // capturing

Use:

 Event delegation

 Control event flow

Q20. What are promises in JavaScript? Explain states, syntax and example.

A Promise represents the eventual completion (or failure) of an asynchronous operation and
its resulting value.

States of a Promise:

 Pending – Initial state


 Fulfilled – Operation completed successfully

 Rejected – Operation failed

Diagram (Promise Lifecycle):

Pending

├── Fulfilled → .then()

└── Rejected → .catch()

Syntax:

javascript

CopyEdit

let promise = new Promise((resolve, reject) => {

// async task

resolve("Success");

// or reject("Error");

});

Example:

let promise = new Promise((resolve) => {

setTimeout(() => resolve("Done!"), 1000);

});

promise.then(result => console.log(result)); // Done!

Advantages:

 Handles async tasks clearly

 Replaces callback hell

Q21. Explain localStorage and sessionStorage in JavaScript with example and table.
Both localStorage and sessionStorage are part of the Web Storage API, used to store data in
the browser.

Feature localStorage sessionStorage

Persistence Until manually cleared Until browser/tab closed

Capacity ~5MB ~5MB

Scope All tabs/windows Current tab only

Example localStorage.setItem("key", "value") sessionStorage.setItem("key", "value")

Example:

// Save data

localStorage.setItem("name", "SPPU");

sessionStorage.setItem("course", "JS");

// Retrieve data

console.log(localStorage.getItem("name")); // SPPU

Advantages:

 Store small amounts of data

 Fast and easy to use

Q22. Explain error handling using try-catch-finally block with example and diagram.

try-catch-finally allows handling runtime errors gracefully.

Syntax:

try {

// Code that may throw an error

} catch (error) {

// Handle error

} finally {

// Executes always

}
Example:

try {

let x = y + 1; // y is not defined

} catch (error) {

console.log("Error: " + error.message);

} finally {

console.log("Always runs");

Flow Diagram:

try → success → skip catch → finally

try → error → catch → finally

Advantages:

 Prevents crashes

 Provides fallback behavior

Q23. Explain Java Object-Oriented Programming (OOP) concepts with examples and
diagram.

Java is a fully object-oriented language supporting these key concepts:

Concept Description Example

Encapsulation Wrapping data and methods Private variables with getters/setters

Inheritance Reuse properties of a class class Dog extends Animal

Polymorphism Many forms (method overloading/overriding) Same method name,


different behavior

Abstraction Hiding implementation details Abstract classes/interfaces

Diagram (OOP concepts relationship):


Animal (Superclass)

Dog (Subclass)

Example (Encapsulation):

class Person {

private String name;

public String getName() { return name; }

public void setName(String name) { this.name = name; }

Advantages:

Modular code

Easier maintenance and reuse

Q24. Differentiate between abstract class and interface in Java with examples and table.

Feature Abstract Class Interface

Methods Can have abstract + concrete methods All methods abstract (till Java 7),
default/static (Java 8+)

Variables Can have instance variables Only static final (constants)

Inheritance Single Multiple

Constructor Yes No

Example (Interface):
interface Animal {

void eat();

class Dog implements Animal {

public void eat() { System.out.println("Dog eats"); }

Example (Abstract class):

abstract class Animal {

abstract void eat();

void sleep() { System.out.println("Sleeping"); }

Q25. Explain Java exception handling mechanism with try-catch-finally and throws clause.

Java provides structured exception handling to manage runtime errors.

Block Purpose

try Code that may throw an exception

catch Handle exception

finally Always execute (cleanup)

throws Declares an exception may be thrown

Example:

try {

int result = 10 / 0;

} catch (ArithmeticException e) {

System.out.println("Cannot divide by zero");

} finally {
System.out.println("Finally block");

Example (throws):

void readFile() throws IOException {

// code that may throw IOException

Advantages:

Graceful error handling

Prevents program crashes

Q26. What is multithreading in Java? Explain thread lifecycle with diagram and example.

Multithreading allows concurrent execution of two or more threads for maximum CPU
utilization.

Thread Lifecycle Diagram:

New → Runnable → Running → Blocked/Waiting → Terminated

State Description

New Thread object created

Runnable Ready to run

Running Actively executing

Blocked Waiting for resource

Terminated Execution finished


Example:

class MyThread extends Thread {

public void run() {

System.out.println("Thread running");

MyThread t1 = new MyThread();

t1.start();

Advantages:

Better CPU utilization

Parallel task execution

Q27. Differentiate between method overloading and method overriding in Java with
examples and table.

Feature Method Overloading Method Overriding

Same method name, different Same method name, same


Definition
parameters (within same class) parameters (in subclass)

Inheritance Not required Required

Compile/runtime Compile-time polymorphism Runtime polymorphism

Example class Same class Subclass

Cannot reduce parent access


Access modifier Can have any
level

Example (Overloading):
class Calculator {

int add(int a, int b) { return a + b; }

double add(double a, double b) { return a + b; }

Example (Overriding):

java

CopyEdit

class Animal {

void sound() { System.out.println("Animal sound"); }

class Dog extends Animal {

void sound() { System.out.println("Dog barks"); }

Q28. What is Java Collection Framework? Explain List, Set, and Map with examples and
table.

The Java Collection Framework provides classes and interfaces to store and manipulate
groups of objects.

Interface Features Example

List Ordered, allows duplicates ArrayList, LinkedList

Set No duplicates, unordered HashSet, TreeSet

Map Key-value pairs HashMap, TreeMap

Example (List):

List<String> list = new ArrayList<>();

list.add("A");

list.add("B");

Example (Set):

Set<String> set = new HashSet<>();


set.add("A");

set.add("B");

Example (Map):

Map<Integer, String> map = new HashMap<>();

map.put(1, "One");

map.put(2, "Two");

Advantages:

 Efficient data manipulation

 Standardized data structures

Q29. Explain JDBC architecture. Write steps to connect Java with database along with
diagram.

JDBC (Java Database Connectivity) allows Java to interact with relational databases.

Architecture Diagram:

Java App → JDBC API → JDBC Driver Manager → JDBC Driver → Database

Steps to connect Java with database:

1. Import packages

2. Load driver class

3. Establish connection

4. Create statement

5. Execute query

6. Process result

7. Close connection

Example:

Class.forName("com.mysql.cj.jdbc.Driver");

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb",


"user", "pass");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM students");


while(rs.next()) { System.out.println(rs.getString(1)); }

con.close();

Q30. What is servlet in Java? Explain servlet life cycle with diagram and example.

Servlet is a Java class that handles HTTP requests and generates dynamic web content.

Servlet Lifecycle Diagram:

init() → service() → destroy()

Method Purpose

init() Initialize servlet

service() Handle request/response

destroy() Cleanup

Example (Basic Servlet):

public class MyServlet extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {

res.getWriter().println("Hello Servlet");

Advantages:

 Platform independent

 Efficient for dynamic web apps

You might also like