0% found this document useful (0 votes)
7 views12 pages

Class XI CS Master Notes

The document provides comprehensive notes for Class XI Computer Science covering key topics such as number systems, Java programming, data types, operators, decision-making statements, loops, methods, classes, string manipulations, and arrays. Each chapter includes theory explanations, examples, common pitfalls, and practice questions to aid understanding. Additionally, it features a revision checklist and sample programs to prepare for exams.

Uploaded by

raiharshit314
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)
7 views12 pages

Class XI CS Master Notes

The document provides comprehensive notes for Class XI Computer Science covering key topics such as number systems, Java programming, data types, operators, decision-making statements, loops, methods, classes, string manipulations, and arrays. Each chapter includes theory explanations, examples, common pitfalls, and practice questions to aid understanding. Additionally, it features a revision checklist and sample programs to prepare for exams.

Uploaded by

raiharshit314
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
You are on page 1/ 12

Class XI Computer Science — Master Notes

(Half-Yearly Syllabus)
Complete, detailed notes for chapters covered until Half-Yearly. Each chapter includes:
• Thorough theory explanations • Important definitions & rules • Java syntax & common pitfalls • Multiple example
programs with explanations • Quick revision checklist and practice questions
Chapter 1 — Numbers (Number Systems & Representations)
Overview: Number systems are ways to represent numeric values. Important systems: Decimal (base 10),
Binary (base 2), Octal (base 8), Hexadecimal (base 16). Computers use binary internally.
Conversions:
1) Decimal to Binary: repeatedly divide by 2, record remainders (LSB → MSB). Example: 13 → 1101.
2) Binary to Decimal: sum each bit × 2^position. Example: 1101 = 1×2^3 + 1×2^2 + 0×2^1 + 1×2^0 =
8+4+0+1 = 13.
3) Binary ↔ Hex: group binary bits in sets of 4 (nibble) and map to hex digit. Example: 1101 -> D (hex).
Binary arithmetic: Addition rules (0+0=0, 0+1=1, 1+1=10 carry 1). Practice carries carefully. Subtraction
can be performed via two's complement.
Signed integer representations:
• Signed magnitude: MSB is sign (0=+,1=-); magnitude bits represent absolute value. Problem: two zeros
(+0 and -0).
• One's complement: invert all bits of magnitude for negative numbers (still has +0 and -0).
• Two's complement: invert bits and add 1. Advantages: single zero; arithmetic with same adder works for
signed numbers.
Example — Two's complement (8-bit): To represent -5: 5 = 00000101 → invert = 11111010 → add 1 =
11111011.
Floating point (overview): IEEE 754 represents real numbers with sign, exponent and mantissa. For
exams, understand concept, not full details.
Character encoding: ASCII: 7-bit (standard printable characters up to 127). Unicode: supports many
languages (UTF-8 is common encoding).
Common pitfalls: Mixing bases without converting, forgetting to handle carries, confusing bit positions
(LSB vs MSB).
Quick practice: Convert decimal 45 to binary and hex. Add binary 1011 + 1101. Represent -12 in 8-bit two's
complement.
Chapter 2 — Introduction to Java Language
What is Java? Java is an object-oriented, class-based, platform-independent language. Write once, run
anywhere (bytecode on JVM).
Key components: JDK (compiler + tools), JRE (runtime libraries + JVM), JVM (executes bytecode).
Java program structure: A Java program consists of classes. The entry point is the main method: public
static void main(String[] args).
// Hello world in Java
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

Important keywords: class, public, private, protected, static, final, new, this, return, void, if, else, for,
while, switch, case, break, continue, try, catch, throw.
Compilation & execution: javac HelloWorld.java → produces HelloWorld.class (bytecode). java
HelloWorld runs the class on JVM.
Object-oriented features: Encapsulation (data + methods), Inheritance (reuse code), Polymorphism
(method overriding/overloading), Abstraction (interfaces/abstract classes).
Common mistakes: Missing semicolons, wrong file/class name (public class must be in file with same
name), forgetting main signature, case-sensitivity (Java is case-sensitive).
Exam tip: Be able to read a small Java program and predict output, spot errors in syntax, and explain role of main,
class and objects.
Chapter 3 — Concept of Data Types
Primitive data types in Java (8): byte (8-bit), short (16-bit), int (32-bit), long (64-bit), float (32-bit,
decimal), double (64-bit), char (16-bit Unicode), boolean (true/false).
Ranges (important): int: approximately -2^31 to 2^31-1. long used for very large integers (suffix L for
literals: 123L). Float literals require f suffix: 3.14f.
Reference (non-primitive) types: String, Arrays, Classes, Interfaces. Stored as references (pointers) on
heap.
Type casting: Widening (implicit): smaller → larger (int → long). Narrowing (explicit): larger → smaller
must be cast (int x = (int) longVal).
Wrapper classes & autoboxing: int ↔ Integer, double ↔ Double. Java auto-converts between primitives
and wrappers in many contexts.
Constants: Use final keyword to create constants: final int MAX = 100;
Variable scope: Local variables (inside methods) vs instance variables (fields) vs static variables
(class-level). Always initialize variables before use (local vars are not default-initialized).
Example:
int a = 10;
long b = a; // widening
double d = 3.14;
int x = (int) d; // narrowing - fractional part lost

