0% found this document useful (0 votes)
66 views2 pages

Java Exam Cheat Sheet

Uploaded by

althea pauig
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)
66 views2 pages

Java Exam Cheat Sheet

Uploaded by

althea pauig
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

■ Java Exam Cheat Sheet (with Definitions)

■ Printing
- `System.out.println()` → Prints with a newline.
- `System.out.print()` → Prints on the same line.
- `System.out.printf()` → Prints with formatting (%d, %f).

■ Variables & Data Types


- **Variable** → Named container that stores data. Syntax: `datatype name = value;`
- **Primitive**: byte, short, int, long, float, double, char, boolean
- **Non-primitive**: String

■ Type Conversion
- **Casting** → Converting data type.
- Widening (implicit): safe (int → double).
- Narrowing (explicit): manual, data loss possible (double → int).
- **Parsing**: Convert String → number/boolean.
- Examples: `Integer.parseInt()`, `Double.parseDouble()`, `Boolean.parseBoolean()`

■ Input in Java
- **Scanner** → Reads user input.
- `nextLine()` whole line, `next()` one word, `nextInt()`, `nextDouble()`, `nextBoolean()`.

■ Operators
- **Arithmetic**: + - * / %
- **Unary**: ++ -- !
- **Assignment**: =, +=, -=, *=, /=, %=
- **Relational**: == != < <= > >=
- **Logical**: && || !

■ Decision Making
- **Decision Making** → controls flow.
- `if`, `if-else`, `nested if`, `if-else-if ladder`, `switch-case`.
- **Jump**: `break` exit, `continue` skip, `return` exit method.

■ Loops
- **Loop** → repeats code.
- `for` → known iterations.
- `while` → repeats while condition true.
- `do-while` → executes at least once.
- **Nested loop** → loop inside another.
- Loop control: `break`, `continue`.

■ Common Mistakes
- Infinite loops (`while(true)`).
- Wrong loop conditions.
- Forgetting to update loop variable.

■ Sample Applications
- Grade Evaluation (if-else-if).
- Voter Check (nested if).
- Loops: numbers 1–20, even 1–50, multiplication table, star patterns.

You might also like