JETS | IB - Wyatt's Notes
Java Examination Tool Sebset (JETS)
Section titled “Java Examination Tool Sebset (JETS)”The IB does not expect a specific standard of Java to be taught but a subset of Java called JETS for Students to present OOP concepts
Intuition
Section titled “Intuition”OOP is like building with LEGO — objects are modular, reusable blocks that can be combined to create complex systems: Encapsulation, inheritance, and polymorphism allow programmers to model real-world entities and relationships in code
Why it matters: OOP is the dominant paradigm for building large, maintainable software systems
The key insight: Encapsulation, inheritance, and polymorphism allow programmers to model real-world entities and relationships in code
Conventions
Section titled “Conventions”Styles
Section titled “Styles”| Token | Conventions |
|---|---|
| Classes identifier | CapitalCamelCase |
| Variable identifier | camelCase |
| Method identifier | camelCase |
| Constant identifier | UPPER_CASE |
Ordering
Section titled “Ordering”- Main class should be placed at the top
- Constructors should be place as the first method
Operators Permitted
Section titled “Operators Permitted”- Arithmetic
+-*/%- Relational
==!=><$\ge$$\le$- Boolean
!&&||
Primitive Data Types
Section titled “Primitive Data Types”Primitive data types are data types other data types are constructed with, these are normally Built-in as standard data types of programming languages, in JETS, these are: | type declaration | Size | range | Standard | Default init value | | :---------------- | :---------------------------------------: | :--------------------------------------------------: | :------------------------------------------------------: | :------------------: | | byte | 8 bits | | signed | 0 | | int | 32 bits | | signed | 0 | | long | 64 bits | | signed | 0 | | double | 64 bits | | IEEE 754-1984 (double precision binary Floating-point) | 0.0d | | char | 16 bits | | UTF-16 | "\u0000' 'a' | | boolean | 1 bit (logical) 1 byte (in-practice) | false |
byte b = 120 // byte is an 8-bit signed type with range -128 to 127int i = 1243 // int is a 32-bit signed type with range -2^31 to 2^31-1longdoublecharbooleanScopes
Section titled “Scopes”Attribute Scopes
Section titled “Attribute Scopes”Java access modifiers used in JETS are:
class ClassIdentifier{ public int n1 = 0; //Accessible by any class protected int n2 = 0; //Accessible by any extended class private int n3 = 0; //Only accessible by the class}Type Casting
Section titled “Type Casting”Type casting refers to the converting of value to another type:
int n1 = (int)9.8 //9double n2 = (double)6 //6.0fbyte n3 = (byte)1000 //Signed integer truncated to 8 bits: 1000%256-256 = -24char n4 = (char)75 //K, from ascii mappingError Handling
Section titled “Error Handling”Error handling refers to the handling of exceptions for functions that:
type funcIdentifier () throws IOExceptiontry{ /*commands*/ } catch(Exception e){ /*Error condition handle*/ }Object-Oriented Programming Principles
Section titled “Object-Oriented Programming Principles”OOP is a programming paradigm that organises code around objects, which are instances of classes. JETS is designed to demonstrate these core principles.
Encapsulation
Section titled “Encapsulation”Encapsulation is the bundling of data (attributes) and methods that operate on that data within a Single unit (class), while restricting direct access to some of the object’s components.
- Private attributes can only be accessed through public methods (getters and setters).
- This protects the internal state of an object from unauthorised or accidental modification.
class Student { private String name; private int grade;
public Student(String name, int grade) { this.name = name; this.grade = grade; }
// Getter public String getName() { return this.name; }
// Setter with validation public void setGrade(int grade) { if (grade >= 0 && grade <= 100) { this.grade = grade; } }
public int getGrade() { return this.grade; }}Exam tip: In IB exams, encapsulation questions often ask you to identify whether attributes Should be private and explain why. Always justify with data protection/validation.
Inheritance
Section titled “Inheritance”Inheritance allows a class (subclass/child) to inherit attributes and methods from another class (superclass/parent). This promotes code reuse and establishes an “is-a” relationship.
class Animal { private String name;
public Animal(String name) { this.name = name; }
public String getName() { return this.name; }
public void speak() { // General behaviour }}
class Dog extends Animal { private String breed;
public Dog(String name, String breed) { super(name); // Call parent constructor this.breed = breed; }
// Overriding the speak method public void speak() { System.out.println("Woof"); }
public String getBreed() { return this.breed; }}Key concepts:
extendskeyword creates the inheritance relationship.super()calls the parent class constructor.- The subclass inherits all
publicandprotectedmembers of the superclass. privatemembers are not directly accessible but can be accessed through inherited public methods.
Polymorphism
Section titled “Polymorphism”Polymorphism means “many forms.” It allows objects of different classes to be treated through a Common interface.
Method overriding: A subclass provides a specific implementation of a method already defined in Its superclass.
class Shape { public double area() { return 0; }}
class Circle extends Shape { private double radius;
public Circle(double radius) { this.radius = radius; }
public double area() { return 3.14159 * this.radius * this.radius; }}
class Rectangle extends Shape { private double width; private double height;
public Rectangle(double width, double height) { this.width = width; this.height = height; }
public double area() { return this.width * this.height; }}Method overloading: Multiple methods with the same name but different parameter lists within the Same class.
class Calculator { public int add(int a, int b) { return a + b; }
public double add(double a, double b) { return a + b; }
public int add(int a, int b, int c) { return a + b + c; }}Abstraction
Section titled “Abstraction”Abstraction hides complex implementation details and shows only the essential features of an object. In JETS, this is achieved through abstract classes and interfaces.
abstract class Vehicle { private String type;
public Vehicle(String type) { this.type = type; }
// Abstract method — no implementation public abstract void move();
public String getType() { return this.type; }}
class Car extends Vehicle { public Car() { super("Car"); }
public void move() { System.out.println("Driving on road"); }}UML Class Diagrams
Section titled “UML Class Diagrams”UML (Unified Modelling Language) class diagrams are a standard way to represent the structure of OOP Programs. IB exams frequently include UML diagrams and ask you to interpret or construct them.
Key UML Notation
Section titled “Key UML Notation”| Element | Symbol | Meaning |
|---|---|---|
| Class | Rectangle with three sections | Class name, attributes, methods |
- (private) | Minus sign before attribute/method | Only accessible within the class |
+ (public) | Plus sign before attribute/method | Accessible from any class |
# (protected) | Hash sign before attribute/method | Accessible within the class and subclasses |
| Inheritance | Solid line with hollow arrow pointing to parent | ”Is-a” relationship |
| Association | Solid line with arrow | ”Has-a” relationship |
| Aggregation | Solid line with hollow diamond | ”Has-a” (weak ownership) |
| Composition | Solid line with filled diamond | ”Has-a” (strong ownership) |
Example UML Diagram (Text Representation)
Section titled “Example UML Diagram (Text Representation)”+------------------+| Animal |+------------------+| - name: String |+------------------+| + getName(): Str || + speak(): void |+------------------+ ^ | (extends) |+------------------+| Dog |+------------------+| - breed: String |+------------------+| + speak(): void || + getBreed(): Str|+------------------+Design Patterns (IB Context)
Section titled “Design Patterns (IB Context)”Design patterns are reusable solutions to common programming problems. While the IB does not require Deep knowledge of design patterns, understanding these concepts helps with exam questions.
Singleton Pattern
Section titled “Singleton Pattern”Ensures a class has only one instance and provides a global point of access to it.
class DatabaseConnection { private static DatabaseConnection instance; private String status;
private DatabaseConnection() { this.status = "Connected"; }
public static DatabaseConnection getInstance() { if (instance == null) { instance = new DatabaseConnection(); } return instance; }
public String getStatus() { return this.status; }}Observer Pattern
Section titled “Observer Pattern”A one-to-many dependency: when one object (subject) changes state, all its dependents (observers) Are notified and updated automatically. This is relevant to event-driven programming in the IB Syllabus.
Collections and Data Structures in JETS
Section titled “Collections and Data Structures in JETS”Arrays
Section titled “Arrays”int[] numbers = new int[5]; // Declare array of 5 integersint[] values = {1, 2, 3, 4, 5}; // Initialise with valuesArrayList (Dynamic Arrays)
Section titled “ArrayList (Dynamic Arrays)”ArrayList is not part of the basic JETS subset but appears in IB exam questions:
import java.util.ArrayList;
ArrayList<String> names = new ArrayList<String>();names.add("Alice");names.add("Bob");String first = names.get(0); // "Alice"int size = names.size(); // 2names.remove(0); // Removes "Alice"Two-Dimensional Arrays
Section titled “Two-Dimensional Arrays”int[][] matrix = new int[3][3];matrix[0][0] = 1;matrix[1][2] = 5;
// Iterating through a 2D arrayfor (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { System.out.println(matrix[i][j]); }}Control Structures
Section titled “Control Structures”Conditional Statements
Section titled “Conditional Statements”int score = 85;
if (score >= 90) { System.out.println("Grade A");} else if (score >= 80) { System.out.println("Grade B");} else if (score >= 70) { System.out.println("Grade C");} else { System.out.println("Grade D");}// For loopfor (int i = 0; i < 10; i++) { System.out.println(i);}
// While loopint count = 0;while (count < 10) { System.out.println(count); count++;}
// Enhanced for loop (for-each)int[] numbers = {1, 2, 3, 4, 5};for (int num : numbers) { System.out.println(num);}Searching and Sorting Algorithms
Section titled “Searching and Sorting Algorithms”Linear Search
Section titled “Linear Search”Checks each element sequentially until the target is found.
int linearSearch(int[] arr, int target) { for (int i = 0; i < arr.length; i++) { if (arr[i] == target) { return i; } } return -1; // Not found}- Time complexity: — worst case checks every element.
- Best for: Small or unsorted arrays.
Binary Search
Section titled “Binary Search”Divides a sorted array in half repeatedly to find the target. The array must be sorted.
int binarySearch(int[] arr, int target) { int low = 0; int high = arr.length - 1;
while (low <= high) { int mid = (low + high) / 2; if (arr[mid] == target) { return mid; } else if (arr[mid] < target) { low = mid + 1; } else { high = mid - 1; } } return -1; // Not found}- Time complexity: — much faster for large sorted arrays.
- Best for: Large, sorted arrays.
Bubble Sort
Section titled “Bubble Sort”Repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the Wrong order.
void bubbleSort(int[] arr) { int n = arr.length; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { // Swap int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } }}- Time complexity: — slow for large arrays.
- Space complexity: — sorts in place.
Selection Sort
Section titled “Selection Sort”Finds the minimum element from the unsorted part and places it at the beginning.
void selectionSort(int[] arr) { int n = arr.length; for (int i = 0; i < n - 1; i++) { int minIdx = i; for (int j = i + 1; j < n; j++) { if (arr[j] < arr[minIdx]) { minIdx = j; } } // Swap int temp = arr[minIdx]; arr[minIdx] = arr[i]; arr[i] = temp; }}IB Exam Tips for JETS
Section titled “IB Exam Tips for JETS”Know the access modifiers: Understand when to use
public``privateAndprotected. Most attributes should beprivate; most methods should bepublic.Constructors come first: In JETS convention, constructors are placed as the first method in a class.
Use
thiskeyword: When a parameter has the same name as an attribute, usethis.attributeto distinguish them.Read UML diagrams carefully: Identify the attributes (with types and access modifiers), methods, and relationships between classes.
Practise tracing code: IB exams often include code tracing questions where you must determine the output of a given program. Step through the code line by line.
Understand polymorphism: Be prepared to explain how method overriding works and why it is useful.
Be careful with array indices: Arrays in Java are zero-indexed.
arr.lengthgives the number of elements, but the last valid index isarr.length - 1.
Common Pitfalls
Section titled “Common Pitfalls”Forgetting edge cases in algorithm design (e.g., empty input, single element, already sorted data).
Confusing authentication (who you are) with authorisation (what you can do) in security contexts.
Confusing an algorithm with a program. An algorithm is a step-by-step procedure, not its implementation in code.
Mixing up Big O, Big , and Big notation. Big O is an upper bound, not necessarily tight.
Cross-References
Section titled “Cross-References”| Topic | Site | Link |
|---|---|---|
| [Object-Oriented Programming] | A-Level | View |
| [Object-Oriented Programming] | IB | View |
flowchart TD
A[1_Object Oriented Programming] --> B[Key Concepts]
A --> C[Core Principles]
A --> D[Practical Applications]
B --> E[Fundamental definitions]
C --> F[Design patterns]
D --> G[Real-world usage]Summary
Section titled “Summary”The key principles covered in this topic are linked in the sub-pages above. Focus on understanding the definitions, applying the formulas or frameworks, and evaluating strengths and limitations of each approach.
Worked Examples
Section titled “Worked Examples”Worked examples demonstrating the application of key concepts are covered in the detailed sub-pages linked above.