BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
Java Programming - Quick Exam Notes
1. Data Types
Q: What are Java data types? A: Two categories:
Primitive (8 types): int, long, float, double, char, boolean, byte, short - passed by value
Non-Primitive: String, Array, Class, Interface - passed by reference
2. Control Structures
Q: What are control structures in Java? A: Three types:
Conditional: if, if-else, switch
Loops: while, do-while, for
Jump: break, continue, return
3. Arrays
Q: What is an array? A: Collection of same data type elements
Declaration: int[] arr = new int[5];
Initialization: int[] arr = {1,2,3,4,5};
Access: arr[0] (index starts at 0)
Multi-dimensional: int[][] arr = new int[3][3];
4. Strings
Q: What is a String? A: Immutable sequence of characters
Declaration: String s = "Hello";
Concatenation: "John " + "Doe"
Methods: length(), charAt(index)
5. Vector
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
Q: What is Vector? A: Synchronized dynamic array (thread-safe)
java
Vector<Integer> v = new Vector();
[Link](1); // add element
[Link](0); // get element
[Link](); // get size
6. Classes
Q: What is a class? A: Blueprint for creating objects
Contains: instance variables + methods
Object creation: Dog myDog = new Dog("Lab", 5);
Constructor initializes objects
7. Inheritance
Q: What is inheritance? A: Subclass inherits properties from superclass
Uses extends keyword
Example: class Dog extends Animal
Use super() to call parent constructor
Promotes code reusability
8. Packages
Q: What is a package? A: Collection of related classes/interfaces
Declaration: package [Link];
Import: import [Link];
Organizes code, prevents naming conflicts
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
9. Exception Handling
Q: What is exception handling? A: Handles errors gracefully
java
try {
// risky code
} catch (ExceptionType e) {
// handle error
} finally {
// always executes
10. Multithreading
Q: What is multithreading? A: Multiple threads run concurrently
Method 1: Extend Thread class, override run()
Method 2: Implement Runnable interface
Start thread: [Link]()
Enables parallel task execution
Good luck with your exam! 🎯
Retry
Claude does not have the ability to run the code it generates yet.
RS
a little bit detailed
Java Programming - Detailed Exam Notes
1. Data Types
Q: Explain data types in Java with examples.
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
A: Java has two categories:
Primitive Data Types (8 types):
int: stores whole numbers (-2³¹ to 2³¹-1)
long: stores large whole numbers (-2⁶³ to 2⁶³-1)
float: stores decimals (7 significant digits)
double: stores decimals (16 significant digits)
char: stores single character
boolean: stores true/false
byte: stores values (-128 to 127)
short: stores values (-32,768 to 32,767)
Non-Primitive Data Types:
String: immutable sequence of characters
Array: collection of similar elements
Class: blueprint for objects
Interface: blueprint for class methods
Key Difference: Primitives passed by value (copy created), non-primitives passed by reference (original object
modified)
2. Control Structures
Q: What are control structures? Explain with examples.
A: Control structures manage program flow:
1. Conditional Statements:
if: executes code if condition true
if-else: executes one block if true, another if false
switch: selects one block from many options
2. Looping Structures:
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
while: repeats code while condition true
do-while: executes once, then repeats while condition true
for: repeats code specific number of times
3. Jump Statements:
break: exits loop early
continue: skips current iteration, moves to next
return: exits method and returns value
3. Arrays
Q: What are arrays? How to declare and use them?
A: Array is collection of elements of same data type.
Declaration:
java
int[] numbers = new int[5]; // declares array of size 5
Initialization:
java
int[] numbers = {1, 2, 3, 4, 5}; // declare and initialize
Accessing Elements:
java
int first = numbers[0]; // index starts at 0
numbers[2] = 6; // modify element
Multi-dimensional Arrays:
java
int[][] matrix = new int[3][3]; // 2D array (3x3)
matrix[0][0] = 1; // access using row and column index
Uses:
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
Store list of values (student marks)
Store related values (shopping cart prices)
Iterate over values
4. Strings
Q: Explain String class with operations.
A: String is object representing sequence of characters (immutable).
Declaration & Initialization:
java
String greeting = "Hello, World!"; // using literal
char[] arr = {'H','e','l','l','o'};
String s = new String(arr); // using constructor
Operations:
Concatenation: String full = "John " + "Doe";
Length: int len = [Link]();
Character Access: char ch = [Link](0);
Key Point: Strings are immutable - once created, value cannot be changed.
5. Vector
Q: What is Vector class? Explain with example.
A: Vector is synchronized dynamic array (thread-safe). Multiple threads can access simultaneously without
data corruption.
Example:
java
import [Link];
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
Vector<Integer> numbers = new Vector();
[Link](1); // add elements
[Link](2);
[Link](3);
[Link]([Link](0)); // get element at index 0
[Link](1); // remove element at index 1
[Link](5, 1); // insert 5 at index 1
int size = [Link](); // get size
Advantages:
Dynamic size (grows/shrinks automatically)
Thread-safe (synchronized)
Similar to ArrayList but safer for multi-threading
6. Classes and Objects
Q: What is a class? Explain with example.
A: Class is blueprint/template for creating objects. Contains instance variables (attributes) and methods
(behavior).
Example:
java
public class Dog {
private String breed;
private int age;
// Constructor
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
public Dog(String breed, int age) {
[Link] = breed;
[Link] = age;
// Methods
public void bark() {
[Link]("Woof!");
public void printInfo() {
[Link]("Breed: " + breed + ", Age: " + age);
Creating Object:
java
Dog myDog = new Dog("Labrador", 5);
[Link](); // calls method
[Link]();
Components:
Instance variables: breed, age
Constructor: initializes object
Methods: define behavior
7. Inheritance
Q: Explain inheritance with example.
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
A: Inheritance allows new class to inherit properties and methods from existing class. Uses extends keyword.
Terminology:
Superclass: parent class (inherited from)
Subclass: child class (inherits properties)
Example:
java
class Animal {
private String name;
public Animal(String name) {
[Link] = name;
public void move() {
[Link]("Animal is moving.");
class Dog extends Animal {
private String breed;
public Dog(String name, String breed) {
super(name); // call parent constructor
[Link] = breed;
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
public void bark() {
[Link]("Woof!");
Usage:
java
Dog myDog = new Dog("Max", "Labrador");
[Link](); // inherited from Animal
[Link](); // defined in Dog
Benefits:
Code reusability
Creates specialized classes
Establishes parent-child relationship
8. Packages
Q: What are packages? How to create and use them?
A: Package is collection of related classes and interfaces. Organizes code and prevents naming conflicts.
Creating Package:
java
package [Link];
public class MyClass {
// class code
Using Package:
java
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
import [Link];
public class Main {
public static void main(String[] args) {
MyClass obj = new MyClass();
Standard Java Packages:
[Link]: collections, data structures
[Link]: input/output operations
[Link]: network programming
Benefits:
Organizes code structure
Prevents naming conflicts
Makes code maintainable and reusable
9. Exception Handling
Q: What is exception handling? Explain with example.
A: Exception handling manages errors gracefully without crashing program. Uses try-catch-finally blocks.
Syntax:
java
try {
// code that may cause error
int result = 10 / 0; // throws ArithmeticException
catch (ArithmeticException e) {
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
// handle specific exception
[Link]("Cannot divide by zero");
catch (Exception e) {
// handle any other exception
[Link]("Error occurred");
finally {
// always executes (optional)
[Link]("This always runs");
Components:
try: contains risky code
catch: handles specific exceptions
finally: executes regardless of exception (cleanup code)
Benefits:
Prevents program crash
Provides meaningful error messages
Separates error handling from normal code
10. Multithreading
Q: What is multithreading? Explain with examples.
A: Multithreading allows multiple threads to run concurrently within single program. Enables parallel task
execution.
Method 1: Extending Thread Class
java
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
class WorkerThread extends Thread {
public void run() {
[Link]("Worker thread starting");
public class Main {
public static void main(String[] args) {
WorkerThread worker = new WorkerThread();
[Link](); // starts thread
[Link]("Main thread continuing");
Method 2: Implementing Runnable Interface
java
class WorkerRunnable implements Runnable {
public void run() {
[Link]("Worker thread starting");
public class Main {
public static void main(String[] args) {
Thread worker = new Thread(new WorkerRunnable());
[Link]();
[Link]("Main thread continuing");
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I)
}
Key Points:
run() method contains thread code
start() method begins thread execution
Multiple threads run independently and concurrently
Benefits:
Better CPU utilization
Improved performance
Parallel task execution
Responsive applications
BCA5002 – Java Programming and Dynamic Webpages Design (Unit-I) RAMAN SHUKLA