Please enable JavaScript.
Coggle requires JavaScript to display documents.
AP chapter 2 Intro to JAva - Coggle Diagram
AP chapter 2 Intro to JAva
Operators
Arithmetic: +, -, *, /, %
Relational: ==, !=, >, <, >=, <=
Logical: &&, ||, !
Assignment: =, +=, -=, *=, /=, etc.
Precedence:
Use parentheses to control order.
Input/Output
input use scanner
Scanner input = new Scanner(System.in);
int num = input.nextInt();
String word = input.next();
String line = input.nextLine(); // for whole line
system.out.println for new line after else use system.out.print
Packages and Classes
Package: A namespace that organizes classes (like java.util, java.lang, java.io).
Class: A blueprint for creating objects.
You define classes using class:
public class myclass
types and identifiers
primitive data types
built in
int. double, boolean char
reference types
any object or class like string or scanner
identifiers
Must start with a letter, _, or $
Can't use Java keywords (like int, if, etc.)
Should be meaningful (camelCase for variables/methods)
control structures
if/else/elseif
for while loops
errors and exeptions
Syntax errors: Code doesn’t compile (e.g., missing ;, wrong type)
Runtime errors (exceptions): Crash during execution
e.g., divide by zero, null pointer
Logic errors: Program runs but produces wrong output
Common exception: InputMismatchException when using Scanner