Another cheatsheet from my Java journey.
Primitive Data Types
- byte – 8-bit signed two’s compliment integer. -128 to 127 (inclusive)
- short – 16-bit signed two’s complement integer. -32768 to 32767 (inclusive)
- int – 32-bit signed two’s complement integer. -2^31 to 2^31 – 1
- long – 64 bit signed two’s complement integer -2^63 to 2^63 – 1
- float – single-precision 32-bit IEEE 754 floating point – fractional numbers for 6 – 7 decimal digits
- double – double-precision 64-bit IEEE 754 floating point – fractional numbers for up to 15 decimal digits
- boolean – true or false
- char – 16-bit unicode character. ‘\u0000’ to ‘\uffff’
Signed vs Unsigned
A signed binary number uses the first bit to determine the sign of the number; positive being 0 and negative being 1. Unsigned binary numbers use the first bit as a part of the actual number. This means unsigned binary numbers cannot store any negative numbers, but it can store bigger positive numbers. Here is a better explanation.
Class
Blueprint of individual objects.
Overloading Constructor
The need to initialize an object in different ways.
Inheritance
Classes can be derived from other classes, inheriting fields and methods from those classes.
Overriding Methods
You can override superclass methods.
Notes:
- You cannot override superclass methods if they are labeled final.
- You cannot extend a class labeled final.
Error Handling
All errors and exceptions are under the Throwable class. Errors are related to the virtual machine finding issues such as loading a class when it doesn’t exist. Exceptions fall into two types; Runtime and Checked. Runtime exceptions often represent errors in programs such as a NullPointerException. Checked exceptions will have the compiler validate if things exist before it will build. Exceptions are part of a method’s contact and any class using it is responsible for catching any checked exceptions that might occur; otherwise the compiler will complain if it does not find it being caught when it traverses through the call stack.
Happy coding!