Here is a short and clear explanation of each Java concept you mentioned:
1. Difference between Class and Object
Class: A blueprint or template (e.g., Car).
Object: An instance of a class (e.g., Car myCar = new Car();).
2. Encapsulation
Binding data (variables) and methods in one unit (class).
class Student {
private int age; // private data
public void setAge(int a) { age = a; }
public int getAge() { return age; }
}
3. Inheritance
One class inherits features of another.
Types:
o Single
o Multilevel
o Hierarchical
o Hybrid (via interfaces)
4. Polymorphism
One task, many forms.
Method Overloading: Same method name, different parameters.
class Add {
int sum(int a, int b) { return a + b; }
int sum(int a, int b, int c) { return a + b + c; }
}
5. Abstraction
Hiding internal details, showing only functionality.
abstract class Shape {
abstract void draw();
}
class Circle extends Shape {
void draw() { [Link]("Drawing Circle"); }
}
6. Access Modifiers
Modifier Class Package Subclass World
private ✔ ✘ ✘ ✘
default ✔ ✔ ✘ ✘
protected ✔ ✔ ✔ ✘
public ✔ ✔ ✔ ✔
7. Abstract Class vs Interface
Abstract Class: Can have method implementations.
Interface: Only method declarations (Java 8+ allows default methods).
abstract class Animal {
abstract void sound();
}
interface Flyable {
void fly();
}
8. == vs .equals()
==: Compares references (memory addresses).
.equals(): Compares content (values).
9. Method Overloading Example
class Print {
void show(int a) { [Link](a); }
void show(String s) { [Link](s); }
}
10. Abstract Class Use Case
When you want to define a common base with shared code and abstract methods.
abstract class Vehicle {
abstract void start();
}
11. Inheritance Example
class Animal {
void sound() { [Link]("Animal sound"); }
}
class Dog extends Animal {
void bark() { [Link]("Dog barks"); }
}
Let me know if you'd like this as a PDF or formatted notes for study!
5 marks
Here is a detailed explanation for each Java topic, including theoretical concepts and sample
programs where required:
1. Main Features of Java
Platform Independent (via JVM)
Object-Oriented
Simple and Secure
Robust and Portable
Multithreaded
Architecture Neutral
High Performance
Dynamic
2. Object-Oriented Programming in Java
Java follows OOP principles:
Class & Object
Encapsulation (data hiding)
Inheritance (code reuse)
Polymorphism (method behavior change)
Abstraction (hiding complexity)
3. Difference: JDK vs JRE vs JVM
Component Description
JVM Java Virtual Machine, runs bytecode
JRE Java Runtime Environment (JVM + libraries)
JDK Java Development Kit (JRE + development tools)
4. Constructor in Java
Special method called when object is created.
class Student {
String name;
Student(String n) { name = n; }
}
5. Method Overloading vs Method Overriding
Feature Overloading Overriding
Class Same class Subclass
Parameters Must differ Must be same
Runtime Compile-time Runtime
6. Use of static Keyword
Belongs to the class, not instance.
class Example {
static int count = 0;
}
7. Inheritance Example
class Animal {
void sound() { [Link]("Animal sound"); }
}
class Dog extends Animal {
void bark() { [Link]("Dog barks"); }
}
8. Interface in Java
A reference type with abstract methods (no body).
interface Drawable {
void draw();
}
class Circle implements Drawable {
public void draw() { [Link]("Drawing Circle"); }
}
9. Use of final Keyword
final variable: constant value.
final method: cannot be overridden.
final class: cannot be extended.
10. Java Program to Check Prime Number
import [Link];
public class PrimeCheck {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int num = [Link]();
boolean isPrime = true;
for(int i = 2; i <= num/2; i++) {
if(num % i == 0) {
isPrime = false; break;
}
}
[Link](isPrime ? "Prime" : "Not Prime");
}
}
11. Access Modifiers in Java
Modifier Scope
private Class only
(default) Package
protected Package + subclass
public Everywhere
12. Reverse a String in Java
import [Link];
public class ReverseString {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String input = [Link]();
String reversed = new StringBuilder(input).reverse().toString();
[Link]("Reversed: " + reversed);
}
}
13. Java Switch-based Calculator
import [Link];
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter two numbers:");
double a = [Link](), b = [Link]();
[Link]("Enter operator (+, -, *, /):");
char op = [Link]().charAt(0);
switch(op) {
case '+': [Link](a + b); break;
case '-': [Link](a - b); break;
case '*': [Link](a * b); break;
case '/': [Link](a / b); break;
default: [Link]("Invalid operator");
}
}
}
14. Count Vowels and Consonants
import [Link];
public class VowelConsonantCount {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String input = [Link]().toLowerCase();
int vowels = 0, consonants = 0;
for(char c : [Link]()) {
if([Link](c)) {
if("aeiou".indexOf(c) != -1) vowels++;
else consonants++;
}
}
[Link]("Vowels: " + vowels + ", Consonants: " +
consonants);
}
}
15. Copy One Array to Another
public class ArrayCopy {
public static void main(String[] args) {
int[] original = {1, 2, 3, 4};
int[] copy = new int[[Link]];
for(int i = 0; i < [Link]; i++) {
copy[i] = original[i];
}
for(int val : copy) [Link](val + " ");
}
}
16. Student Info Entry System for Presidency University
import [Link];
public class StudentInfo {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter name: ");
String name = [Link]();
[Link]("Enter course: ");
String course = [Link]();
[Link]("Enter gender: ");
String gender = [Link]();
[Link]("Enter age: ");
int age = [Link]();
[Link]("Enter total fees: ");
double fees = [Link]();
[Link]("Fees paid (true/false): ");
boolean paid = [Link]();
[Link]("\n--- Student Information ---");
[Link]("Name: " + name);
[Link]("Course: " + course);
[Link]("Gender: " + gender);
[Link]("Age: " + age);
[Link]("Total Fees: ₹" + fees);
[Link]("Fees Paid: " + (paid ? "Yes" : "No"));
}
}
Let me know if you'd like all this compiled into a PDF file, notes format, or if you want
explanations in Hindi as well.