Class 12 – Java Programming (IT 802) Board Notes
Detailed Theory Notes and Important Programs
Language: English
PART A – Detailed Theory Notes
BASIC QUESTIONS
1. What is Java?
Java is a high-level, object-oriented, platform-independent programming language developed by
Sun Microsystems. It allows developers to write code once and run it anywhere using the Java
Virtual Machine (JVM).
2. Write any five features of Java.
1. Object-Oriented 2. Platform Independent 3. Simple & Secure 4. Robust 5. Multithreaded.
3. What is JVM, JRE, and JDK?
JVM executes bytecode; JRE provides the runtime environment; JDK includes JRE and tools for
development.
4. Difference between compiler and interpreter.
Compiler translates entire source code into machine code at once, while interpreter translates line
by line.
5. What is platform independence in Java?
It means Java programs can run on any OS because compiled code (bytecode) is executed by JVM
on all platforms.
6. What is bytecode?
An intermediate platform-independent code generated after compilation, executed by JVM.
7. Variables and data types.
A variable stores data. Data types define the type of data. Primitive types include int, char, boolean;
Non-primitive types include String, Array, Class.
8. Primitive vs Non-Primitive data types.
Primitive types are predefined (int, float), Non-Primitive are created by users (String, Arrays).
9. Operators in Java.
Operators perform operations: Arithmetic (+,-,*), Relational (<,==), Logical (&&,||), Assignment
(=,+=), Increment (++), Conditional (?:).
10. Identifier and Literals.
Identifiers are variable/method names. Literals are constant fixed values like 10, 'A', "Hello".
CONTROL STATEMENTS
1. Conditional Statements.
Control flow using if, if-else, nested if, and switch statements.
2. Example of if, if-else, and nested if.
if(marks>=40) System.out.println('Pass'); else System.out.println('Fail'); Nested if checks multiple
conditions inside another if.
3. Switch statement syntax.
switch(choice){ case 1: System.out.println('One'); break; default: System.out.println('Invalid'); }
4. Loops in Java.
Used to repeat code. for, while (entry-controlled), and do-while (exit-controlled) loops.
5. Difference between break and continue.
break exits loop completely; continue skips current iteration.
6. Entry vs Exit controlled loops.
Entry-controlled: condition checked before (for, while). Exit-controlled: condition checked after
execution (do-while).
ARRAYS AND STRINGS
1. What is an Array?
Collection of same data type elements stored sequentially. Example: int arr[]={1,2,3};
2. Declaration and Initialization.
int arr[]=new int[5]; or int arr[]={10,20,30};
3. Difference between 1D and 2D Arrays.
1D stores linear elements. 2D stores in rows and columns. Example: int a[][]={{1,2},{3,4}};
4. What is a String?
Sequence of characters enclosed in double quotes. String s='Java'; Strings are immutable objects
of String class.
5. String vs StringBuffer.
String is immutable; StringBuffer is mutable and faster for repeated changes.
6. Two methods of String class.
length() – returns length; toUpperCase() – converts to uppercase.
FUNCTIONS / METHODS
1. What is a Method?
A reusable block of code that performs a specific task. Example: int add(int a,int b){return a+b;}
2. Call by Value vs Reference.
Call by value copies data, changes don't affect original; call by reference passes address, changes
affect original.
3. Method Overloading.
Multiple methods with same name but different parameters. Example: int add(int a,int b), int add(int
a,int b,int c).
4. Use of return statement.
Returns a value to the calling method. Example: return sum;
5. Recursion.
When a method calls itself. Example: factorial function calls itself until n==1.
CLASSES AND OBJECTS
1. What is a Class?
A blueprint containing variables and methods to define an object.
2. What is an Object?
An instance of a class that holds actual values. Example: Student s1 = new Student();
3. Class vs Object.
Class = blueprint, Object = instance. Class is logical, Object is physical entity.
4. Constructor in Java.
A special method called automatically when an object is created; initializes data members.
5. Types of Constructors.
Default (no parameters) and Parameterized (accepts arguments).
6. Constructor vs Method.
Constructor auto-calls, no return; Method explicitly called, can return value.
7. this keyword.
Refers to current object; used to distinguish between instance variables and parameters.
8. static keyword.
Used for class-level members shared by all objects.
9. Encapsulation.
Binding of data and methods; uses private variables and public getters/setters.
10. Inheritance.
Acquiring properties from another class using 'extends' keyword.
11. Polymorphism.
One method behaves differently in different contexts (overloading and overriding).
12. Abstraction.
Hiding implementation using abstract classes or interfaces.
13. Interface.
Collection of abstract methods; supports multiple inheritance.
14. Access Modifiers.
public, private, protected, default – control scope.
15. OOP Principles.
Encapsulation, Inheritance, Polymorphism, and Abstraction.
PART B – Important Java Programs
1. Factorial of a Number
class Factorial { public static void main(String args[]) { int n=5, fact=1; for(int i=1;i<=n;i++) fact*=i;
System.out.println('Factorial: '+fact); } }
2. Fibonacci Series
class Fibonacci { public static void main(String args[]) { int a=0,b=1,c,n=10; System.out.print(a+'
'+b); for(int i=2;i
3. Sum of Digits
class SumDigits { public static void main(String args[]) { int n=123, sum=0; while(n>0) {
sum+=n%10; n/=10; } System.out.println('Sum: '+sum); } }
4. Palindrome Number
class Palindrome { public static void main(String args[]) { int n=121, r, rev=0, temp=n; while(n>0){
r=n%10; rev=rev*10+r; n/=10; } if(temp==rev) System.out.println('Palindrome'); else
System.out.println('Not Palindrome'); } }
5. Reverse a Number
class Reverse { public static void main(String args[]) { int n=1234, rev=0; while(n>0){
rev=rev*10+(n%10); n/=10; } System.out.println('Reverse: '+rev); } }
6. Swapping Two Numbers
class Swap { public static void main(String args[]) { int a=5,b=10,temp; temp=a; a=b; b=temp;
System.out.println('a='+a+' b='+b); } }
7. Largest of Three Numbers
class Largest { public static void main(String args[]) { int a=10,b=20,c=15; if(a>=b && a>=c)
System.out.println(a); else if(b>=a && b>=c) System.out.println(b); else System.out.println(c); } }
8. Simple Interest
class SimpleInterest { public static void main(String args[]) { double p=1000,r=5,t=2,si;
si=(p*r*t)/100; System.out.println('Simple Interest: '+si); } }
9. Prime Number Check
class PrimeCheck { public static void main(String args[]) { int n=7,flag=0; for(int i=2;i<=n/2;i++)
if(n%i==0){flag=1;break;} if(flag==0) System.out.println('Prime'); else System.out.println('Not
Prime'); } }
10. Even or Odd
class EvenOdd { public static void main(String args[]) { int n=7; if(n%2==0)
System.out.println('Even'); else System.out.println('Odd'); } }