Computer Applications - BASIC JAVA CONCEPTS (Part-1)
Computer Applications - BASIC JAVA CONCEPTS (Part-1)
Concepts of OOP’s
Object: An entity with a specific identity and having specific characteristics and specific behaviour.
Class: It’s a blueprint representing a set of objects that share common characteristics & behaviour.
Data Abstraction: The act of representing essential features without including the background details or
explanations. It hides the internal details.
Encapsulation: The wrapping up of data and functions (that operate on the data) into a single unit (called
class) is known as Encapsulation. Encapsulation is a way to implement data abstraction. It hides the
details of the implementation of the object. It enables access restriction to a class members and
methods by making them public, private or protected.
Modularity: The act of partitioning a program into individual components (modules) is called Modularity.
Inheritance: It is the capability of one class of things to inherit or derive capabilities or properties from
another class.
Polymorphism: It is the ability of the objects to take on many forms.
Polymorphism is achieved through 1. Overloading and 2. Overriding.
Two type of Overloading: 1. Function overloading and 2. Operator overloading
Byte code: It is an intermediary code produced by the Java Compiler after compiling the Java Program.
JVM (Java Virtual Machine): JVM is the interpreter which interprets the byte code into the native
executable code for a particular machine.
Every Java program is first compiled into byte code by the Java Compiler and then interpreted into
machine code by JVM. Hence, Java is both compiled and interpreted based language.
Literals: These are data items that have fixed data values.
1. Integer Literals – Whole numbers
a. Decimal Form – starts with a non-zero number (Eg: 10, 434, 2, 54452)
b. Octal Form – starts with a zero (Eg: 04, 056, 076) (Only valid octal numbers)
c. Hexadecimal Form – starts with a 0x (Eg: 0xC, 0x34, 0xFA)
d. Binary Form – starts with 0b or 0B (Eg: 0b111, 0b1010, 0B10110)
2. Floating-point Literals – Numbers with fractional points or decimal points
a. Fractional Form – Eg: 9.34, 0.000045
b. Exponent Form – Eg: 0.36E-3, 0.0934E2
3. Boolean Literals – It takes either true or false value
4. Character Literals – Single character or escape sequence enclosed within single quotation
Eg: ‘a’, ‘3’, ‘\t’
5. String Literals – One or more characters enclosed within double quotation marks
Eg: “Avg”, “abc”, “Everest”, “Emp22”
6. Null Literal – It represents null reference and written as null.
Identifiers: Identifiers are user-defined names given to various program units of Java. Example – Names to
variables, methods, classes, packages, interface, etc.
Identifier Naming Rules:
1. It should start with any alphabet or _ underscore or $ dollar and can be of any length.
2. It must not be a Java keyword or Boolean literal (true, false) or null literal (null).
3. It can contain number but not in the beginning.
4. Java is case sensitive. i.e. upper case is different from lower case.
5. Except _ underscore and $ dollar symbol no other special characters are allowed.
Variables: It is a named memory location, which holds a data value of a particular data type.
Constants: A constant value represents a named value that remains fixed throughout an entire program.
Data Types: Data type defines the type of data a variable can hold and the operations that can be
performed on it.
Primitive data type is used to define and hold a value of basic type in a named variable.
Reference data types are created using the primitive data types. It is used to store the
memory address of an object.
Data Types
Classes
Numeric Non-numeric
Interface
Integer Boolean
Arrays
byte Strings
boolean
short
int
long
Floating-
point
float
double
Character
char
Operators: Operators are nothing but symbols which denotes a certain operation. The variables or values
on which the operation is performed is called as Operands.
Eg: a+b is an expression, where a and b are operands and + is an operator.
Types of Operators:
# Types Operators Name Example
1 Arithmetic Operators + Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division (Quotient) a/b
% Modulation (Remainder) a%b
2 Relational Operators (or) > Greater than A>b
Comparison Operators < Lesser than A<b
>= Greater than or equal to A >= b
<= Lesser than or equal to A <= b
== Equal to A == B
!= Not Equal to A != B
3 Logical Operators && Logical And A > B && A > C
|| Logical Or A > B || A > C
! Logical Not !A
4 Shift Operators >> Signed Right shift A >> 2
<< Signed Left shift B << 4
>>> Unsigned Right shift A >>> 2
5 Bitwise Operators & Bitwise AND 1&1
| Bitwise OR 1|0
^ Bitwise XOR 1^1
~ Bitwise NOT (Complement) ~1
6 Assignment Operator = Assignment operation C = 22
7 Arithmetic Assignment Operators A += B
+= A=A+B
(or) Short hand Operators
-= A=A–B A -= B
*= A=A*B A *= B
/= B=B/C B /= C
%= D=D%C D %= C
Other Short hand Operators &=, |=, ^= Bitwise Assignment Operators
>>=, <<=, >>>= Shift Assignment Operators
8 Increment / Decrement Operators A++ (Postfix)
++ Increment
(Prefix – Change-then-use) ++A (Prefix)
(Postfix – Use-then-Change) A-- (Postfix)
-- Decrement
-- A (Prefix)
9 Conditional Operator (or) Ternary
?: For simple if…. else C = 26 > 34 ? 5 : 32;
Operator