IT112 M2L1,2,3
an attribute associated with a piece of data that tells a computer system how to interpret its value.
data type
two types of data type
primitive data type and non primitive data type
specifies the size and type of variable values, and it has no additional methods.
primitive data type
It includes byte, short, int, long, float, double, boolean and char.
primitive data type
are called reference types because they refer to objects.
non primitive data type
Examples of these are Strings, Arrays, Classes, Interface, etc.
non primitive data type
data types are called reference types because they refer to objects.
non primitive data type
are predefined (already defined) in Java.
primitive data type
types are created by the programmer and is not defined by Java (except for String).
non primitive data type
can be used to call methods to perform certain operations
non primitive data type
type starts with a lowercase letter
primitive data type
types starts with an uppercase letter.
non primitive data type
There are eight primitive datatypes supported by Java. Primitive datatypes are predefined by the language and named by a keyword.
byte short int long float double boolean char
Primitive number types are divided into two groups:
integer types and floating point types
stores whole numbers, positive or negative (such as 123 or -456), without decimals.
integer types
represents numbers with a fractional part, containing one or more decimals.
floating point types
The byte data type can store whole numbers from -128 to 127. This can be used instead of int or other integer types to save memory when you are certain that the value will be within -128 and 127:
byte
data type can store whole numbers from -32768 to 32767:
short
data type can store whole numbers from-2147483648 to 2147483647. In general, the int data type is the preferred data type when we create variables with a numeric value.
int
data type can store whole numbers from -9223372036854775808 to 9223372036854775807.
long
This is used when int is not large enough to store the value. Note that you should end the value with an "L":
long
data type can store fractional numbers from
3.4e−038 to 3.4e+038. Note that you should end the value with an "f":
float
data type can store fractional numbers from
1.7e−308 to 1.7e+308. Note that you should end the value with a "d":
double
data type is declared with the boolean keyword and can only take the values true or false:
boolean
data type is used to store a single character. The character must be surrounded by single quotes, like 'A' or 'c':
char
data type is used to store a sequence of characters (text).
string
must be surrounded by double quotes:
string
Any constant value which can be assigned to the variable is called as literal/constant.
java literals
are used to represent a decimal, binary, or hexadecimal value.
integer literals
are used to initialize variables of integer data types byte, short, int and long.
integer literals
is used to represent value for a float and double variable or constants.
floating point literals
is composed of a sequence of decimal digits followed by either a decimal fraction, a decimal exponent, or both.
floating point literals
have only two values, true or false
boolean literals
is represented as a single character surrounded by single quotes.
character literals
represent multiple characters and are enclosed by double quotes.
string literals
Apply the declaration and initialization of Java variables in solving real-world problems.
variables
is a name which is associated with a value that can be changed.
variables
are containers for storing data values. It is assigned with a data type. It is a name given to a memory location. And it is the basic unit of storage in a program.
variables
System.out.println()
Appends a newline at the end of the data output
true
System.out.print()
Does not append newline at the end of the data output
true
constitute the basic building block to any programming language.
java operators
Java divides the operators into the following groups:
arithmetic rational bitwise boolean assignment operator
operators are used in mathematical expressions in the same way that they are used in algebra.
arithmethic operators
operators also known as Comparison Operators are used to check for relations like equality, greater than, less than. They return Boolean result after the comparison.
rational operators
which can be applied to the integer types, long, int, short, char, and byte. works on bits and performs bit-by-bit operation.
bitwise operators
also known as Logical Operators are used to perform logical “AND”, “OR” and “NOT” operation, i.e. the function similar to AND gate and OR gate in digital electronics.
boolean operators
are used to assign values to a variable.
assignment operators