Notes for Learn Java @ Codecademy

I used the Learn Java modules from Codeacademy to refresh my Java knowledge.


The precedence of each Boolean operator is as follows:

  1. ! is evaluated first
  2. && is evaluated second
  3. || is evaluated third

ternary conditional statement:

char canDrive = (fuelLevel > 0) ? ‘Y’ : ‘N’;


int subwayTrain = 5;

switch (subwayTrain){

case 1 : System.out.println(“This is a South Ferry bound train!”);
case 5 : System.out.println(“This is a Brooklyn bound train!”);
case 7 : System.out.println(“This is a Queens bound train!”);
System.out.println(“I’m not sure where that train goes…”);


By the way, I found switch statement very powerful combined with finite state machine (FSM) when doing my Arduino course projects.

Object Oriented Programming


class Name extends AnotherClass{

instance variable

constructor (parameters)

method (void, or has return value)


create new object;

call method;




Declare an ArrayList object storing integers:

ArrayList<Integer> listName = new ArrayList<Integer>();

Add 3 to the list:


Get a value at index 0:

listName. get(0);

Insert a new value 22 to index 2:


the size of list:

int size = listName.size();

for each loop:

for (Integer value : listName){



Declare a HashMap object (store String keys and Integer values):

HashMap<String, Integer> name = new HashMap<String, Integer>();

the size of HashMap:

int size = name.size();

Add keys and values:

name.put(“key”, 1);

Get value using key:


for each loop:

for (String item: name.keySet()) {




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s