Primitive data types are predefined types that are used when declaring a variable or literals.
8 Types
================================
1. byte
- it has range from -128 to 127
- default value = 02. short
- it has a range from -32768 to 32767
- default value = 03. int
- it has a range of -2e31 to 2e31 - 1
- this is a whole number.
- default value = 0
- usually, we use base 10 numbering system. This is our normal counting. Binary, octal and hexadecimal is also allowed in case you might need it.4. long
- it has a range of -2e63 to 2e63 - 1
- default value = 0L5. float
- it has higher range than int and you use this in decimal values but you cannot use this in currency.
- default value = 0.0f
- you can use e for exponents6. double
- it has higher range than float and can use with decimal values but you cannot use this in currency.
- for currency, you need to use the java.math.BigDecimal
- default value = 0.07. boolean
- it has two possible values which is true or false
- default value = false8. char
- 16 bit unicorn character
- it has a range from '\u0000' or 0 to '\uffff' or 65535
- default value = '\u0000'
- you can use this \u or sometimes called the unicode escape
- you need to use single quotation for the char value apart from String which is double quotation.
- char letter = 'z'java.lang.String
- this is an array of characters but does not belong to the 8 primitive data types.
- default value = nullJava.math.BigDecimal
- this is used for precise calculation of numbers.Literals
- this is the opposite of variables
- the value is fixed.Special escape sequences for character and strings
==============================
\b - backspace
\t - tab- line feed
\f - form feed
\r - carriage return
\" - double quote
\' - single quote
\\ - backslashYou can use underscore to separate numbers for readability.
Example:
==≈====≈======================public static void main(String[] args){
System.out.println("HELLO");
}===================≈===========
Result:
H
ELLO
YOU ARE READING
Java Programming
Randomhttps://docs.oracle.com/javase/tutorial/ This is the link where I learned my java lessons online. I choose java as first programming language. I am a career shifter. I just want to start something new. I choose to write it here in Wattpad so that I...