WEEK 1 CP213

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/77

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

78 Terms

1
New cards
OOP idea
Program is a set of objects that act & interact like real-world things.
2
New cards
Object Contains
Data (fields) + methods (actions).
3
New cards
Class
Blueprint for objects, objects share the same methods, can have different data values.
4
New cards
Main program
Class with a main() method (entry point) = public static void main(String[] args).
5
New cards
Benefits of OOP
Readable, Maintainable, Reusable, Team-friendly - divide work by class; Fewer errors.
6
New cards
Encapsulation
Bundles data + methods into a class; use private for data (inside the class access only - hidden), public for access → protects integrity & modification.
7
New cards
Inheritance
One class (subclass/child) can reuse and extend another (superclass/parent). Subclass inherits fields + methods from the superclass automatically; can also add new features or override existing methods.
8
New cards
Polymorphism
Same method or object behaves differently depending on its type. Achieved through method overriding — subclass changes how a superclass method works.
9
New cards
Abstraction
Show essential features (what obj does not how), hides details; use abstract classes/interfaces → simpler, modular design.
10
New cards
Objects
Share structure/methods, but have their own data.
11
New cards
Java Origin
Created by James Gosling & team, 1991, Sun Microsystems → Oracle.
12
New cards
Java Goal
Run programs on different processors.
13
New cards
Java Bytecode
Intermediate form compiled from programs; runs on the Java Virtual Machine (JVM) → portable across all systems.
14
New cards
Java Applets
Small programs for browsers or applet viewer; graphical interface.
15
New cards
System.out
An object that sends output to the screen.
16
New cards
println()
A method that prints text to the screen.
17
New cards
Method call syntax
object.methodName(arguments); where object = who performs the action, methodName = what action to perform, arguments = info sent to the method (optional).
18
New cards
Variable Declaration Syntax
type variableName;
19
New cards
Assignment
Assigns a value to a variable using =; for example, ans = 2 + 2; // ans now holds 4.
20
New cards
+ Operator (Numbers)
Performs addition → 3 + 5 → 8.
21
New cards
+ Operator (Strings)
Performs concatenation → 'Hi' + ' there' → 'Hi there'.
22
New cards
High-level language
Human-readable (like Java). Must be translated to run.
23
New cards
Low-level language / Machine code
Directly understood by the computer.
24
New cards
Compiler
Converts high-level → low-level. This process = compiling.
25
New cards
Java's Execution Model
Java compiles to bytecode (universal for JVM).
26
New cards
Interpreter
Executes bytecode line by line.
27
New cards
JIT (Just-In-Time Compiler)
Converts frequently-used bytecode into machine code while running, improving speed.
28
New cards
Source code
Written by you (input to compiler).
29
New cards
Object code
Compiled version (bytecode in Java).
30
New cards
JVM
Runs bytecode.
31
New cards
Class Loader
Loads bytecode of needed classes (like a linker in other languages).
32
New cards
Compiling
javac FirstProgram.java creates FirstProgram.class (bytecode file).
33
New cards
Running
java FirstProgram. Don't include .java or .class, only run the class with a main() method.
34
New cards
Syntax
Structure / grammar (rules).
35
New cards
Semantics
Meaning / logic of code.
36
New cards
Syntax error
Example: Missing ;.
37
New cards
Semantic error
Example: 5 / 0 (invalid operation).
38
New cards
Syntax error (Type)
Detected at compile-time, e.g., Missing ;, misspelled keyword.
39
New cards
Run-time error (Type)
Detected during execution, e.g., Division by 0.
40
New cards
Logic error (Type)
Detected after execution, e.g., Wrong output, bad formula.
41
New cards
Identifiers
Names for variables, methods, classes, etc.
42
New cards
Naming Convention for Variable / Method
Start lowercase, use camelCase, e.g., firstName, totalScore.
43
New cards
Naming Convention for Class
Start Uppercase, e.g., StudentRecord.
44
New cards
Naming Convention for Constant
ALL_CAPS, underscores, e.g., MAX_USERS.
45
New cards
Variables
Must declare before use; tells the compiler the data type.
46
New cards
Assignment Statements
Purpose: Assign/change variable values. Structure: variable = expression;.
47
New cards
Chained assignments
a = b = c = 10.
48
New cards
Uninitialized variables
May cause errors if used. Best practice: Initialize explicitly, e.g., int num = 0.
49
New cards
Shorthand Assignment
Combines arithmetic with = for concise updates.
50
New cards
Form
variable Op= expression; → variable = variable Op expression
51
New cards
Assignment Compatibility
Type mismatch: Value of one type usually cannot be stored in a variable of another type.
52
New cards
Widening
Allowed: Smaller → larger type automatically.
53
New cards
Hierarchy
byte → short → int → long → float → double
54
New cards
Narrowing
Requires explicit cast.
55
New cards
Boolean
Cannot mix with numeric types.
56
New cards
Arithmetic Operators
Operators: + (add), - (subtract), * (multiply), / (divide), % (modulo).
57
New cards
Type rules
int + int → int
58
New cards
Mixed types
Result is widest type.
59
New cards
Brackets
Parentheses clarify order; recommended to avoid ambiguity.
60
New cards
Operator precedence
Determines evaluation order when no parentheses.
61
New cards
Associativity
Resolves operations of equal precedence.
62
New cards
Floating-point numbers
Are approximate.
63
New cards
Division
If any operand is floating-point → result is floating-point.
64
New cards
Modulo %
Remainder.
65
New cards
Type conversion
Widening (int → double) automatic.
66
New cards
Increment/Decrement
++ adds 1, -- subtracts 1.
67
New cards
String
No primitive type; handled by String class.
68
New cards
String object
Sequence of characters in double quotes ("Hello").
69
New cards
Concatenation
+ joins strings; combining with other types converts them to string.
70
New cards
String Methods
Actions objects can perform; shared by all objects of the same class.
71
New cards
.length()
Returns string length.
72
New cards
.toUpperCase()
Converts to uppercase.
73
New cards
.charAt(index)
Returns character at index.
74
New cards
Escape Sequences
Special characters in strings.
75
New cards
Strings are immutable
Char inside string obj cannot be changed.
76
New cards
Named Constants
Fixed value that can't change.
77
New cards
Primitive Constants
Types include Integer, Floating-point, Character, String, Boolean.
78
New cards
Comments
Single-line: // comment, Multi-line: /* ... */, Documentation (Javadoc): /** ... */