Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
10 views
Java Cheatsheet
Uploaded by
Ishaan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Java Cheatsheet For Later
Download
Save
Save Java Cheatsheet For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
10 views
Java Cheatsheet
Uploaded by
Ishaan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Java Cheatsheet For Later
Carousel Previous
Carousel Next
Save
Save Java Cheatsheet For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 2
Search
Fullscreen
THE JAVA LANGUAGE CHEAT SHEET Primitive Type: ¥ O@atulkumare INTEGER: byte (bit), short (16bit), int (32bit), long (64bit) , DECIM: float (32bit) , double (64bit) sOTHER: boolean(ibit), char (Unicode) yb00101, LONG: saseeeeeesaseL ta AM ARES INTE INE VT Primi Operators Assignment Operator: = (ex: int a=5,b=3; ) Binary Operators (two arguments): + - ° / & Unary Operators: + - ++ -- Boolean Not Operator (Unary): ! Boolean Binary: Is > oe cee Boolean Binary Only: 45 || Bitwise Operators: ~ 6 * | << >> >>> Ternary Operator: bool?valtrue:valfalse; (int)5.5; //works for numeric types Integer.parsernt ("123"); arseFloat ("1.5"); Integer.parsernt ("7A",16); //fromHex String hex = Integer. toString (99,16) ;//toHex //erevious lines work w/ binary, other bases java.util.scanner, input, output Scanner sc = new Scanner (System.in); int i= sc.nextint (); //stops at whitespace String Line = sc.nextLine(); //whole Line Systen.out.printin(*bla"); //stdout System.err.print ("bla"); //stderr,no newline java.lang.Number types Integer x = 5; double y = x.doubleValue(): double y = (double) x. intValue (); //Many other methods for Long, Double, etc java.lang.String Methods 7foperator +, e.g. “fat"s"cat” -> “fatcat” boolean equais (String other); int length ( char charat(int i); String substring(int 1, int 3}7 //j not incl boolean contains (String sub) boolean startsiith (String pre); boolean endsWith(String post); int indexof (String p): //-1 if not found int indexof (String p, int ij; //start at i int compareTo (String t); 1/*a" .compareto(*b") => -1 String replaceall (String str, String find); Steingl] split (String delim ; StringBuffer, StringBuilder SeringSuffer is synchronized StringBuilder (Use StringBuilder unless multithreaded) Use the .apend( xyz ) methods to concat toString() converts back to String java.lang.Math Math. abs (NUM) ,Math.ceil (NUM) , Math. floor (HUM) sMath. log (NUM) ,Math.max (A,B) ,Math.min (C, D) Math. pow (A,B) ,Math.cound(A) ,Math.random() IF_STATEMENTS : “CODING BUGS ©)NOTES GALLERY Tf boolean value ) ( STATEMENTS } else if( bool } ( STATEMENTS } else if( ..etc ) | STATEMENTS } else ( STATEMENTS | ‘/curly brackets optional if one line LOOPS: while( bool ) ( STATEMENTS } for(INIT;BOOL;UPDATE) ( STATEMENTS } //AINIT 2OOL 3STATEMENTS 4UPDATE 5->step2 do( STATEMENTS Jwhile( bool ); //do loops run at least once before checking break: — //ends enclosing loop (exit loop) continue; //jumps to bottom of loop ARRAYS int{] x = new int{10]z //ten zeros int(][] * = new int(51(5]7 //5 by 5 matcix int[] x = (1,2,3,4)7 x.length; //int expression length of array ant) * = (11,21, (3,4,5)}2 //ragged array String!] y = new String[10]; //10 nulls J/wove that object types are null by default / Poop through array for(int i=0ricarrayname.lengthrit+) { Jase arrayname(i]i ) //f0r-each loop through array int {] x = (10,20, 30,4017 for(int vz x) { //¥ cycles between 10,20, 30, 40 ' //toop through ragged array for(int i=0;icx.length;i++) for(int j=07}
( T value T getValue() { return value: | , class ExampleTwo
{ Ax By: , class ExampleThree
,B> | aA lists B head; , (Note the extends keyword here applies as well to interfaces, so A can be an int that extends List
JAVA COLLECTIONS Lister: Similar to arrays ArrayListcT>: Slow insert into middl //azrayList has fast random access LinkedList
: slow random access //isnkedList fast as queue/stack Stack: Removes and adds from end List Usage: boolean add(T e); void clear(); //empties boolean contains (Object 0}; T get (int index); T remove(int index); boolean remove (Object 0): //remove uses comparator T set (int index, E val); Int size(); List Traversal: for(int isGicx.size()ritt) ( Jyase x.get (i)? ) //assuming List
: for(Te: x) { )ase e 1 QueuecT>: Remove end, Insert beginning LinkedList implements Queue Queue Usage: T element(); // does not renove boolean offer(T 0); //adds T peek(); //pike element T poll(): //removes T remove(); //like poll Traversal: for(T e : x) () jat
: uses Comparable<7> for uniqueness TreeSet
, items are sorted HashSet
, not sorted, no order LinkedHashSet
, ordered by insert Usage like list: add, remove, size Traversal: for(T e : x) (1 MapcK,V>: Pairs where keys are unique HashMap
, no order LinkedHashMap
ordered by insert TreeMap
sorted by keys V get(K key); Set
keySet(); //set of keys V put(K key, V value: Vv remove (K key); Int size(); Collection
values(); //all values ee for-each w/ kevyset/values
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6127)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2542)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
CSE2221 - Cryptography Handout Updated
PDF
No ratings yet
CSE2221 - Cryptography Handout Updated
10 pages
ch-05
PDF
No ratings yet
ch-05
35 pages
C Experiment 4
PDF
No ratings yet
C Experiment 4
3 pages
ch-02
PDF
No ratings yet
ch-02
80 pages
MA1002 - Subjective Questions Module 1
PDF
No ratings yet
MA1002 - Subjective Questions Module 1
4 pages
MA1002 - Subjective Questions Module 2
PDF
No ratings yet
MA1002 - Subjective Questions Module 2
3 pages
Traffic Light
PDF
No ratings yet
Traffic Light
14 pages
Updated Module 3 Notes
PDF
No ratings yet
Updated Module 3 Notes
48 pages
2.5 Pil
PDF
No ratings yet
2.5 Pil
15 pages
SRM SOFT BSC Approved Syllabus 2018
PDF
No ratings yet
SRM SOFT BSC Approved Syllabus 2018
234 pages
Separation of Powers
PDF
No ratings yet
Separation of Powers
19 pages
Javascript Handwritten Notes
PDF
No ratings yet
Javascript Handwritten Notes
28 pages
HEI Exempted U 0473
PDF
No ratings yet
HEI Exempted U 0473
15 pages
MCA
PDF
No ratings yet
MCA
7 pages
Admissions Questions Answered by FAO Ebook
PDF
No ratings yet
Admissions Questions Answered by FAO Ebook
8 pages
Neil DeGrasse Tyson
PDF
No ratings yet
Neil DeGrasse Tyson
2 pages
Conservation of Water
PDF
No ratings yet
Conservation of Water
1 page
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)