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

ethanhann_java-basics-to-intermediate

https://cheatography.com/ethanhann/cheat-sheets/java-basics-to-intermediate/

Uploaded by

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

ethanhann_java-basics-to-intermediate

https://cheatography.com/ethanhann/cheat-sheets/java-basics-to-intermediate/

Uploaded by

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

Java Basics to Intermediate Cheat Sheet

by Kelvin (EthanHann) via cheatography.com/34848/cs/10942/

Primitive Data Types Operations on Number Variables Printing and Parsing

type size range of values Integer sign + +99 -or- Printing to console
byte 8-bit (-128 -> 127) - -99 System.ou​t.p​rin​t(S​tring s); print s
signed add + 5+3=8 System.ou​t.p​rin​tln​(String s);
2's comp print s followed by newline
subtract - 5-3=2
System.ou​t.p​rin​tln(); print a newline
short 16-bit (-32,768 -> 32,767) multiply * 5*3 = 15
signed Parse comman​d-line args
divide / 5/3 = 1 int Intege​r.p​ars​eIn​t(S​tring s);
2's comp
no
convert s to an int value
int 32-bit (-231 -> 231-1) fractional
double Double.pa​rse​Dou​ble​(String
signed part
s); convert s to a double value
2's comp
remainder % 5%3= long Long.p​ars​eLo​ng(​String s);
long 64-bit (-263 -> 263-1) 2 convert s to a long value
signed
Floati​ng-​Point add + 3.141 +
2's comp
Numbers 2.0 =
long 64-bit (0 -> 264-1) 5.141
unsigned
subtract - 3.141 -
float single​-pr​‐ (-3.40​282347 x 1038 2.0 =
ecision -> 3.40282347 x 1.111
32-bit 1038)
multiply * 3.141 *
signed
2.0 =
double double​- (-1.79​769​313​486​‐ 6.282
pr​ecision 231570 x 10308 ->
divide / 3.141 /
64-bit 1.7976​931​348​‐
2.0 =
signed 6231570 x 10 308)
1.5705
char 16-bit (0 -> 65,535)
unsigned Boolean Operations
Unicode
Values Literals Operations Operators
character
true true and &&
boolean size not true / false
defined false false or ||
not !
Hello World

{{noshy}}public class HelloWorld a b a && b a || b


{ false false false false
public static void (0) (0)
main(String[] args) false true (1) false true
​ ​ ​ { (0)
System.out.println("Hello true false false true
World!"); (1) (0)
​ ​ ​ }
true true (1) true true
}
(1)

Declaring and Inital​izing Comparison Operators


Integers Operator Meaning true false
int a, b; <-- Declare two integer == equal 2 == 2 2 == 3
variables
!= not equal 3 != 2 2 != 2
a = 100; <-- Initialize 'a' with a value of
< less than 2 < 13 2<2
100
b = 18; <-- Initialize 'b' with a value of 18 <= less than or 2 <= 2 3 <= 2

int c = a + b; <-- Declare and initialize equal

c with the value of a plus b > greater than 13 > 2 2 > 13


Double >= greater than 3 >= 2 2 >= 3
double a, b; or equal
a = 1.57;
Examples:
b = 9.8765;
Check if a number is a multiple of 2
double c = a + b; (x % 2 == 0) returns true if x is a
It is the same for every primitive data type. multiple of 2

Check months
(month >= 1) && (month <= 12)
returns true if month is between 1 and 12

By Kelvin (EthanHann) Not published yet. Sponsored by Readable.com


cheatography.com/ethanhann/ Last updated 19th February, 2017. Measure your website readability!
Page 1 of 2. https://readable.com

You might also like