0% found this document useful (0 votes)
5 views20 pages

Computer

The document outlines key concepts of programming, contrasting procedure-oriented and object-oriented programming, and introducing essential object-oriented principles such as encapsulation, inheritance, polymorphism, and data abstraction. It also covers Java-specific elements including data types, operators, error handling, comments, and method structures, emphasizing the importance of access specifiers and constructors. Additionally, it explains the characteristics of classes and methods, detailing how they function within Java programming.

Uploaded by

lmg.ashmitadas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views20 pages

Computer

The document outlines key concepts of programming, contrasting procedure-oriented and object-oriented programming, and introducing essential object-oriented principles such as encapsulation, inheritance, polymorphism, and data abstraction. It also covers Java-specific elements including data types, operators, error handling, comments, and method structures, emphasizing the importance of access specifiers and constructors. Additionally, it explains the characteristics of classes and methods, detailing how they function within Java programming.

Uploaded by

lmg.ashmitadas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Class IX

Procedure oriented programming. Object oriented programming.


It divides the programs into small It divides the programme into
parts known as methods. object.
It follows a top down approach. It follows a bottom up approach.
It deals with algorithm. Ideals with data.
It is less secure. It is more secure.
Example: C, Fortran. Example C++, Java.

The wrapping up of data members and member methods together into


a single unit is called encapsulation. The main objective of
encapsulation. Run estu. Smake the method safe from outside
interference and misuse, thus leading to the important concept of
object oriented programming, which is known as data hiding.

Data abstraction is the property by which the essential features of a


class are represented without informing the users about the
background details. That is, the non essential units are hidden from the
user. The main objective of data abstraction is to reduce the
complexity of the programme.

Inheritance is the method that allows one class to inherit the


properties, data members and member methods of another class.
The class from which the features are being taken are known as
the Super class, parent class, base class. The class which inherits the
properties of the other class are called the child class, subclass,
extended class, derived class.

The Greek word quality which means many and morph which means
change of forms. It is the ability of an object to take on many forms.
Polymorphism is a feature of being able to allot a different meaning to
a variable, a method or an object so they can have more than one
form. Thus it is the ability to use in operator method in different ways.

Class as the Basis of all computation.


The new is a keyword used to create the object of a class.
Object is an instance of the class. World defining a class in Java, it does
not occupy any space in memory. But as soon as an object is created
in acquired memory facing the computer. An object is the physical
existence of a class. While creating an object of a class CR basically
defining a variable. There is a size of the Super bikes. All the data
members, health and object is also called an instance of a class as it is
the same properties of a class.
Values and Types.
ASCII - American standard code for information interchange.
A to Z = 65 to 90
a to z = 97 to 122
0 or 9 = 48 to 57

Escape sequence characters are non graphical characters that is


preceded by a backslash and her special meaning for the compiler.

Token is an atomic part of a Java program that has a meaning for the
compiler and is used to execute the program efficiently. There are
various types of token. Pachas, keywords, identifiers, literals,
operators, and punctuators.
 Keywords are reserved words that are predefined in the Java
compiler for a specific purpose.
 Identifiers are the names given to different components of a Java
programme, like class variables and methods. It can be a
combination of letters and numbers, or a secret sequence of
letters. Keywords cannot be used as identifiers.
 literals are the values that can be stored in the variables.
 Operators are Special symbols that signifies the compiler to
perform some specific mathematical or non mathematical
operations or one or more operator.
 Separator The special characters used to separate the variable or
characters in a Java program.
 Punctuators are special characters in Java. Uses punctuation sign.

Type Size Default value Range of values


that can be
stored
Byte 1 byte 0 -128 to 127
Short 2 bytes 0 -32768 to
32767
In 4 bytes 0
Long 8 bytes 0L
Float 4 bytes 0.0f or 0.0F 3.4e – 038 to
3.4e +038
Double 8 bytes 0.0 or 0,0d or 1.7e-308 to
0.0D 1.7e+308
Boolean 1 byte or 1 bit False True or false
Char 2 bytes \u0000 \u0000 to \
u0041

Primitive data type Non-predicative data type


They are built in data types They are user, define data types
To use them, the use of new The use of new operator is
keyboard is not mandatory mandatory
The size of a primitive type The size of the non-tubular data
depends on its data type type may vary
Store only one single value at a The non-data types are used to
time store the group of values

Implicit type conversion takes place when two types are compatible or
the larger type is larger than the source type. It is ascending order.
The implicit data type is automatically done by the Java compiler in
implicit data conversion. The resulting data types are not specified and
are chosen by the compiler. It is a process of widening. This is also
known as Coercion.

