Quick Reference
Click the tab for your background language, or check Operators and Errors.
Coming from CSCD 110? The concepts are identical — only syntax changes.
| Python (CSCD 110) | Java (CSCD 210) |
|---|---|
x = 5 | int x = 5; |
name = "Alice" | String name = "Alice"; |
pi = 3.14 | double pi = 3.14; |
flag = True | boolean flag = true; |
print("hi") | System.out.println("hi"); |
print("hi", end="") | System.out.print("hi"); |
f"Hello {name}" | "Hello " + name |
f"avg={avg:.2f}" | printf("avg=%.2f%n", avg) |
input("Name: ") | sc.nextLine() |
int(input()) | Integer.parseInt(sc.nextLine()) |
float(input()) | Double.parseDouble(sc.nextLine()) |
7 / 2 → 3.5 | 7 / 2 → 3 truncates! |
7 // 2 → 3 | 7 / 2 (int ÷ int always truncates) |
7 % 2 → 1 | 7 % 2 → 1 |
if x > 5: | if (x > 5) { |
elif x > 3: | } else if (x > 3) { |
else: | } else { |
for i in range(10): | for (int i = 0; i < 10; i++) { |
while x > 0: | while (x > 0) { |
name == "Alice" | name.equals("Alice") not == |
and / or / not | && / || / ! |
# comment | // comment |
Kotlin compiles to the same JVM as Java — but Java requires explicit types everywhere.
| Kotlin | Java (CSCD 210) |
|---|---|
var x = 5 | int x = 5; |
val name = "Alice" | final String name = "Alice"; |
var pi: Double = 3.14 | double pi = 3.14; |
var flag = true | boolean flag = true; |
println("hi") | System.out.println("hi"); |
"Hello $name" | "Hello " + name |
"avg=%.2f".format(avg) | printf("avg=%.2f%n", avg) |
readLine()!! | sc.nextLine() |
readLine()!!.toInt() | Integer.parseInt(sc.nextLine()) |
readLine()!!.toDouble() | Double.parseDouble(sc.nextLine()) |
if (x > 5) { } | if (x > 5) { } (same!) |
when (x) { 1 -> ... } | switch (x) { case 1: ... } |
for (i in 0..9) { } | for (int i = 0; i < 10; i++) { |
while (x > 0) { } | while (x > 0) { } (same!) |
fun greet(name: String) { } | static void greet(String name) { } |
fun add(a: Int, b: Int): Int | static int add(int a, int b) |
name == "Alice" | name.equals("Alice") not == |
null | null (no null safety — NullPointerException!) |
Java looks a lot like C — but no pointers, no manual memory, and everything lives in a class.
| C | Java (CSCD 210) |
|---|---|
#include <stdio.h> | import java.util.Scanner; |
int main() { ... } | public static void main(String[] args) { ... } |
#define MAX 100 | static final int MAX = 100; |
int x = 5; | int x = 5; (same!) |
double pi = 3.14; | double pi = 3.14; (same!) |
int flag = 1; /* true */ | boolean flag = true; |
char name[50]; | String name; (no length limit) |
printf("hi\n"); | System.out.println("hi"); |
printf("x=%d\n", x); | System.out.printf("x=%d%n", x); |
scanf("%d", &x); | int x = Integer.parseInt(sc.nextLine()); |
7 / 2 → 3 | 7 / 2 → 3 (same truncation!) |
7 % 2 → 1 | 7 % 2 → 1 (same!) |
if / else if / else | if / else if / else (same syntax!) |
for / while / do-while | for / while / (do-while same) |
int arr[5]; | int[] arr = new int[5]; |
arr[i] | arr[i] (same!) |
sizeof(arr)/sizeof(arr[0]) | arr.length |
strcmp(a, b) == 0 | a.equals(b) not == |
strlen(s) | s.length() |
int *ptr = &x; | No pointers — Java uses references automatically |
malloc() / free() | Automatic — garbage collector handles memory |
void foo(int x) { } | static void foo(int x) { } |
Higher rows run first. Left-to-right within a row. Use parentheses when in doubt.
| Operators | Category | Associativity |
|---|---|---|
() [] . | Grouping, access, method call | left → right |
! ++ -- (type) | Unary, cast | right → left |
* / % | Multiply, divide, mod | left → right |
+ - | Add, subtract, String concat | left → right |
< <= > >= | Relational | left → right |
== != | Equality (use .equals() for Strings) | left → right |
&& | Logical AND — short-circuits | left → right |
|| | Logical OR — short-circuits | left → right |
= += -= *= /= %= | Assignment | right → left |
Key traps: "x=" + 1 + 2 → "x=12" (concat left-to-right).
7 / 2 * 1.0 → 3.0 (truncation happens before the double).
Click any error to see why it happens and how to fix it.
cannot find symbol
You used a variable or method that doesn't exist here. Check spelling, check it's declared above this line, and check imports (import java.util.Scanner;).
incompatible types
Assigning the wrong type. Example: int x = "hello"; — String can't go in int. Fix with a cast ((int)) or parse method (Integer.parseInt()).
variable might not have been initialized
Java sees a path where this variable could be read before being set. Fix: give it an initial value at declaration — String grade = ""; or int total = 0;.
reached end of file while parsing
Missing a closing }. Count opening and closing braces — they must match. Work from the inside out.
';' expected
Every statement ends with ;. Check the flagged line and the line above it.
== vs .equals() — logic bug
== on Strings compares memory addresses. scanner.nextLine() == "yes" is almost always false even when the user typed "yes". Always use .equals().
NumberFormatException at runtime
You called Integer.parseInt() or Double.parseDouble() on text that isn't a valid number — often an empty line from the Scanner buffer. Use nextLine() for everything.