JAVA. Data Types. Data types are very important in every language for storing and manipulating date. Java Provides eight simple types of data which can be grouped into four groups. 1. Integer 2. Floating Point Numbers 3. Characters 4. Boolean. Integer Types. Floating Point Numbers.
An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
Characters Character data type is used to store single UNICODE character. Unicode character set is 16 bit character set. The standard set of ASCII characters still ranges from 0 to 255. NOTE : char data type is unsigned type.
Boolean Java has a simple type called boolean, for logical values. It can have only one of two possible values.
The variable is the basic unit of storage in a Java program. A variable is defined by the combination of a type, variable name and an optional initializer. In java all variables must be declared before they can be used. int a = 4; Initializevalue Type Name
Some variable declarations examples: - 1. int a = 3; 2. int x,y,z; x = 4; y = 6; z = 3; 3. char c = ‘a’; 4. boolean b = true; 5. double d = 44.4, v = 43.3;
NOTE : All the integer types are considered int type by default. All the floating point types are considered double by default.
Identifier Identifiers are used to name variables, classes, interfaces, methods, and other Java language elements. An identifier is a sequence of characters that starts with an underscore (_), a dollar sign ($), or a letter (ASCII or Unicode). Subsequent characters may contain these characters plus the digits 0 through 9.
Expressions An Expressions can be thought of as a programmatic equation. More formally, “An expression is a sequence of one or more operands and zero or more operators that produce a result. “ e.g. X = y / 3; A = 4 + 3 * 3/2;
Increment and Decrement Operator The ++ and – are java’s increment and decrement operators. The increment operator increases its operand by one; the decrement operator decreases its operand by one.
The expression a = a + 1; can written using increment operator as: a++; Similarly the statement a = a – 1; Is equal to following: a--;
Bitwise Inversion Operator This operator performs bitwise inversion on integral types. This operator works by converting all the 1 bits in a binary to 0s and all the 0 to 1s.
For example binary representation : 01001101 Using the ~ operator convert into following 10110010 You may notice that all the 0 bits are converted into 1s and all the 1 bits are converted into 0s.
Boolean Complement Operator The ! Operator inverts the value of a boolean expression. So !true results into false !false results into true
Arithmetic Operators Basic arithmetic operators are addition(+), subtraction(-), multiplication(*), and division(/). All behave the same, as you would expect for all numeric types. Modulus(%) operator returns the remainder of a division operation.
Comparison Operator These are also called relational operators. They determine the relationship that one operand has to the other. The outcome of these operators is always a boolean value.
Bitwise Operator The bitwise operators provides bitwise AND, XOR and OR operations respectively. These operators can be apply to both integer types and boolean types. These operators compare each bit of first operand with the corresponding bit of the second
The &,^ and | behave in the same way when applied to boolean. However instead of calculating the result on a bit-by-bit basis, the boolean values are treated as single bits, with true corresponding to 1 bit and false to a 0 bit.
Short Circuit Logical Operators The short circuit logical operators && and || provide logical AND and OR operations on boolean types similar to the & and | operators. However they have a valuable additional feature.
The ability to “short circuit” a calculation if the result is definitely known. • For an AND operation, if first operand is false, the result is false without checking the other operand. • For an OR operation, if first operand is true, the result is true, without checking the other operand.
Example int a = 5; boolean b = ( (a>8) && (a==5) ); The first expression (a>8) returns false so the second expression (a==5) never executes and false is stored in b.
Example int a = 5; boolean b = ( (a>3) | | (a==2) ); The first expression (a>3) returns true so the second expression (a==5) never executes and true is stored in b.