Common pitfalls: Overflow (e.g., int overflow), using float for precise money calculations (use BigDecimal in real
apps, but not required for exam).
Chapter 4 — Operators and Expressions
Categories: Arithmetic (+,-,*,/,%), Relational (<,>,<=,>=,==,!=), Logical (&&,||,!), Bitwise (&,|,^,~,<<,>>),
Assignment (=, +=, -= ...), Unary (++, --), Ternary (?:).
Operator precedence: Multiplicative (*,/,% ) > Additive (+,-) > Relational > Logical > Assignment. Use
parentheses to avoid ambiguity.
Short-circuit logical operators: && and || evaluate right-hand operand only if needed. Single & and |
always evaluate both operands (on booleans too).
Example expressions & pitfalls:
int a = 5, b = 2; int c = a / b; // c = 2 (integer division) → watch out for integer division losing fractional part.
Use double if needed.
int a = 5, b = 2;
double r = (double)a / b; // 2.5

Increment operators: Prefix ++x increments before use; Postfix x++ increments after use. Example: int
i=0; int a = i++; // a=0, i=1;
Ternary operator: condition ? expr1 : expr2 — compact if-else for expressions.
Practice: Evaluate expressions with mixed operators; rewrite complex expressions using parentheses to show order.
Chapter 5 — Decision Making Statements
if statement: if (condition) { // statements }
if-else: if (cond) { } else { } — choose between two paths.
Nested if: if inside another if. Keep indentation clear and consider else-if ladder for multiple checks.
switch-case: switch(variable) { case val: ... break; default: ... } — Use for discrete values (int, char, String
in Java 7+). Always use break unless fall-through intended.
// Grade example
int marks = 76;
if (marks >= 90) { System.out.println("A+"); }
else if (marks >= 75) { System.out.println("A"); }
else if (marks >= 60) { System.out.println("B"); }
else { System.out.println("C"); }

Best practices: Always include default in switch. Avoid deep nesting — prefer methods to split logic. Use
relational operators carefully with correct boundary conditions (>=, >).
Common exam tasks: Write a program to assign grades, check leap year, find max of three numbers using if-else or
switch.
Chapter 6 — Iteration Through Loops
for loop: for(initialization; condition; update) { body } — best when number of iterations known.
while loop: while(condition) { body } — condition checked before each iteration.
do-while loop: do { body } while(condition); — runs body at least once.
Nested loops: loops inside loops (common in 2D arrays and patterns).
break & continue: break exits the nearest loop; continue skips current iteration and proceeds with next
one.
// print first 5 natural numbers
for (int i = 1; i <= 5; i++) {
System.out.println(i);
}

Common problems: Off-by-one errors (use <= vs <), infinite loops (wrong update or condition), modifying
loop variable inside body unpredictably.
Practice: Write loops for factorial, Fibonacci sequence, pattern printing (triangles), sum of digits, reverse number.
Chapter 7 — Methods (Functions)
Definition: A method is a named block of code that performs a task. Syntax: returnType
name(parameter-list) { body }
Types: void methods (no return), value-returning methods (int, double, etc.).
Parameters & arguments: Methods receive data via parameters; Java is pass-by-value (copies of values
are passed). For objects, copies of references are passed (so object fields can be modified inside
method).
Method overloading: Same method name, different parameter lists. Java selects best match at compile
time.
// Example of methods and overloading
public class Demo {
static int add(int a, int b) { return a + b; }
static double add(double a, double b) { return a + b; }
public static void main(String[] args) {
System.out.println(add(2,3)); // 5
System.out.println(add(2.5, 3.1)); // 5.6
}
}

Return statement: Used to return a value. For void methods, return; can be used to exit early.
Exam tip: Be able to write modular code by breaking tasks into methods; explain parameter passing and show
overloading examples.
Chapter 8 — Classes and Constructors
Class: Blueprint for objects. Contains fields (attributes) and methods (behaviour).
Object: Instance created with new: ClassName obj = new ClassName();
Constructor: Special method with same name as class, no return type, used to initialize objects. Default
constructor provided if none defined.
Types of constructors: Default (no-arg) constructor, parameterized constructor, copy constructor (not
built-in; implemented by programmer).
// Simple class with constructor
class Student {
String name;
int roll;
Student(String name, int roll) {
this.name = name;
this.roll = roll;
}
void display() {
System.out.println(name + " - " + roll);
}
}
class Test {
public static void main(String[] args) {
Student s = new Student("Rahul", 21);
s.display(); // Rahul - 21
}
}

this keyword: Refers to current object; used to resolve name conflicts and to call other constructors
(this(...)).
Encapsulation: Keep fields private and provide public getter/setter methods. This controls access to
internal state.
Practice: Create classes for Book, Rectangle (with methods area(), perimeter()), and show constructors and method
calls.
Chapter 9 — Character Handling & String Manipulations
char type: 16-bit Unicode character. Use single quotes e.g. 'A'.
Character class methods: Character.isDigit(c), Character.isLetter(c), Character.toUpperCase(c),
Character.toLowerCase(c).
String class: Immutable sequence of characters. Methods do not modify original string but return new
ones.
Important String methods: length(), charAt(i), substring(a,b), indexOf(str), lastIndexOf, equals(),
equalsIgnoreCase(), compareTo(), concat(), trim(), replace().
// Common string tasks
String s = "Hello World";
int len = s.length(); // 11
char ch = s.charAt(0); // 'H'
String sub = s.substring(0,5); // "Hello"
boolean eq = s.equals("hello"); // false

StringBuilder: Mutable sequence for efficient modifications (append, insert, delete). Use when doing
many modifications.
Common programs: reverse a string, check palindrome, count vowels/consonants/digits, split words, find
occurrences of a substring.
// Reverse using StringBuilder
String s = "abcd";
StringBuilder sb = new StringBuilder(s);
sb.reverse();
System.out.println(sb.toString()); // "dcba"

Practice: Implement reverse, palindrome check, and frequency count without using libraries (use loops and arrays).
Chapter 10 — Arrays (1D and 2D)
Overview: Arrays store multiple elements of same type in contiguous memory. Indexing starts at 0. Arrays
have fixed size once created.
1D arrays: Declaration: int[] arr = new int[5]; or int[] arr = {1,2,3}; Traversal via loops. Common tasks: sum,
max/min, average, linear search, bubble sort.
// Sum of elements in array
int[] arr = {2,4,6,8};
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
}

