Computer Application Update
Computer Application Update
CHAPTER – I
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING
Programming language:- The sequence of set of instruction of any programmng language
used to find the solution of a problem is known as programming language. The programming
language are commonly divided into two parts:
System Programming Language:- These programming languages are used to write system
program or system software or an operating system.
The Object – Oriented programming is a programming methodology that helps to organize set
of instruction in a proper sequence to develop program or software.
Advantages:
It implements code Reuse and Recycling concept; which means the objects created for Object
Oriented Programs can easily be reused in other programs.
Categorized as:
What is an object?
An identifiableentity with some characteristics, a state and behavior is known as an Object.
OR
An object is self – contained entity that contains attributes and behavior. The object can be
an item, place, person or any other entity.
Example:-
. Red, Green, Yellow, Blue etc.
What is class?
A class can be a blue print or template of thought for multiple objects with similar feature. It
is a collection of similar type of objects.
Example:-
Characteristics of Object
i) Identity:- The name by which an object is recognized is known as identity. E.g. pen,
laptop, CD etc.
ii) State:- It refers to whether an object is in processed or unprocessed state. E.g.
computer may be in any state : On state, Off state, Out of order state.
iii) Behavior:- This refers that what an object is capable of doing.
i) Abstraction ( Data Abstraction ):- The act of representing the essential features of an
object without knowing its background details.
Example :- We only are pressing certain switches according to our requirement, what
is happening inside, how it is happening etc. we not know.
Data Hiding: The property which does not allow the data and its function to be used
as public interface is known as data hiding ( or information hiding ).
ii) Encapsulation: The wrapping up of data and methods into a single unit is known as
Encapsulation. Example, The TV is considered as single unit that encapsulate many
program.
iii) Inheritance:- The act of process of acquiring the properties from an existing class by
another class is known as Inheritance.
Base class:- The existing class whose properties are inherited by some other class is known as
Base class or Supper class or Parent class.
Derived class:- The class that acquires the properties from existing class is Derived class or sub
class or child class.
A
Advantages of Inheritance:-
Polymorphism:- More than one function with same name and unique parameter when present in
a same class is known as function overloading. Such concept is known as Polymorphism.
TABLE
An object is self – contained entity that contains attributes and behavior. The object can be
an item, place, person or any other entity.
Example:-
}
}
CHAPTER -2
INTRODUCTION TO JAVA
Java environment has a number of development tools hundred of libraries. All the
development tools are the part of system known as Java Development Kit ( J. D. K.).
APPLICATION PROGRAMMING INTERFACE:-
Classes and methods are the part of Java Standard Library (J. S. L.), which are also called
Application Programming Interface( A. P. I.).
Applet program:- The Java applets that runs within a web browser. These are mainly used for
internet programming. An applet is capable of performing many task on a web page. Applets
are also used to create animation, displaying graphics, playing sounds, accepting user input
and interactive games.
Stand Alone Application:- A stand- alone application refers to a Java program that can run
independently on a computer.
Byte Code:- The Java program are both compiled and interpreted. The compiler translates the
source code to an intermediate level language called Byte Code. It is independent of the
machine on which the program runs. The byte code file can be used any system.
The Java run-time system or virtual machines that translates or interprets byte code into
machine code is known as Java Virtual Machine.
Source Code:- The set of instruction and statements written by computer programmer using a
programming language to find the solution of a problem is known as source code or program.
Object code :- The machine language program produced after the compilation of the source
code is known as Object Code.
Characteristics of Java
Platform Independent:- It is a platform independent language which means the change of
environment or platform, the Java program will not be affected.
Write Once Run Anywhere(W. O. R. A):- It means the program written in Java can be
successfully executed in platform without any change.
Object Oriented Language:- It support OOP concept i.e. Data Abstraction, Encapsulation,
Inheritance and Polymorphism. Which enables easier and convenient program development.
Simple Coding:- The Java coding is simple which does not require complex instruction.
User Friendly Envornment:- It can also be used by the novice user with fundamental
programming concept.
Java is Robust:- The Java has features of automatically memory management and garbage
collection along with strong exception handling mechanism that makes it Java Robust.
Secure Environment:- The Java language supports many strong in – built security features
that makes the system secure from crash.
Types of Errors:-
Syntax Error:- Violation of any grammatical rules causes syntax error and it is also known as
compilation error.
Run Time Errors:- The runtime errors occurs during execution of program. The runtimes are :
Dividing a number by zero, Array index out of bound, Arithmetic error like square root of
negative number, range errors and other input errors.
Logical Errors:- Logical error are the result of wrong logic of program. For example, if the
problem is to calculate sum of two numbers instead of it gives product of two numbers.
2. Identifiers:- Identifiers are fundamental building blocks of a program and are used to
name different components of a program. E.g. name of function, variables, class,
object etc.
Rules for naming Identifier:
i) An identifier can consists of any combination of letters, digits,
underscore character, dollar sign($).
ii) An identifier cannot begin with a digit.
iii) Identifiers can be of any length.
iv) Uppercase and lowercase will be treated distinctly
v) It should not be keyword.
Numeric literals:-
Integer Literals:- Integer literals are value, which represent whole numbers only. They can be
positive or negative values. The integer value that contains no sign represent a positive value by
default.
Rules:-
Comma not allowed
Spaces not allowed
No other character are allowed
From following find out which are valid and which are invalid Integer constant. If invalid,
write why?
From following find out which are valid and which are invalid real constant. If invalid, give
the reason:
From following find out which are valid and which are invalid exponent form. If invalid,
write why:
Data type:- To identify the type of the data involved in an operation is known as data type.
OR
The means to recognize or identify an entity / entities and their operations are known as data
type.
TYPES OF DATA TYPES
.i. Primitive /Intrinsic / Built – in / Fundamental / Basic Data Type
Primitive Data Type:- The fundamental data types that are an integral part of the Java
programming language are called Primitive data type.
The primitive data types can be grouped into the following four categories:
Integer Data Type:- Integer data type are used to store whole numbers. For example 345, -323,
1000. There are further four types of integers in Java. These are byte, short, int and long. The
values that can be stored in these depends on which data type is being used in the program.
Type Size in bits Size in byte Range
byte 8 bits 1 byte -128 to 127
short 16 bits 2 bytes -32,768 to 32,767
( - 215 to 215 – 1)
int 32 bits 4 bytes -2 billion to +2 billion ( approx)
-231 to 231 – 1
long 64 bits 8 bytes - 9 E 18 to + 9 E 18 ( approx )
-263 to 263 - 1
Floating point Data Type:- The floating point data type are used to store fractional number i.e.
numbers with decimal values. Floating point data types can be further divided into float and
double data type.
Type Size in bits Size in bytes Range
float 32 bits 4 bytes 3.4 E -38 to 3.4 E +38
Upto 7 significant decimal digits
double 64 bits 8 bytes 1.7 E -308 to 1.7 E +308
Upto 15 significant decimal digits
Character Data type:- In Java, characters are stored using char data types. This data types
supports the Unicode character set. The character data type occupies 2 bytes ( 16 bits ) in the
memory.
Boolean Data type:- The boolean data types is used for logical values. There are only two
values a boolean data type can have true or false. It occupies 1 byte ( 8 bits ) in the memory.
Although a Boolean data type needs only one bit of storage, the java compiler reserves 8
bits = 1 byte for it.
Non Primitive Data Type:- The data types that are derived from the primitive types are called
non – primitive types. They are also known as reference types, derived types or composite data
types. There are three non-primitive types in Java: classes, arrays and interfaces.
Variables Initialzation:-
Symbolic Constant:- The final keyword is used to convert a variable and its value into
constant. It is known as symbolic constant.
Syntax:-
Final data_type variable= literals or value;
e.g. final float PI= 3.1412;
Type conversion:- It’s a process that converts a value of one data type to another data type.
There are two forms of Type Conversion in Java : Implicit and Explicit Conversion.
Implicit Type Conversion:- The conversion performed by Java compiler to convert data type is
known as Implicit Type Conversion or Automatic Type Conversion or Coercion or Type
promotion. The Java compiler generally converts all operand on the basis of data type of
largest operands.
Example:- Suppose there are following variables:
byte b; int a,c; float f, g, h; double d, e;
Assume that expression e = ( a + b ) * ( c – g ) – ( f + h ) – d is to be evaluated
e=( a + b ) *( c - g ) - ( f + h ) - d
int byte int float float float
int float float double
float
float
double
Explicit Type Conversion:- The process of converting an operand to the user defined data type
is known as Type Casting or Explicit Type Conversion. In other word force fully conversion of
one data type to another is known as Explicit type conversion
Eg. int x=68;
char ch = ( char ) x;
OPERATORS AND EXPRESSION:-
Expression:- An expression in Java is any valid combination of operators, constant and
variables i.e. legal combination.
Operators:- An operator is a symbol that tells the computer to perform certain mathematical or
logical manipulation. Operators are used in program to manipulate data and variables. They
usually form a part of mathematical or logical expression.
Types Of Operator:-
1. Arithmetic operator
2. Relational operator
3. Logical operator
4. Assignment operator
5. Increment and Decrement operator
6. Conditional operator
7. Bitwise operator
8. Special operator
Arithmetic operator
There are five arithmetic operator:-
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo division ( to get remainder )
Example
i. a + b .ii) a - b .iv) a * b/5 .iv) a % b
.i) x = a – b / 3 + c * 2 – 1
.ii) x = a – b / ( 3 + c ) * ( 2 – 1 )
Where a = 9, b = 12 and c = 3
a) a b – c
b) ( m + n ) ( x + y )
ab
c)
𝑐
a
d)
𝑏𝑐
e) 3 x2 + 2 x + 1
x
f) + c
𝑦
Types of arithmetic
1. Integer Arithmetic
2. Real Arithmetic
3. Mixed – Mode Arithmetic
Integer Arithmetic:- In an expression when all the operands are of integer
types, the expression is called and integer expression and the operation is called
integer arithmetic. Integer arithmetic always gives an integer values.
Suppose a and b are integer with a = 14 and b = 4 then we have the following
results:
a – b = 10 a + b = 18 a * b = 56 a/b=3 a%b=2
Note:- For modulo division the sign of the result is always the sign of
numerator.
- 14 % 3 = - 2 - 14 % ( -3 ) = - 2 14 % ( - 3 ) = 2
Real Arithmetic:- In an expression when all the operands are of real types, the
expression is known as real arithmetic. It always gives a real value.
Suppose value of a and b are double type with a = 20.5 and b = 6.4
1. ½ * 10 * 20
2. 1.0 /2 * 10 * 20
3. 1 / 2.0 * 10 * 20
4. 0.5 * 10.0 * 20.0
5. 15 /10
6. 15/ 10.0
7. 15.0/ 10.0
Syntax:-
Value Value
Or Or
Variable Relational Operator Variable
Or Or
Arithmetic expression Arithmetic expression
Relational Operator:
Logical Expression:- Two or more relational expression with logical operators make a logical
expression. Logical expression always gives boolean values.
Syntax:-
&& AND
|| OR
! NOT
State the output of the following:
a) 7 > 5 || 5 > 7
b) 5 + 3 > 7 || 7 > = 4 + 3
c) 3 = = 5 && 5 = = 5
d) 3 > 1 || 0 < - 5
int x, y, z;
x = 9;
y = 7;
z = x + y;
Short hand assignment operator:-
Java offers special short hand that simplify the coding of a certain type of assignment
statement.
1. p = p + d 2. c = c - 20 3. t = t * 0.5 4. d = d / 10 5. e = e / 2
e. g. c = ( a > b ) ? a : b;
In this statement, the value of a is assigned to c only if the given condition is true, otherwise b.
Nested Ternary Operator:- Ternary operator within ternary operator is known as nested
ternary operator.
( int ) ( i + f ) / ( j * d );