Syntax Flashcards
Static variable
private static int n;
instance variable
private int n;
Static method
public static int calc(int a, int b) {
return a + b * 2;
}
Typecast
BankAccount myAccount = (BankAccount) anObject;
Instanceof
if (anObject instanceof BankAccount)
Wrapper
String input = “5”;
int in = Integer.parseInt(input);
make a child class
public class Child extends Parent
default constructor of a child class
super();
abstract class
public abstract class Instructions {stuff}
interface
public interface Moveable {
implements
public class Warrior implements Moveable, Drawable {
enum def
public enum FilingStatus {SINGLE,MARRIED};
File IO
open:
FileReader reader = new FileReader(filename);
read: using scanner
Scanner data = new Scanner( reader ) ;
String line = data.nextLine() ;
try catch
try {
FileReader reader = new FileReader(“input.txt”);
} catch (FileNotFoundException e) {
System.out.println(“File not found: input.txt”);
}
throws
public void loadFile3() throws FileNotFoundException {
FileReader reader = new FileReader(“input.txt”);
}