2D arrays (matrix): int[][] mat = new int[3][3]; Access: mat[i][j]. Use nested loops for traversal. Common
tasks: matrix addition, multiplication (careful with indices), transpose.
// Matrix addition
int[][] A = {{1,2},{3,4}};
int[][] B = {{5,6},{7,8}};
int[][] C = new int[2][2];
for (int i=0;i<2;i++){
for(int j=0;j<2;j++){
C[i][j] = A[i][j] + B[i][j];
}
}

Common pitfalls: ArrayIndexOutOfBoundsException when index <0 or >= length; confusion between
rows and columns; forgetting that length is property (arr.length) and not method.
Practice: Implement binary search (sorted array), bubble sort, find second largest element, rotate array by k, and
matrix transpose.
Appendix — Sample Programs & Exam Checklist
Must-know short programs (implement & understand):

Program Core idea / code snippet


Factorial (using loop & recursion) int factorial(int n) { int f=1; for(int i=2;i<=n;i++) f*=i; return f; }
Fibonacci (iterative) int a=0,b=1; for(int i=1;i<=n;i++){ int c=a+b; a=b; b=c; }
Reverse string StringBuilder sb = new StringBuilder(s); sb.reverse();
Array sum & max for loop to compute sum and track max value
Matrix addition nested loops adding corresponding cells
Class with constructor class X{ int v; X(int v){ this.v=v;} }

Revision checklist (quick):


• Be able to convert between number systems and represent negative numbers in two's complement. •
Know Java program structure, main method, compilation/execution steps. • Memorize primitive data types
and ranges (at least know which to use). • Understand operator precedence, integer division quirks, and
use parentheses when needed. • Practice if-else and switch for decision tasks; avoid missing break in
switch. • Write loops carefully; watch off-by-one and infinite loops. • Use methods to modularize code and
understand call-by-value nature. • Create classes with constructors and use 'this' properly. • Master String
methods and when to use StringBuilder. • Implement array algorithms: sum, max, sort, search, matrix ops.
Last-minute exam tips: Read questions carefully, draw sample input-steps for programs, dry-run loops
on paper for small inputs, keep code modular, and write comments to make your logic clear to examiner.

You might also like