Show Menu

MSA Java (rp) Cheat Sheet by

java

Data Types

String
" type string here "
int
E.G: 0
boolean
true/false
char
'x'
double
E.G 0.00

Operators (Summary)

+
Addition / String concat­enation
%
Modulus (remai­nder)
++ , --
Increment / Decrement by 1
!
Inverts boolean value
= , ==
Assigns, Equals to
!=
Does Not equal to
>=
Greater than OR Equal to
<=
Lesser than OR Equal to
&&
Condit­ional - AND
||
Condit­ional - OR

Methods

System.ou­t.p­rin­tln­(line)
System.ou­t.p­rin­tf(­format, arguments)
Helper.re­ad­Da­taT­ype­(­string)
// For printf formatting //
%d = integer
%s = String
%f = double (.2f = 2dp)
%b = boolean

Loops / Impt Statements

while(­con­dition)
(option != 4) { code }
for(va­r,c­ond­,incre)
(int 1=0;i<­10;i++)
if / else if / else
if(con­dition) { code }
switch­(Ex­pre­ssion)
switch (choice)
Switch syntax: E.g: Input is an int Choice

Switch (choice)
{
case 1:
< code >
break;
.....
default:
< code >
break;
}
 

Arrays

Decl­aring an Array
Syntax:
Datat­ype[ ] nameO­fArray =
new Datat­ype[ No. of elements in array ];

Example:
int [ ] rando­mVa­lues = new int [ 7 ];
// Creates an array called rando­mVa­lues with 7 elements (0-6)


Assi­gning Value to Array: (Using prev E.G)
random­Val­ues[3] = 100;
// Assigns value of 100 to the 4th element [3] of random­Values array


Decl­aring & Initia­lizing @ Same Time
int[ ] random­Values = {5,12,­51,­23,­12,­24,21};
// Creates an array called rando­mVa­lues and assigning 7 elements in it in a single line.


Acce­ssing Elemen­ts:
System.ou­t.p­rin­tln­(ra­ndo­mVa­lue­[3]);
// Prints out "­23" (prev example)


Finding out Array Length
System.ou­t.p­rin­tln­(ra­ndo­mVa­lue.le­ngth);
// Prints out 7

Values for Primitive Arrays

int
0
double
0.0
boolean
false
String
null

String Methods

charAt­(index)
Returns char @ index
endsWi­th(­suffix)
if ends w suffix
equals­Ign­ore­Cas­e(s­tring)
length()
Returns length of string
starts­Wit­h(p­refix)
if starts w prefix
toUppe­rCase()
Converts to upperCase
toLowe­rCase()
Converts to lowerCase
 

Class Diagram

'+' = Public , '-' = Private
underlined = Static

// Constr­uctors have the same name as class.
// if return type is 'void' , no return statement is required.

Creation of Class

// Using the Class Diagram above //
Declare Fields First:
public String licenseNo, colour;
public int speed;

Cons­tru­ctor
[Right­-click, Source, Create constr­uctor using Fields, delete the super(); ]

Create Methods:
public void accele­rat­e(int acc)
{
}

public void honk ()
{
}
// Creating Array/ Object in Main Class //

Array:
Syntax:
Class­Name[ ]arra­yName = new Class­Nam­e[x];

E.g:
Car[ ] testArray = new Car[5]

Obje­cts
E.g:
Car newObject = new Car();
// Creates a new object, called 'newOb­ject'.

Calling a method in Main class from another class
newObj­ect.me­tho­dNa­me();

Download the MSA Java (rp) Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/rawbeef_msa-java-rp.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Selenium WebDriver Cheat Sheet Cheat Sheet
          Spring Framework 4 Cheat Sheet