Type version, we can assign a value of larger data type to a smaller


data type. It is a process of nano whinge. Automatic conversion is not
done here. It requires uses intervention. This is also known as type
casting.

Types of operators
 Arithmetic operators, (+, -, /, *, ++, --, %) (unary plus and unary
minus)
 relation operators, (<, >, <=, >=, ==, !=)
 logical operators ( &&, ||, !)
 assignment operators (-=, +=, *=, /=, =, %=)
 Ternary operators (condition) ? (print if true) : (print if false)
 Miscellaneous operators (dot operator and new operator)

Input in Java
Package collection of Java classes and other packages having similar
functionality

Types of packages built in in Java


 util
 lang
 io
 math

Errors in Java
 Syntax error: The errors that occurred due to violation of syntax,
role of the Java programming language are called syntax error.
Syntax errors are known as compile time errors.
 Logical error, : Sometimes there may be errors in the logic of the
program due to which the program will not give the appropriate
output. This type of error is a logical error. Logical errors are also
called semantic error.
 Runtime error: Runtime errors are occurred due to the execution
of a successfully compiled program.
Comments in Java
Comments are non-executive statements used to explain the code
such as why the variable has been used. What is the purpose of the
function et cetera? Can also be used to hide the code from the
compiler without deleting it. Commented statements are ignored by
the compiler comments are the programmer, debug any error easily.
Three types of comments.
 Single line comments : these comments are used to write one
line. It starts with //
 Multiline comments: these comments have to write more than
one line so that the logic of the court can be explained in details.
It begins with a ‘/*’ and end with ‘*/’
 Documentation comments: these comments are used to write the
documentation part of the program, which is the question about
the program, the name of the programmer, et cetera. At the
beginning of the program, they did not depict the program logic.
It starts with ass for work /** and ends with */.

Ja statements in Java
Statement is used to exit from the loop. As soon as the break
statement in a loop execute the execution will be transferred to the
next statement immediately outside the loop. This means a statement
after the break statement in the loop body will not be executed. The
break statement can be applied to all the different types of loop
Continue statement is used to control the loop by sending the control
of to the next iteration when it is executed, the current flow stops and
skipping the remaining go to the next iteration

Written statement in Java when a method is called, the control is


moved to the collar module to the method which has to return back to
the collar model. After execution of the method. This is done by the
return statement. If the method does not return any value, we have to
use the keyboard void, else, we will use the data type of the returned
valu.

Mathematical library methods


Mathematical library methods are present in the Java package in which
the maths classes is present. After importing the maths class, we can
use its methods.
Function Description Return
data
type
min(a,b) Which is the Int/ If the given numbers are of
smaller number long/ different data types and the
between a and B? float/ return value is converted to
double the higher data type
max(a, b) Returns the larger int/
number between a long/
and B float/
double
sqrt(a) Returns the square Double Works only on positive
root of a positive numbers
number
cbrt(a) Returns, the cube double Works on both positive and
root of a positive negative numbers
number
pow(a, b) returns, the value Double Works on both positive and
of a to the power B negative numbers
abs(a) Returns the int/ Always returns a positive
absolute value, long/ value, and the return type
magnitude of any float/ depends on the type of
number double argument passed to it
round(a) Returns rounded of int/long It depends on the decimal
value to the point of the number if it is
nearest integer more than 0.5 then it will go to
the next digit and if it is less
than 0.5, then it will go to the
previous digit
floor(a) Return the Double Smaller number than the
rounded value to given number
the nearest integer
ceil(a) Returns the whole Double Greater number than the
number, greater given number
than or equal to
the number
rint(a) Returns the Double If it is an even value in the
nearest integer method will return the
value of the previous integer value. If it is
fractional number, an odd value in the method
provided as an will return the next integer
argument value.
random() Returns a random Double
number between 0
to 1.
Classes the basis of all computation
Characteristics or attributes: the properties of an object at the
characteristics or attribute it is also known as the state of an object.
Behaviour of methods is the action of an object that can perform is
called it behaviour
Classes a blueprint to create several objects with the same properties
and behaviour every object of a class has the same properties and
behaviour that the class has we can create multiple objects of a class
the class is also known as an object factory.

class object

Classes in Java are non primitive data types that act is a blueprint for
creating objects of the same type in other words they are a set of
instructions to build the specific type of object and object of a class is
also called an instance and the process of feating in object is called
instantiation
Access specifiers
The private access specifier restricts accessibility of data members and
member methods within a class only this means that the data
members and member methods are preceded by access specifier
private can be accessed only within the class which they are declared
in the same package
public access specifier allows the data members and member methods
to be accessed within the class and also outside the class in the same
package.

