Overview of JAVA Language
1.INTRODUCTION
Java is a general-purpose , object oriented programming language. We can develop two types of Java programs:
i) Standalone applications
ii) Web applets
2. SIMPLE SYNTAX
The best way to learn a new language is to write a few simple example programs and execute them.
- Case Sensitivity − Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.
- Class Names − For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word’s first letter should be in Upper Case.
- Example: class HelloWorld
- Method Names − All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word’s first letter should be in Upper Case.
- Example: public void main()
- Program File Name − Name of the program file should exactly match the class name
3. CONSTANTS
Constants in Java refers to fixed values that do not change during the execution of program.
i) Integer Constants : It refers to sequence of digits . There are three types of integers namely decimal integer , octal integer and hexadecimal integer.
ii) Real Constants : Integer numbers are inadequate to represent quantities that are very continuously , such as temperatures , prices , heights etc. These numbers are represented by fractional parts like 12.234. Such numbers are called real comnstants.
iii) Single Character Constants : It contains a single character enclosed within a pair of single quote marks. Example : ‘3’ , ‘a’ , ‘;’ .
iv) String Constants : It contains a single character enclosed within a pair of double quote marks. Example : “hello” , “2000” , “7+5” .
4. VARIABLES
A variable is a name given to a memory location. It is the basic unit of storage in a program.
- The value stored in a variable can be changed during program execution.
- A variable is only a name given to a memory location, all the operations done on the variable effects that memory location.
- In Java, all the variables must be declared before use.
There are three types of variables in Java:
TYPES OF VARIABLES:
- local variable
- instance variable
- static variable
5. DATA TYPES
Data types specify the different sizes and values that can be stored in the variable. There are two types of data types in Java:
- Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and double.
- Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.
6. OPERATORS
i) Arithmetic Operators
Java arithmatic operators are used to perform addition, subtraction, multiplication, and division. They act as basic mathematical operations.
ii) Unary Operator
The Java unary operators require only one operand. Unary operators are used to perform various operations i.e.:
- incrementing/decrementing a value by one
- negating an expression
- inverting the value of a boolean
iii ) Assignment Operator
Java assignment operator is one of the most common operator. It is used to assign the value on its right to the operand on its left.
iv) Relational Operator
Relational operators are used to check the relationship between two operands. For example,
// check is a is less than b
a < b;
Here, >
operator is the relational operator. It checks if a is less than b or not.
It returns either true
or false
.
v) Logical Operator
Logical operators are used to check whether an expression is true
or false
. They are used in decision making.( logical AND , logical OR, logical NOT).
vi) Ternary Operator
Java Ternary operator is used as one liner replacement for if-then-else statement and used a lot in Java programming. it is the only conditional operator which takes three operands.
vii) Shift Operators
In Java, an operator is a symbol that performs the specified operations. In this section, we will discuss only the bitwise operator and its types with proper examples.
viii) Bitwise Operator
Bitwise operators in Java are used to perform operations on individual bits. For example,
Bitwise complement Operation of 3535 = 00100011 (In Binary)~ 00100011
________
11011100 = 220 (In decimal)
Here, ~
is a bitwise operator. It inverts the value of each bit (0 to 1 and 1 to 0).
TYPES OF BITWISE OPERATOR
There are six types of the bitwise operator in Java:
- Bitwise AND
- Bitwise exclusive OR
- Bitwise inclusive OR
- Bitwise Compliment
- Bit Shift Operators