This cheat sheet contains the most important takeaways that lead up to section five.
1. Getting Started
class: contains all of your code.
main(): entry point of your app.
javac <file-name>.java: compiles your code.
java <file-name>: runs the compiled code.
There are 6 main data types.
long can store very big numbers. But,
int is faster and takes less memory.
Put math operations in brackets if you wish to embed them inside a
"5 + 2 is " + (5 + 2);
3. Booleans and Conditionals
Put comparison operations in brackets if you wish to embed them inside a
"Five is not smaller than one. I'm certain this is " + (5 < 1);
Rules of thumb
When controlling how your code runs:
switchto compare one value against a list of values.
in any other scenario, use
Do not confuse
=to set a value equal to another.
==to compare two values and return a
Level of access:
Parameter: value received by the function.
Argument: value passed into the function.
Code: performs your task.
returnbreaks the entire function. Nothing after it can run.
Rule of thumb: if a function calculates a value, return it.
Rule of thumb:
forloops when you know in advance how many times your code should run.
whileloops to keep running code while a condition is
break: breaks a loop and stops it from running.
continue: skips the current run, and continues to the next one.
The default delimiter is white space.
Good coding habits
Tips and tricks
Use the up key to run previous terminal commands.
clearto clear the terminal output.
tabkey for auto-complete.
\nadds a new line of space.
\tadds a new tab of space.
/to comment a highlighted piece of code.
In Visual Studio Code, use
sysoutas a shortcut to
Cto interrupt the terminal output.