the protected access specifier allows data members and member


methods to be accessed within the package it also allows the data
members remember methods to be accessed outside the package
through inheritance.

Instance variables are also known as non static data members these
variables are declared within the class but outside the member
methods they are created whenever an object is generated the
instance variables associated with different objects contain different
values/
class variable a class variable is also under the state static data
member it is a variable that is declared within the class using a static
keyword only one copy is created for all the objects of the class thus
having single value of the variable for all the objects.

local variables a variable that is declared within a member method is


called a local variable it can be accessed only within the method in
which it is declared we cannot use the static keyword to declare a local
variable it is necessary to initialize the local variable before using it.

member methods
a method that is declared within the class is known as a member
method it can be declared private or public.

static member methods a member that is declared within the class


using the static keyword is known as a static member method similar
to a static data member the static member method can be accessed
by using its class name a static member method only uses the static
data members.

constructors are special methods with the name which is same as that
of the class name they're also called automatically when the object is
created they used to initialize the instance of a class.

Classes in object factory a factory usually produces a product of similar


kinds similarly a class in Java also creates several objects of the same
class kind kind same kind. a class being a prototype no values can be
assigned to it directly we need to create objects of the class these
objects contain attributes and behaviors of the class thus a class is
basically an object maker.
sometimes the instance variables in the parameters passed to a
method have the same name these variables create an anomaly as
when the name is used in the program then which one will be executed
in this situation we can use the name of the instance variable
exceeded by the word this to access the instance variables this
keyword denotes the currents class object.
User defined methods.

Header of method.
When a method is declared, the first line is known as method header or
method prototype or function prototype. This line contains the access
specifier, return type, method name, and list of parameters.

Method signature.
Method signature is the part of a method header containing only the
name of the method along with the parameter list.

Since methods can be accessed by other classes, the same class or


other methods, we need to apply some restrictions in the accessibility
of the methods. This is done by the access specifier.
Access specifier or access modifier specifies the boundary for a
method in which it is accessible. There are 3 types of access. Specifier
The public access specifier allows us to give permission to a method
accessible anywhere inside the class and outside the class.
A private access specifier restricts a method accessibility outside the
class. Only the method of the same class can access a private method.
A protected access specifier. The protected is a special type of access
specifier which allows methods of the same class in inherited class can
access a protected method.

A method is used only when it is called by another method. So after


completing the assigned task, the method returns control to the
portion from where it is called.
While returning the control, a method may or may not return a value
along with it. For this purpose we require return type and return
statement. Return statement is required at the function is returning
some value. The returned value may be of any data type even non
primitive data types following other characteristics of return
statement.
It is used to return value from the method to the calling program. It is
always the last line of the method. By defaulting always returns a
single value of one data type. Only AP want to return more than one
value. We have to create a non primitive data type and return.

Return type: If the function is returning a value, then the data type of
the value is written before the function name. The different data types
used to return type are byte, short int, long, float, double, car or
boolean. We can also use string if you want to return a word or
sentence. Other than these, all non primitive data types such as. Adi
class Xtra can be used to return type. If a function is not returning any
value then the keyword void is used.

Method name.
Every method should be provided with a names that it can be called
from the same class or different classes. Method name should be a
valid identifier. The method name should be meaningful and related to
the task done by it.

Parameter list. One or more parameters are passed to a method within


the pair of parenthesis. While defining the method, there are data
types along with the variable names which are passed to the method
as parameter. These parameters are separated by a comma.
The values of these parameters are passed at the time of calling the
method in the same order in the parameters are defined in the
definition of the method. In some methods there may not be any
parameter, which may be known as an empty parameter list.

Body of the method is defined by curly brackets. Inside the curly


brackets, a set of statements are defined to perform a desired task.
When the method is called, the statements resident inside the curly
brackets are executed.

Actual and formal parameters.

Actual parameters Formal Parameters


the actual Values that are passed The values send by the calling
directly or through variables to program are received in the
the respective method at the parameters described in the
time of calling the method are method.
called actual parameters.
They are defined in the calling The parameters that receive the
program. values from the collar programme
are known as formal parameters.

Pass by value in Colby value a method is called by passing the value of


parameters. In this type of method called, the copy of the actual
parameters is sent to the formal parameters.

Pass by reference. The actual parameter on the formal parameter


shares the same location in the memory. Reference means the
memory location.

Pass by value Pass by reference


