A comprehensive guide to all Java 1.1 concepts with practical examples for interview preparation.
- Inner Classes
- JavaBeans
- JDBC (Java Database Connectivity)
- RMI (Remote Method Invocation)
- Reflection API
- Common Interview Questions
Java 1.1 introduced inner classes, allowing classes to be defined within other classes.
Inner classes provide better encapsulation and can access private members of the outer class.
class Outer {
private String message = "Hello from Outer";
class Inner {
void display() {
System.out.println(message); // Can access outer's private members
}
}
}
// Usage
Outer outer = new Outer();
Outer.Inner inner = outer.new Inner();
inner.display();class Outer {
void method() {
class LocalInner {
void display() {
System.out.println("Local inner class");
}
}
LocalInner local = new LocalInner();
local.display();
}
}interface Greeting {
void greet();
}
// Anonymous inner class
Greeting greeting = new Greeting() {
public void greet() {
System.out.println("Hello from anonymous class");
}
};
greeting.greet();- Better encapsulation
- Access to outer class private members
- Logical grouping of classes
- More readable code
See InnerClassesExample.java for complete example.
JavaBeans is a component architecture for reusable Java components.
JavaBeans follow specific conventions for creating reusable components.
public class PersonBean {
private String name;
private int age;
// No-arg constructor
public PersonBean() {
}
// Getter methods
public String getName() {
return name;
}
public int getAge() {
return age;
}
// Setter methods
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
}- No-argument constructor
- Getter methods (getPropertyName)
- Setter methods (setPropertyName)
- Serializable (optional)
- Property change support (optional)
See JavaBeansExample.java for complete example.
JDBC provides a standard API for database connectivity.
JDBC allows Java applications to connect to databases and execute SQL queries.
import java.sql.*;
public class JDBCExample {
public static void main(String[] args) {
try {
// Load driver
Class.forName("com.mysql.jdbc.Driver");
// Create connection
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydb", "user", "password");
// Create statement
Statement stmt = conn.createStatement();
// Execute query
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
// Process results
while (rs.next()) {
System.out.println(rs.getString("name"));
}
// Close resources
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}- Database connectivity
- SQL query execution
- Result set processing
- Transaction management
- Prepared statements
See JDBCExample.java for complete example.
RMI enables distributed computing by allowing objects to invoke methods on remote objects.
RMI allows Java objects to call methods on objects running in different JVMs.
// Remote interface
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Calculator extends Remote {
int add(int a, int b) throws RemoteException;
}
// Remote implementation
import java.rmi.server.UnicastRemoteObject;
public class CalculatorImpl extends UnicastRemoteObject implements Calculator {
public CalculatorImpl() throws RemoteException {
super();
}
public int add(int a, int b) throws RemoteException {
return a + b;
}
}
// Server
Registry registry = LocateRegistry.createRegistry(1099);
Calculator calc = new CalculatorImpl();
registry.rebind("Calculator", calc);
// Client
Registry registry = LocateRegistry.getRegistry("localhost", 1099);
Calculator calc = (Calculator) registry.lookup("Calculator");
int result = calc.add(5, 3);- Remote method invocation
- Distributed computing
- Object serialization
- Registry for service lookup
See RMIExample.java for complete example.
Reflection allows runtime inspection and manipulation of classes, methods, and fields.
Reflection API provides the ability to examine and modify program structure at runtime.
import java.lang.reflect.*;
// Get class information
Class<?> clazz = String.class;
System.out.println("Class name: " + clazz.getName());
// Get methods
Method[] methods = clazz.getMethods();
for (Method method : methods) {
System.out.println("Method: " + method.getName());
}
// Get fields
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
System.out.println("Field: " + field.getName());
}
// Invoke method
Method method = clazz.getMethod("length");
String str = "Hello";
int length = (Integer) method.invoke(str);- Class inspection
- Method invocation
- Field access
- Constructor access
- Dynamic class loading
See ReflectionExample.java for complete example.
A: Classes defined within other classes:
- Member Inner Class: Defined at class level
- Local Inner Class: Defined within a method
- Anonymous Inner Class: Class without a name
- Can access outer class private members
A: Reusable Java components following conventions:
- No-argument constructor
- Getter/setter methods
- Serializable (optional)
- Property change support
A: Java Database Connectivity:
- Standard API for database access
- Driver-based architecture
- SQL query execution
- Result set processing
A: Remote Method Invocation:
- Distributed computing
- Remote method calls
- Object serialization
- Registry for service lookup
A: Runtime inspection and manipulation:
- Class information
- Method invocation
- Field access
- Dynamic class loading
Last Updated: 2025
Version: 1.0
This guide covers the features of Java 1.1, released on February 19, 1997.