0% found this document useful (0 votes)
47 views

Java Midterm Cheat Sheet: by Via

This document provides a cheat sheet for Java concepts for a midterm exam. It includes summaries of String methods, Scanner methods, Math methods, Objects, Arrays, ArrayLists, Loops, Characters, and common Java vocabulary terms in 3 sentences or less.

Uploaded by

Thu Huynh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Java Midterm Cheat Sheet: by Via

This document provides a cheat sheet for Java concepts for a midterm exam. It includes summaries of String methods, Scanner methods, Math methods, Objects, Arrays, ArrayLists, Loops, Characters, and common Java vocabulary terms in 3 sentences or less.

Uploaded by

Thu Huynh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Midterm Cheat Sheet

by sefergus via cheatography.com/31341/cs/9489/

String Methods Escape Sequences Objects (cont)

.toUpp​erC​ase() .equal​s(str) \t tab array of for (int i, i<t​hin​g.l​ength, i++)

.toLow​erC​ase() .index​Of(e) \n newline objects ​ ​ array[i]= new


Thing(​par​am);}
.subst​rin​g(i,j) j is excluded .conca​t(str) \" double quote
"​thi​s.r​adi​us" is an instance variable, as is the
.length() .charAt(i) \\ backslash
original data field
.compa​reT​o(str) .conta​ins(e) "​rad​ius​" is the local variable
Date Class
Intege​r.p​ars​eIn​teg​er(​int​String)
jav.ut​il.Date date= new java.u​til.Date; constr​uctors must have same name as class
Double.pa​rse​Dou​ble​(do​ubl​eSt​ring)
constr​uctors do not have a return type, not
date.t​oSt​ring();
import java.u​til.Sc​anner; even void
Scanner input= new Scanne​r(S​yst​em.in); constr​uctors are invoked using the new
Point2D Class
operator when an object is created
Scanner Methods: default constr​uctor goes to class with no other
import java.g​eom​etr​y.P​oint2D;
.nextL​ine() ends with line constr​uctors defined
Point2D variable = new Point2D(x, y);
.next() ends with white space
.nextD​ouble()
Abstract Classes and Interfaces
.nextInt() Objects
Abstract Classes Inte​rfa​ces
no Circle() {
Naming variable } cannot use "​new​" only has abstract
constr​ucto methods
keywords lowercase rule
r methods have no body no constr​uctors
variables camelCase convention
constr​ucto Circle (double radius) { mix of abstra​ct/​non​- "​imp​lem​ent​s"
constants ALL_CAPS rule r this.r​adi​us=​rad​ius;} ab​stract methods
class names CamelCase convention
getter double getArea() { "​ext​end​s" contains
return 2 x radius x radius x Math.PI; } constants
Math Methods
setter void setRad​ius​(double radius) { has constr​uctors
Math.p​ow(a, b) Math.PI() this.r​adi​us=​rad​ius;}
contains contacts and variables
Math.l​og(x), Math.s​qrt(x) instanceof tests whether an object is an
instance of a class public abstract class ClassName {
Math.l​og10(x)

Math.floor rounds Math.c​eil() rounds up super(); calls no arg constr​uctor of


java.lang.Comparable
down superclass
public interface comparable <E>{
Math.r​andom() Math.m​in(), super(​arg) calls matching arg constr​uctor of public int compareTo(E o); }
Math.max() ; superclass returns -1 for less than, 0 for equals,
1 for greater than
import java.l​ang.Math;

java.lang.Cloneable
has sin, cos, tan, toRadians, toDegree, asin,
public interface clonable {}
acos, atan
use .clone()

low + Math.r​and​om()* high (non-i​ncl​usive)


Loops

while int x=n;


while (x>1) {
change x; }

for for (int i, i<v​ari​able, i++){

for each (arrays) for (int i: list){

boolean (boolean ? true : false)

By sefergus Published 16th October, 2016. Sponsored by Readability-Score.com


cheatography.com/sefergus/ Last updated 16th October, 2016. Measure your website readability!
Page 1 of 2. https://readability-score.com
Java Midterm Cheat Sheet
by sefergus via cheatography.com/31341/cs/9489/

Characters Array methods Vocabulary (cont)

.isDig​it(ch) .isLet​ter(ch) java.util.Arrays.sort(array) .length static shared by all instances of a class

.isLow​erC​ase​(ch), .toLow​erC​ase​(ch), java.util.Arrays.equal(a1, a2) if relational <, <=, ==, !=, >, >=
.isUpp​erC​ase(ch) .toUpp​erc​ase(ch) corres​ponding operator
elements are
logical !, &&, || (incl​usi​ve), ^
ArrayList Methods the same
operator (excl​usive)
Arrays.toString(array) .reverse()
create ArrayL​ist​<ty​pe> name = new Numeric byte, short, int, long, float,
ArrayL​ist​<ty​pe>(); array[i] array[i]=e Types (in double
order)
access list.g​et(i) import java.u​til.Ar​rays;
element int[] values= new int[10] Variable variables only exist within {}
default values: 0, /u0000, or false Scope
update list.s​et(i, e)
element printing gives reference assignment =, +=, -=, *=, /=, %=
methods can modify arrays operators
return size list.s​ize()
import java.u​til.Ar​rays;
operators +, -, %, / (trun​cates for int)
add element list.a​dd((i), e) multi-​dim​ens​ional arrays: arrays of arrays.
increment/ ++, --
remove list.r​emove(i or e) eleme​ntType [rows]​[co​lumns]
decrement
element arrayVar
operators
remove all list.c​lear()
instance a method that can only be
elements Vocabulary
method invoked from a specific object
import java.u​til.Ar​ray​List; compos​ition inform​ation belongs to one
local within a method
object
variable
Important methods associ​ati​on/​se inform​ation can belong to
instance dependent on the specific
modifier return​Val​ueType g​reg​ation many objects
variable instance (class)
method​Nam​e(p​arams){ public can be seen anywhere in any
overlo​ading methods can have the same
public Class ClassName{ visibility package
methods name as long as their method
​ ​ ​public static void main (String[] args) private can be seen within class signatures are different
visibility
Scanner input= new Scanne​r(S​yst​em.in) binary operators are left-a​sso​cia​tive,
System.ou​t.p​rin​tln​(line); protected in package and subclasses of assignment operators are right associ​ative
visibility this in any package
public static type name (type param){
​ ​ ​return type; } runtime error crash

public boolean equals (Object o){ compile error doesn't run

​ ​ if (o instance Person){ final static constant modifier


Person p= (Person) o;
byte 8 bits*
return this.n​ame.eq​ual​s(p.ge​tNa​me()));
block /* ... */
}else{
comment
​ ​ ​ ​ ​ ​return false;
} line comment //
} javadoc /** ... */
public String toStri​ng(){ comments
return "​Str​ing​";} break; breaks out of a loop
to use a method from a different class: continue; stays in loop
Class.m​et​hod​(var);
variable creating a variable with its type
declar​ation

By sefergus Published 16th October, 2016. Sponsored by Readability-Score.com


cheatography.com/sefergus/ Last updated 16th October, 2016. Measure your website readability!
Page 2 of 2. https://readability-score.com

You might also like