0% found this document useful (0 votes)
26 views2 pages

Java Consolidated

This document provides a summary of key Java concepts including: 1. Primitives like int, float, and boolean, wrapper classes, and literals. Strings and how they are stored. 2. Exceptions and errors in Java including checked and unchecked exceptions, and how to throw and catch exceptions. 3. File I/O for reading and writing files using classes like FileInputStream and FileWriter.

Uploaded by

sachintel321
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)
26 views2 pages

Java Consolidated

This document provides a summary of key Java concepts including: 1. Primitives like int, float, and boolean, wrapper classes, and literals. Strings and how they are stored. 2. Exceptions and errors in Java including checked and unchecked exceptions, and how to throw and catch exceptions. 3. File I/O for reading and writing files using classes like FileInputStream and FileWriter.

Uploaded by

sachintel321
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

Java Cheat Sheet

by CommanderJak via cheatography.com/121316/cs/22168/

Primitives - raw data types Except​ion​s/E​rrors (cont) File I/O - data access outside JRE

int (32-bits) short (16) throw commands e be thrown FileIn​put​/Ou​tpu​tSteam read/write bytes
float (32) double (64) useful for testing FileRe​ade​r/W​riter by characters
throw new Excep​tio​‐
char (16) long (64) Buffer​edR​ead​er/​Writer line by line
nTy​pe();
byte (8) boolean (1) Buffe​red​Writer bw = new Buffer​‐
Create by extending Excep​tion
Wrapper Class - object version of primitive, edW​riter (new FileWr​ite​r(".../​‐
Exception class
can convert by un/aut​oboxing jav​a/s​rc/​mai​n/r​eso​urc​es.i​o.t​ex​‐
public Money
Literal - represents a primitive value (d, f, ' ', t"));
Exception{
" ", L)
super("Error Messag​‐
final Keyword
e")};
Strings - immutable, final sequence of
Class cannot be extended
chars try{must have try & catch/​‐
Method cannot be overridden
finally not just try}
String Pool area in Heap that
catch​( E​xce​pti​onType e){ca​tches+ Variable cannot change value
stores String literals to
save memory but only 1 runs}
Terms
final​ly{​always execut​es };
String s1 = draws from same
Catches go from specific exception to Java classe​d-based object​-or​iented
"hi"; memory address
general progra​mming (OOP), write
String s2 =
once run anywhere (WORA),
"hi"; stored in heap not pool
Advanced Operators automatic memory manage​‐
String s3 =
ment, pass by value or copy
new String + Concat​‐ only operator overlo​ading
reference, strong types
enation in Java
("hi​");
IDE Integrated Develo​pment
% Modulus returns reminder (7 % 5 =
String​Builder mutable Enviro​nment
2)
String​Buffer +threa​dsafe Linter auto compiles and catches
! Not returns opposite boolean
Integer Pool - range -128 to 127 errors in IDE
++/-- pre (println(++5)=6)
Reflection allows java to write code at
Increment post (prin​tln​(5+​+)=5)
Array - object holding elements of one API runtime where classes, fields,
type &&/|| And/Or short-​circuit evaluates one methods are treated as objects
side
int[] numbers = {1, 2, 3}; Recursion calling a method within itself
& / | And/Or evaluates both sides
int[] numbers = new int[si​ze]; Code how much reachable tested
^ Exclusive both cannot be true Coverage code
int[][] 2dArray = new int[ro​ws]​‐
Or
[co​lumns]
? Ternary (if condit​ion)? return​:else Memory
return
Object Class - everything inherits from MetaSpace unchanging info

.toSt​rin​‐ prints memory address HeapSpace variable content


Access Modifiers
g(); StackSpace method calls/​var​iable
Public all
references
.equa​‐ checks for same memory
Private only class
ls(); address
Prote​cted also children
.hash​Cod​‐ id not guaranteed to be
(Default) only package
e(); unique

Object - an instance of a class Scopes - where does reference extend


Class - blueprint for object
Class static

Except​ion​s/E​rrors Object instance


Method local
Block local

Static { block runs at beginning


Error cannot recover from when class first accessed,
stackoverflow, syntax... initia​liz​ati​on};

Checke​d/C​‐ cannot compile,


ompile compiler sees
FiloIO, SQLExc​ept​ion...
Unchec​ked​/Ru​‐ not required to be
ntime handled
NullPointer, Arithm​etic...
throws throws e to method
caller

By CommanderJak Not published yet. Sponsored by Readable.com


Last updated 26th March, 2020. Measure your website readability!
Page 1 of 2. https://readable.com

cheatography.com/commanderjak/

You might also like