Java Reference Cheat Sheet
Java Reference Cheat Sheet
1
Our standard random library. .................................................................................................................. 20
Our standard statistics library. ................................................................................................................. 20
Using an object. ...................................................................................................................................... 22
Creating an object................................................................................................................................... 22
Object-oriented libraries. ........................................................................................................................ 23
Java's String data type. ............................................................................................................................ 24
Java's Color data type.............................................................................................................................. 25
Our input library. .................................................................................................................................... 25
Our output library. .................................................................................................................................. 25
Our picture library. .................................................................................................................................. 26
Hello, World.
2
3
Access Modifiers
public Y Y
nothing Y N
public Y Y Y Y
protected Y Y Y N
no access modifier Y Y N N
private Y N N N
Non-Access Modifiers
static, final, abstract,
Class declaration
public final class Grclass
extends Object
implements Serializable, GenericDeclaration, Type, AnnotatedElement
4
Method
public static int funcName(int a, int b) {
// body
}
public static : modifier.
int: return type
funcName: function name
a, b: formal parameters
int a, int b: list of parameters
Methods pass Parameters by Value
Method overloading same overloading rules apply same name, parameters type diff or # diff
Interface
Use when expect that unrelated classes would implement your interface. OR
You want to specify the behavior of a particular data type, but not concerned about who implements its behavior.
Constructor
5
public MyClass(int theNumber) {
this.number = theNumber;
Overloading
Single Class AND (number of parameters is different OR parameter types are different )
Overriding
public class Animal{
public class Dog extends Animal{
public static void main(String args[]){
Animal a = new Animal(); // Animal reference and object
Animal b = new Dog(); // Animal reference but Dog object
a.move(); // runs the method in Animal class
b.move(); //Runs the method in Dog class
Integers.
6
Floating-point numbers.
Booleans.
7
Comparison operators.
Math library.
8
Type conversion.
9
10
While and for loops.
Break statement.
Do-while loop.
Switch statement.
11
12
Arrays.
Compile-time initialization.
Two-dimensional arrays.
13
Compile-time initialization.
Ragged arrays.
14
15
Our standard input library.
16
17
Redirection and piping.
Functions.
18
Libraries of functions.
19
Our standard random library.
20
21
Using an object.
Creating an object.
Instance variables.
Constructors.
Instance methods.
22
Classes
Object-oriented libraries.
23
Java's String data type.
24
Java's Color data type.
25
Our picture library.
http://www.javagenious.com/interview/java-interview-questions-and-answers-part-1.html
26