0% found this document useful (0 votes)
2 views4 pages

Java Exam Notes

The document provides exam notes on Java OOP concepts, including the main method structure, classpath, and Java RMI architecture. It covers various programming topics such as file analysis, function overloading, dynamic binding, and differences between String and StringBuffer. Additional topics include applet lifecycle, socket types, literals, threading, garbage collection, and system calls.

Uploaded by

sanakhannnnn49
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)
2 views4 pages

Java Exam Notes

The document provides exam notes on Java OOP concepts, including the main method structure, classpath, and Java RMI architecture. It covers various programming topics such as file analysis, function overloading, dynamic binding, and differences between String and StringBuffer. Additional topics include applet lifecycle, socket types, literals, threading, garbage collection, and system calls.

Uploaded by

sanakhannnnn49
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

Java OOPS & Programming - Exam Notes

3(a) public static void main(String args[])

Components: - public: access specifier, JVM can access from anywhere - static: belongs to class, JVM can call
without object - void: no return value - main: method name, entry point - String args[]: command-line
arguments

Not used in Applets/Servlets; they use init(), start(), paint(), service() etc.

3(b) Classpath

Definition: path where JVM/compiler searches for classes/packages. Utility: helps find user-defined classes,
external jars. Example: javac -classpath C:\MyJava\Classes [Link] java -classpath C:
\MyJava\Classes MyProgram

3(c) Java RMI Architecture

Definition: RMI (Remote Method Invocation) allows Java programs to call methods on remote objects in
different JVMs.

Components: - Client: calls remote methods - Server: implements remote objects - Remote Interface:
declares remote methods - Stub: client-side proxy - Skeleton: server-side dispatcher (older versions) - RMI
Registry: object lookup service

Diagram: CLIENT JVM --> Stub --> Network --> Skeleton --> Server Object

4(a) File Analysis Program

import [Link].*;

class FileAnalysis {
public static void main(String[] args) {
try {
FileReader fr = new FileReader("[Link]");
int ch;
int charCount = 0, wordCount = 0, spaceCount = 0, fullStopCount = 0;
boolean wordFlag = false;
while ((ch = [Link]()) != -1) {
charCount++;

1
char c = (char) ch;
if (c == ' ') {
spaceCount++;
wordFlag = false;
} else if (c == '.') {
fullStopCount++;
wordFlag = false;
} else {
if (!wordFlag) {
wordCount++;
wordFlag = true;
}
}
}
[Link]();
[Link]("Total Characters: " + charCount);
[Link]("Total Words: " + wordCount);
[Link]("Total Spaces: " + spaceCount);
[Link]("Total Full Stops: " + fullStopCount);
} catch (IOException e) {
[Link]("Error reading file: " + [Link]());
}
}
}

Logic: read characters, count spaces/full stops, use flag to count words.

(a) Function Overloading in Java

Definition: multiple methods with same name, different parameters. Example:

class Calculator {
int add(int a, int b) { return a+b; }
int add(int a, int b, int c) { return a+b+c; }
double add(double a, double b) { return a+b; }
}

(b) Dynamic Binding

Definition: method call resolved at runtime (late binding), used with method overriding. Example:

2
Animal obj = new Dog();
[Link](); // Dog's method executed

Advantages: runtime polymorphism, flexibility, extensibility.

(c) Main method static in Java

Reason: JVM can call it without creating object, program execution starts before object creation, belongs to
class.

(d) String vs StringBuffer

Feature String StringBuffer

Mutability Immutable Mutable

Memory New object per change Same object modified

Performance Slower Faster

Thread-safe No Yes

Methods concat(), replace() append(), insert(), delete(), reverse()

Package [Link] [Link]

Use StringBuffer for frequent modifications.

(a) This keyword

Definition: refers to current object instance. Example:

class Student {
String name;
Student(String name) { [Link] = name; }
}

(b) AWT vs Swing

Feature AWT Swing

Platform Dependent Independent

3
Feature AWT Swing

Components Heavyweight Lightweight

Look & Feel OS native Customizable

Package [Link] [Link]

(c) Factorial Program

import [Link];
class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int num = [Link]();
int fact = 1;
for(int i=1;i<=num;i++) fact *= i;
[Link](fact);
[Link]();
}
}

(d) Applet Lifecycle: init(), start(), paint(), stop(), destroy() with diagram. (e) Stream vs Datagram Socket: TCP
vs UDP, connection vs connectionless, reliable vs unreliable. (f) Literals: integer, floating-point, character,
string, boolean. (g) Threads via Runnable, Thread priority. (h) Garbage Collection: automatic memory
management, advantages/disadvantages.

Additional Topics Covered: - Network vs Distributed OS (NOS vs DOS) - System Call: user to kernel mode
transition - Banker's Algorithm: Available & Need matrices, safe sequence - CPU Scheduling: Pre-emptive vs
Non-Pre-emptive with examples

You might also like