Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Ultimate Java Quick Reference - CodeWithHarry, Cheat Sheet of Java Programming

java codes and cheat sheet basics for learning java language

Typology: Cheat Sheet

2020/2021

Uploaded on 07/07/2021

epil-tode
epil-tode 🇮🇳

4 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Ultimate Java Quick Reference - CodeWithHarry
1. // [comment]
Single line comment.
2. /* [comment] */
Multi line comment.
3. public
This can be imported
publically.
4. import [object].*
Imports everything in
object.
5. static
Going to be shared by every
[object].
6. final
Cannot be changed;
common to be defined with
all uppercase.
7. double
Integer with numbers that
can have decimals.
8. ;
Put after every command.
9. String
Just a string of characters.
10. Private
Can only be changed by a
method.
11. int
Can store numbers from 2^-
31 to 2^31.
12. fields are attributes
13. boolean
Can have true or false as
the value.
14. { }
These are used to start and
end a function, class, etc.
15. byte
These can store from -127 -
128.
16. long
Can store numbers from
2^127 to 2^-127.
17. char
Just lets you put in one
chracter.
18. double
64-bit number with
decimals.
19. float
32-bit number with
decimals.
20. protected
Can only be accessed by
other code in the package.
21. Scanner
This lets you get user input.
22. new [object
constructor]
This will let you create a
new object.
23. System.in
This lets you get data from
the keyboard.
24. public [class]()
This will be the constructor,
you use it to create new
objects.
25. super()
This will create the
superclass (the class it's
inheriting).
pf3
pf4

Partial preview of the text

Download Ultimate Java Quick Reference - CodeWithHarry and more Cheat Sheet Java Programming in PDF only on Docsity!

  1. // [comment] Single line comment.
  2. /* [comment] */ Multi line comment.
  3. public This can be imported publically.
  4. import [object].* Imports everything in object.
  5. static Going to be shared by every [object].
  6. final Cannot be changed; common to be defined with all uppercase.
  7. double Integer with numbers that can have decimals.
  8. ; Put after every command.
  9. String Just a string of characters.
    1. Private Can only be changed by a method.
    2. int Can store numbers from 2^- 31 to 2^31.
    3. fields are attributes
    4. boolean Can have true or false as the value.
    5. { } These are used to start and end a function, class, etc.
    6. byte These can store from - 127 -
    7. long Can store numbers from 2^127 to 2^-127.
    8. char Just lets you put in one chracter.
    9. double 64 - bit number with decimals.
    10. float 32 - bit number with decimals.
    11. protected Can only be accessed by other code in the package.
    12. Scanner This lets you get user input.
    13. new [object constructor] This will let you create a new object.
    14. System.in This lets you get data from the keyboard.
    15. public class This will be the constructor, you use it to create new objects.
    16. super() This will create the superclass (the class it's inheriting).
  1. extends [class] Makes the object a subclass of [object], [object] must be a superclass.
  2. ++ Will increment the amount.
  3. -- Will decrement the amount.
  4. += [amount] Increment by [amount]
    • = [amount] Decrement by [amount]
  5. *= [amount] Multiply by [amount]
  6. /= [amount] Divide by [amount]

System.out.println([text]) Will print something to the output console.

Can be used for concatenation. (ex. "6" + [var_here]) 35. public static void main(String[] args) This is your main function and your project will start in here. 36. System.out.print([text]) This prints stuff but there is no line break. (/n) 37. \n Called a line break; will print a new line. 38. \t This will print a tab. 39. if ([condition]) This will make it so if [condition] is true then it'll keep going. 40. && This means and. 41.! This means not. 42. || This means or. 43. == This means equal to.

This means less than.

This means greater than.

  1. = This means greater than or equal to.

[inputVarHere].hasNextLine () This will return if there is a next line in the input.

  1. this Refer to the class that you are in.
  2. [caller].nextdatatype This will get the [datatype] that you somehow inputted.
  3. Create getters and setters This will create the get methods and set methods for every checked variable.

[caller].hasNextdatatype

  1. System.out.printf([text]) Another way to print? // didn't quite get but ok then
  2. [type] [returntype] name { This is a way to create a method.
  3. [type][[indexes]] This will create an array with [indexes] amount of indexes; default infinite.
  4. int[] something = new int[20]; This will just make an array of ints with 20 ints in it.
  5. for ([object] [nameOfObject] : [arrayOfObject]) { This will iterate through all of the arrayOfObject with object in use incrementing by 1 until done.
  6. [object][[1]][[2]][[3]] [name] = {[value] [value] [value] \n [value] [value] [value]} [1] is how many down in array, [2] how many accross in array, [3] how many groups
  7. .length This will get how long something is, text, amount of indexes in array, etc.
    1. Arrays.copy0f([array], indexes); This will copy the array and how many indexes into another array.
    2. Arrays.toString([array]) Convert the whole array into one huge string.
    Arrays.binarySearch([array], [object]) This will search for [object] in [array].