The copy of the actual The actual parameters and formal
parameters is sent to the former parameters shared the same
parameter. location in the memory.
In pass by value, any changes in In pass by reference, any change
the formal parameter will not in the formal parameter will also
reflect on the actual parameter. reflect on the actual parameter.
Only primitive data can be used Only non primitive data type can
in pass by value. be used in pass by reference.

Static and non static methods.


The word static is used before any method. Then it means the method
directly belongs to the class and not to its instance. This means it only
one copy of the method is created which is used throughout the
programme. Java supports both static and non static methods.

A non static method is also known as an instance method. The world


static is not written before the method name.

Pure and impure methods.

Pure methods. Impure methods. (mutato


Doesn't change the state of an Changes the state of an object.
object.
Returns a value to the method May or may not return a value to
from where it is called. the method from where it is
called.

Constructors.
 Special type of member method with the same name of the class.
 It doesn't have a return type, not even void.
 Used to initialise the instance variables of the class and the
object of the class.
 Constructor of a class is called every time an object of a class is
created.
 Constructors are always public as they can be called from outside
the class while creating the object of the class.
There are 3 types of constructor. Default constructor, parameterised
constructor, non parameterised constructor.
Constructor. Method.
Used to initialise the instance Used to execute the Java code
variables of a class. which performs a specific job.
Can be evoked only once, at the It can be evoked anytime as and
time of creating the object. when required.
It has the same name as that of It has a different name from the
the class. class name.
It does not have a return type, It has a return diet.
not even void.
It is always public. It may or may not be public.

Library classes.
 Java.lang - Used for string manipulations.
 Java.io - Used for input output operations.
 Java.util - Use for input through Scanner class.
 Java.math - News for mathematical operations.

* allows you to import all the characters from the Java packages when
used.
Primitive and composite data types.

Primitive data type. Composite data type.


It is a predefined data type. It is a user defined data type.
It always contains a value. It can also contain null values.
It is always starting with a lower It can also start with Either lower
case letter. case or upper case letter.

Wrapper classes are the inbuilt classes that contain primitive data
types. These classes are used to convert primitive data types into
objects and vice versa with the help of their methods.
Every wrapper class has various methods too, providing a way to use
the primitive data types as objects.
All the wrapper classes are part of the Java Lang package in the Java
library.
Need for Wrapper class.
 To allow primitive data types to convert from one data type to
another.
 To store primitive data types objects.

To use wrapper classes in our programs we need to import Java Lang


package using the import statement in the following manner.
import java.lang.*;
After importing the Java Lang package, we can use the methods of the
wrapper class in the following way.
Wrapper class name . method name()
Automatic conversion from PDF reader type to its corresponding object
classes called autoboxing. Automatic conversion of object of Wrapper
Class to its primitive data type is called unboxing.

Function Purpose
Integer.parseInt(String) It converts a string into integer
Integer.valueOf(String) form and stores it in integer
variable.
Long.parseInt(String) It converts a string into long type
Long.valueOf(String) data and stores it in a long
variable.
Float.parseInt(String) It converts string into float data
Float.valueOf(String) type and stores it in a Float
variable.
Double.parseInt(String) It converts string in 2 double data
Double.valueOf(String) type and stores it in a double
variable.

Function Description
Character.IsLetter It checks whether a character is a
letter or not. In returns true for
the given character.
Character.isDigit It checks whether a character is a
digit or not. In returns true for the
given character.
Character.isLetterOrDigit It takes whether a character is a
digit or letter. It returns true for
the given characters if it is a
character or a digit.
Character.isWhiteSpace Checks if a character is a white
space or not. It returns true if it
stores a white space. If turns
false if it return, it does not store
a white space.
Character.isUpperCase Check if character given is
uppercase or not.
Character.isLowerCase Check if a character given is
lower case or not.
Character.toUpperCase Converts the given character to
uppercase.
Character.toLowerCase Converts the given character to
lower case.
String handling

1. length()
2. charAt()
3. indexOf()
4. lastIndexOf()
5. toLowerCase()
6. toUpperCase()
7. concat()
8. substring()
9. replace()
10. equals()
11. equalsIgnoreCase()
12. compareTo()
13. compareToIgnoreCase()
14. startsWith()
15. endsWith()
16. trim()
17. valueOf()

Array handling

Genius search Binary search


It works on both sorted and It works only unsorted array
unsorted diary
It starts searching from the zero It starts searching from the
position middle and proceed either to
the left of the right, depending
on the value of the search
element

Bubble, sort Selection sort


Compares with the next Select the minimum element
element and swap with the from the unsorted part of the
condition matches area and places it in the next
position in the sorted part of the
array
Execution is slow Execution is fast
Less efficient More efficient

You might also like