You are on page 1of 82

Ultimate Java Quick Reference - CodeWithHarry

1. // [comment] 10. Private 64-bit number with


decimals.
Single line comment. Can only be changed by a
method.

19. float
2. /* [comment] */
11. int 32-bit number with
Multi line comment.
decimals.
Can store numbers from 2^-
31 to 2^31.
3. public
20. protected
This can be imported
12. fields are attributes Can only be accessed by
publically.
other code in the package.

13. boolean
4. import [object].*
21. Scanner
Can have true or false as
Imports everything in
the value. This lets you get user input.
object.

14. { } 22. new [object


5. static
constructor]
These are used to start and
Going to be shared by every
end a function, class, etc. This will let you create a
[object].
new object.

15. byte
6. final
23. System.in
These can store from -127 -
Cannot be changed;
128. This lets you get data from
common to be defined with
the keyboard.
all uppercase.

16. long
24. public [class]()
7. double Can store numbers from
2^127 to 2^-127. This will be the constructor,
Integer with numbers that
you use it to create new
can have decimals.
objects.
17. char

8. ; Just lets you put in one


25. super()
chracter.
Put after every command.
This will create the
superclass (the class it's
18. double inheriting).
9. String

Just a string of characters.


Ultimate Java Quick Reference - CodeWithHarry
26. extends [class] 35. public static void 44. <
main(String[] args)
Makes the object a subclass This means less than.
of [object], [object] must be This is your main function
a superclass. and your project will start in
here. 45. >

This means greater than.


27. ++
36. System.out.print([text])
Will increment the amount.
This prints stuff but there is 46. >=
no line break. (/n)
This means greater than or
28. --
equal to.
Will decrement the amount.
37. \n

Called a line break; will print 47.


29. += [amount] a new line. [inputVarHere].hasNextLine
()
Increment by [amount]
This will return if there is a
38. \t
next line in the input.
30. -= [amount] This will print a tab.

Decrement by [amount]
48. this
39. if ([condition])
Refer to the class that you
31. *= [amount] This will make it so if are in.
[condition] is true then it'll
Multiply by [amount] keep going.
49. [caller].next[datatype]()

32. /= [amount] This will get the [datatype]


40. &&
that you somehow
Divide by [amount] This means and. inputted.

33. 41. ! 50. Create getters and


System.out.println([text]) setters
This means not.
Will print something to the This will create the get
output console. methods and set methods
42. || for every checked variable.

34. + This means or.

Can be used for 51.


concatenation. (ex. "6" + [caller].hasNext[datatype]()
43. ==
[var_here])
This means equal to.
Ultimate Java Quick Reference - CodeWithHarry
This will return if it has the This will parse [number] 66. for ([number];
correct datatype within the into the [numbertype] with [condition]; [operation])
input. [string].
This will start at [number]
and then do [operation]
until [condition] is met.
52. overloading 59. ^

If you have different Return true if there is one


parameters you can call true and one false. 67. continue
them whatever way you
This will just go back to the
want.
enclosing loop before
60. !=
reaching other code.
Not equal too. (NEQ)
53. parameters

These are the inputs of your 68. while ([condition])


function. 61. ([condition]) ? [amount]
This will basically do
: [var]
something while [condition]
This will be like a shortcut is true.
54. ([datatype])[variable]
way to an if statement.
This will convert [variable]
into [datatype]. Also known 69. void
as casting. 62. switch([variable])
This means no return type.
This will do stuff with
specific cases. (e.g.
55. Math.random()
switch(hi){ case 2: (do 70. return
Generate an extremely stuff)})
This will return something
percise string of numbers
when you call it to where it
between 0 and 1.
was called from .
63. case [value]:

This will do stuff if the case


56. Primitives
is the case. 71. do { } while ([condition])
Just the basic data types
Guarantees it will execute
which are not objects.
once even if [condition]
64. break
isn't met.
Put that when you want to
57. [x].toString()
leave the loop/switch;
Will convert [x] into a string. should be at end of case. 72. printf("%[type] stuff
here bah bla", [variable
here])
58. 65. default [value]:
This will let you use
[number].parse[numbertyp
This will do stuff if none of [variable here] with %s
e]([string])
the cases in the switch being where.
statement was made.
Ultimate Java Quick Reference - CodeWithHarry
73. System.out.printf([text]) This will get how long
something is, text, amount
Another way to print? //
of indexes in array, etc.
didn't quite get but ok then

80. Arrays.copy0f([array],
74. [type] [returntype]
indexes);
[name]([parameters]) {
This will copy the array and
This is a way to create a
how many indexes into
method.
another array.

75. [type][[indexes]]
81. Arrays.toString([array])
This will create an array
Convert the whole array
with [indexes] amount of
into one huge string.
indexes; default infinite.

82.
76. int[] something = new
Arrays.binarySearch([array],
int[20];
[object])
This will just make an array
This will search for [object]
of ints with 20 ints in it.
in [array].

77. for ([object]


[nameOfObject] :
[arrayOfObject]) {

This will iterate through all


of the arrayOfObject with
object in use incrementing
by 1 until done.

78. [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

79. .length
Scanned with
ECG3

You might also like