0% found this document useful (0 votes)
3 views3 pages

Sefergus Java Midterm

This Java Midterm Cheat Sheet provides a comprehensive overview of essential Java concepts, including string methods, date classes, abstract classes, interfaces, and various programming constructs. It covers key methods, naming conventions, array manipulation, and error handling, along with visibility modifiers and operator types. The document serves as a quick reference for students preparing for their midterm exams in Java programming.

Uploaded by

717822i159
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Sefergus Java Midterm

This Java Midterm Cheat Sheet provides a comprehensive overview of essential Java concepts, including string methods, date classes, abstract classes, interfaces, and various programming constructs. It covers key methods, naming conventions, array manipulation, and error handling, along with visibility modifiers and operator types. The document serves as a quick reference for students preparing for their midterm exams in Java programming.

Uploaded by

717822i159
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Midterm Cheat Sheet

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

String Methods Date Class Abstract Classes and Interfaces

.toUpp​erC​ase() .equal​s(str) jav.ut​il.Date date= new java.u​til.Date; Abstract Classes Interfaces


.toLow​erC​ase() .index​Of(e) date.t​oSt​ring(); cannot use "​new​" only has abstract
.subst​rin​g(i,j) j is excluded .conca​t(str) methods
Point2D Class methods have no body no constr​uctors
.length() .charAt(i)
import java.g​eom​etr​y.P​oint2D; mix of abstra​ct/​non​-ab​‐ "​imp​lem​ent​s"
.compa​reT​o(str) .conta​ins(e)
Point2D variable = new Point2D(x, y); stract methods
Intege​r.p​ars​eIn​teg​er(​int​String)
"​ext​end​s" contains
Double.pa​rse​Dou​ble​(do​ubl​eSt​ring)
Objects constants
import java.u​til.Sc​anner;
no Circle() { has constr​uctors
Scanner input= new Scanne​r(S​yst​em.in);
variable } contains contacts and variables
constr​‐
Scanner Methods: public abstract class ClassName {
uctor
.nextL​ine() ends with line
constr​‐ Circle (double radius) {
.next() ends with white space java.lang.Comparable
uctor this.r​adi​us=​rad​ius;}
.nextD​ouble() public interface comparable <E>{
.nextInt() getter double getArea() { public int compareTo(E o); }
return 2 x radius x radius x Math.PI; } returns -1 for less than, 0 for equals,
Naming setter void setRad​ius​(double radius) { 1 for greater than

keywords lowercase rule this.r​adi​us=​rad​ius;}


java.lang.Cloneable
variables camelCase convention instanceof tests whether an object is an instance
public interface clonable {}
of a class
constants ALL_CAPS rule use .clone()
super(); calls no arg constr​uctor of superclass
class names CamelCase convention
super(​‐ calls matching arg constr​uctor of Loops
Math Methods arg); superclass
while int x=n;
array of for (int i, i<t​hin​g.l​ength, i++)
Math.p​ow(a, b) Math.PI() while (x>1) {
objects ​ ​ array[i]= new Thing(​par​am);}
Math.l​og(x), Math.l​‐ Math.s​qrt(x) change x; }
og10(x) "​thi​s.r​adi​us" is an instance variable, as is for for (int i, i<v​ari​able, i++){
the original data field
Math.floor rounds Math.c​eil() rounds for each (arrays) for (int i: list){
"​rad​ius​" is the local variable
down up boolean (boolean ? true : false)
Math.r​andom() Math.m​in(),
constr​uctors must have same name as
Math.max() Characters
class
import java.l​ang.Math; constr​uctors do not have a return type, not .isDig​it(ch) .isLet​ter(ch)
even void .isLow​erC​ase​(ch), .toLow​erC​ase​(ch),
has sin, cos, tan, toRadians, toDegree, asin, constr​uctors are invoked using the new .isUpp​erC​ase(ch) .toUpp​erc​ase(ch)
acos, atan operator when an object is created
default constr​uctor goes to class with no ArrayList Methods
low + Math.r​and​om()* high (non-i​ncl​usive) other constr​uctors defined

Escape Sequences

\t tab
\n newline
\" double quote
\\ backslash
create ArrayL​ist​<ty​pe> name = new
ArrayL​ist​<ty​pe>();
access list.g​et(i)
element
update list.s​et(i, e)
element
return list.s​ize()
size
add list.a​dd((i), e)
element
remove list.r​emove(i or e)
element

By sefergus Published 16th October, 2016. Sponsored by CrosswordCheats.com


cheatography.com/sefergus/ Last updated 16th October, 2016. Learn to solve cryptic crosswords!
Page 1 of 3. http://crosswordcheats.com
Java Midterm Cheat Sheet
by sefergus via cheatography.com/31341/cs/9489/

ArrayList Methods (cont) Vocabulary Vocabulary (cont)

remove all elements list.c​lear() compos​ition inform​ation belongs to instance a method that can only be
one object method invoked from a specific object
import java.u​til.Ar​ray​List;
associ​ati​on/​‐ inform​ation can belong to local within a method
Important methods seg​reg​ation many objects variable

modifier return​Val​ueType method​Nam​e(p​‐ public visibility can be seen anywhere in instance dependent on the specific
arams){ any package variable instance (class)

public Class ClassName{ private visibility can be seen within class overlo​‐ methods can have the same
​ ​ ​public static void main (String[] args) protected in package and ading name as long as their method
visibility subclasses of this in any methods signatures are different
Scanner input= new Scanne​r(S​yst​em.in)
package binary operators are left-a​sso​cia​tive,
System.ou​t.p​rin​tln​(line);
runtime error crash assignment operators are right associ​ative
public static type name (type param){
​ ​ ​return type; } compile error doesn't run

public boolean equals (Object o){ final static constant modifier


​ ​ if (o instance Person){ byte 8 bits*
Person p= (Person) o; block comment /* ... */
return this.n​ame.eq​ual​s(p.ge​tNa​me()));
line comment //
}else{
javadoc /** ... */
​ ​ ​ ​ ​ ​return false;
comments
}
} break; breaks out of a loop

public String toStri​ng(){ continue; stays in loop


return "​Str​ing​";} variable declar​‐ creating a variable with
to use a method from a different class: ation its type
Class.m​et​hod​(var); static shared by all instances of
a class
Array methods relational <, <=, ==, !=, >, >=
java.util.Arrays.sort(array) .length operator

java.util.Arrays.equal(a1, a2) if corres​‐ logical operator !, &&, || ( inclusive), ^


ponding ( exclusive)
elements Numeric Types byte, short, int, long,
are the (in order) float, double
same
Variable Scope variables only exist within
Arrays.toString(array) .reverse() {}
array[i] array[i]=e assignment =, +=, -=, *=, /=, %=
import java.u​til.Ar​rays; operators
int[] values= new int[10] operators +, -, %, / (truncates for
default values: 0, /u0000, or false int )
printing gives reference increment/ ++, --
methods can modify arrays decrement
import java.u​til.Ar​rays; operators
multi-​dim​ens​ional arrays: arrays of arrays.
elemen​tType [rows]​[co​lumns] a
rrayVar

By sefergus Published 16th October, 2016. Sponsored by CrosswordCheats.com


cheatography.com/sefergus/ Last updated 16th October, 2016. Learn to solve cryptic crosswords!
Page 2 of 3. http://crosswordcheats.com

You might also like