Ideal for learning the basics of java, and can also be used as a school project for class 10 and 12. The document contains illustrative pictures, and carefully selected information to make the basics of java strong. Pls ignore small spelling mistakes made.
1. Page 1 of 22
COMPUTER PROJECT
Created By: Prarabdh Garg
Standard: X-A
Roll Number: 9
Topic: A program on Cricket
2. Page 2 of 22
CERTIFICATE
This is to certify that Prarabdh Garg of class X has
successfully completed a project on the topic “A
program on cricket” prescribed by Mrs. Vaishali
Bhirud, during the academic session 2015-16 as per the
guideline issues by Indian Certificate of Secondary
Education.
Internal Examiner External Examiner
3. Page 3 of 22
ACKNOWLEDGEMENT
I, Prarabdh Garg, would like to extend my heartfelt
gratitude towards my computer teacher, and my principal for
givingme anopportunitytowork on thisproject. Thisproject not
only helped me unleash many new horizons in the field of
programing, but also helped me in knowing more about the
subject.
I would also like to thank my parents and my friends who
encouraged me towards working on this project and to do my
best. It wasonlybecause of them that I wasableto complete this
project with wonderful learning.
Internal Examiner External Examiner
4. Page 4 of 22
CONTENTS
I. Object Oriented Programing Concepts
II. Introductionto a Class
III. Functions
IV. Constructors
V. Class as A User Defined Type
VI. Decision Making
VII. Iterations
VIII. Using Library Classes
IX. Encapsulation
X. Arrays
XI. Input/output
XII. The program on cricket
XIII. The Output
5. Page 5 of 22
Object Oriented Programing Concepts
here are two ways of organizing a program.
One is around the approach, known as the
process oriented model. The other way is
around its data, and is known as the Object Oriented
Model. Java is an Object oriented model, in which
objects can be considered as a partitioned area of
the computer memory to store and access data.
OBJECTS
An object is a software bundle of variables and
related methods. They have a state and a
behavior, and resemble real-world objects. The
state and behavior of objects are expressed in
the form of variables and methods.
T
6. Page 6 of 22
CLASS
A class is a prototype which defines the variables
and methods common to all objects of a certain
kind.
7. Page 7 of 22
INTRODUCTION TO A CLASS
s we know, Java is an Object Oriented
Program, made up of several basic elements.
These are:
Whitespaces: There are no special indentation
rules in Java.
Identifiers: Symbolic names used for various
data items in a program.
Keywords: Reserved words which convey a
special meaning to the compiler
Constants: A data item whose value cannot be
changed throughout the program. They are also
known as literals
Comments: Remarks from a programmer which
are ignored by the compiler.
A
8. Page 8 of 22
Operators: A symbol or a letter which makes the
compiler perform specific operations on
operands in a program.
OPERATORS
Arithmetic
Binary Unary
Relational Logical Assignment Tertiary
9. Page 9 of 22
1-Everyone canaccess 2-Name of the class 3-Cannotbe accessedwithoutobject
4-Noreturn type 5-Functiontoprinta statement
6-What to print 7-To terminate astatement
11. Page 11 of 22
FUNCTIONS
unctions are sub-programs within the main
program, whose main function is to process
and return data. The syntax for defining a
function is:
[Access specifier][Static][return type] name of
program(parameters)
{
//Body of the function
}
Classification of Functions
1. Predefined functions: These are functions
which are already available with the java
package and can be used by importing the
package.
F
12. Page 12 of 22
2. User defined Functions: These are functions
defined by the user within the program to
perform a particular task.
3. Pure Functions: These are functions generally
contain a return statement, and their main use is
to provide or print values. They do not
manipulate the values.
4. Impure Functions: These are functions which
manipulate the data and also provides the new
values to the program.
Overloading Functions
The process of having two or more functions with the
same name but different parameter declaration is
known as function overloading. Function
overloading is one of the ways in which java
implements polymorphism. The number and types
of arguments passed are used to decide which
function would be invoked.
THE ‘this’ KEYWORD
The ‘this’ keyword can be used inside any method
to refer to the current object.
13. Page 13 of 22
CONSTRUCTORS
ava allows objects to initialize themselves when
they are created. This automatic initialization of
objects during their creation is done by a special
function of the class called constructor.
The syntax for defining a constructor is:
classname()
{
statements;
}
Characteristics of constructors
1. Every constructor has the same name as that of
the class.
2. It has no return type, but can accept arguments
3. A class can have more than 1 constructor.
4.Default constructors don’t accept parameters
J
14. Page 14 of 22
Types of constructors
1.Parameterized Constructor: Constructors that
can take arguments are known as parameterized
constructors.
2. Copy Constructor: When we create a new
object with the same state as that of another
object, a copy constructor is created.
3. Default Constructor: This constructor is one
which cannot take any arguments, and its only
function is to set the values to null.
15. Page 15 of 22
CLASS AS A USER DEFINED CLASS
Wrapper Classes
rapper classes form a part of standard
library of Java.lang package which
provides many methods to help
manipulate primitive data types.
The chief wrapper classes with their functions are:
1. Integer class(Integer.): parseInt(), valueOf(),
toBinaryString(), toOctalString(), toHexString(),
toString()
2. Character class(Character.): isLowerCase(),
isUpperCase(), isDigit(), isLetter(),
isWhitespace(), toUpperCase(), toLowerCase()
3. Double class(Double.): parseDouble(),
toString() , valueOf()
W
16. Page 16 of 22
DESCISION MAKING
t may be required in a program to cause the flow
of execution not to advance in linear sequence,
but branch to some statement, based on changes
to the state of a program. These can be catagorised
as selection, iteration and jump.
Selection Statements
Selection statements allow the selective execution of
statements, enabling decision and subsequent
selection of some of the several possible actions.
Some of the selection statements are:
If switch case
if-else ternary operator
if-else-if
I
17. Page 17 of 22
ITERATONS
terations or loops help in repeatedly executing a
set of statements, until a termination condition is
met. The two types of loops are:
1. Entry Control: In these loops, the test
expression if first checked, and then the
statements are evaluated.
2. Exit control: In these loops, the statements are
executed, and then the test expression is
checked. The minimum number of iterations is
one.
The three main loops, which are the most widely
used are:
1. For Loop(Entry Control)
2. While Loop(Entry Control)
3. Do while Loop(Exit Control)
I
18. Page 18 of 22
USING LIBRARY CLASSES
he built-in functions which are used by the
programmer are stored in their respective
classes, present in their respective packages.
These functions provide the basic functionality of
Java.
Methods in String class
The methods that are present in the String class
helps in manipulating String data in many ways.
Some of the methods that are present include
length(), trim(), charAt(), equals(),
equalsIgnoreCase(), and may others.
Methods in Math class
The methods that are present in the Math class helps
the programmer to use complicated maths problems
simple. It includes random(), ciel(), floor(), round(),
toRadians(), along with many other methods.
T
19. Page 19 of 22
ENCAPSULATION
ncapsulation is an OOP principle the binds the
code and data, keeping it safe from outside
access and misuse. It acts like a protective
covering that prevents the code from being accessed
from outside.
Inheritance
Inheritance is another basic OOP principle, which
enables one class to acquire attributes and behavior
from its super class.
The three types of inheritance are:
1.Simple Inheritance
2.Hierarchical Inheritance
3.Multi-level Inheritance
E
20. Page 20 of 22
ARRAYS
n array can be defined as a set of homologous
data elements sorted in a contiguous
memory location. A specific element in an
array can be accessed by its index. The first element
has the index 0, and it increases by one for each
subsequent element.
Creating an array
To create an array, the syntax is:
Datatype [] variable name=new data type[array size]
As with declarations for variables of other types, the
declaration of an array variable does not allocate any
memory to contain the array elements. We must
assign a value to the array variable before the name
of the variable refers to a memory location.
A
21. Page 21 of 22
INPUT / OUTPUT
ava employs the notion of a stream as an
abstraction for all possible data sources. A
stream might be receiving bytes from or sending
bytes to a file, a String object, a keyboard, etc. The
main characteristics of a stream are:
Sequence of bytes
Contain either binary or character data
For reading, an input stream is used
For writing, an output stream is used
If a stream has buffer memory, it is known as
Buffer Stream
The two main types of streams that are used are:
1.Bytes Stream: This stream takes the input or
displays the output in a package of 8 bits, or a
byte.
2. Character Stream: This stream takes the input,
or shows the output through characters.
J
22. Page 22 of 22
BIBLOGRAPHY
Books:
1.Total Computers for class X
2.Understanding Computers class X
Websites:
1. www.javapoint.com
2. www.tutorialpoint.com
3.www.wikipedia.com