Upload
lekhanh
View
245
Download
13
Embed Size (px)
Citation preview
Sample Copy. Not For Distribution.
i
ICSE Simplified Java
Sample Copy. Not For Distribution.
ii
Publishing-in-support-of,
EDUCREATION PUBLISHING
RZ 94, Sector - 6, Dwarka, New Delhi - 110075 Shubham Vihar, Mangla, Bilaspur, Chhattisgarh - 495001
Website: www.educreation.in
_____________________________________________________________________________________________
© Copyright, Authors
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted, in any form by any means, electronic, mechanical, magnetic, optical, chemical, manual, photocopying, recording or otherwise, without the prior written consent of its writer.
ISBN: 978-1-5457-0289-5
Price: 525.00
The opinions/ contents expressed in this book are solely of the authors and do not represent the opinions/ standings/ thoughts of Educreation or the Editors . The book is released by using the services of self-publishing house.
Printed in India
Sample Copy. Not For Distribution.
iii
ICSE Simplified Java With BlueJ for Class X
Kunal Banerjee
BCA, MSC.IT
Jamshedpur-831011 (Jharkhand)
EDUCREATION PUBLISHING (Since 2011)
www.educreation.in
Sample Copy. Not For Distribution.
iv
Sample Copy. Not For Distribution.
v
About The Author
KUNAL BANERJEE is software professional in FLANDEZ
SOFTWARE SOLUTION with more than 5 years of experience in
software design.
More formally, he graduated from Sikkim Manipal University with an
MSC.IT degree in computer science. He holds multiple professional
certifications like honors in Hardware & networking, Visual studio.net,
SAP basis, CCNA, RHCE.
Apart from work, he enjoys serving the community. Work for community
service through his employers for corporate social responsibility
programs. He was organizing free seminars in Government schools as for
motive of basic fundamental computer education.
He is an active speaker, counselor on a variety of subjects in all fields.
This Biography was provided by the author or their representatives.
Sample Copy. Not For Distribution.
vi
Sample Copy. Not For Distribution.
vii
Dedication
This book is dedicated to MAA, BABA, BHAI (Mrinal), Ankita (Priyo)
&
To everyone who wonders if I am writing about them.
Sample Copy. Not For Distribution.
viii
Sample Copy. Not For Distribution.
ix
The book is written strictly according to the syllabus prepared by council for the Indian school
certificate Examination. However this book will also help the beginner to understand the basic
concept of java.
Sample Copy. Not For Distribution.
x
CONTENTS
S.No. Content Page No.
About BlueJ 1
1. Object oriented Programing (OOP) 9
2. History and Development of Java 20
3. Concept of Data types in Java 31
4. Operators and expression in java 52
5. Java – Loop Control 68
6. Java- Decission Making 102
7. Using Library Classes 125
8. Wrapper Class 141
9. String manipulation in java 147
10. Array 178
11. Functions/Methods 207
12. Constructor 236
13. User Define Data Types 249
14. Encapsulation and Inheritence 261
ICSE question bank (2014-2017) 272
Practice Questions 291
Sample Copy. Not For Distribution.
Kunal Banerjee
1
ABOUT BLUEJ ______________________________________________________________________________
Before we learn java we should know about bluej and about its features.
What is Bluej?
Bluej is an integrated development environment or we can say it‘s a platform to develop java
programs. Bluej is basically used for educational purpose but it can also be used by small scale
software development firm.
BlueJ is developed to support the learning and teaching of object-oriented programming, and its
design differs from other development environments as a result. This software application helps
to provide a more precise interface for creating projects and coding in Java.
HISTORY BEHIND DEVELOPING BLUEJ
In late 90‘s Michael Kolling developed a pedagogical language and environment called Blue as
part of his PhD work. It was first released in the year 1999. BlueJ is based on the Blue system.
Blue is an integrated teaching environment and language, developed at the University of Sydney
and Monash University, Australia. BlueJ provides a Blue-like environment for the Java
language.
Previous team members of BlueJ include:
Phil Stevens
Marion Zalk
Poul Henriksen
Cecilia Vargas
Bruce Quig
Damiano Bolla
Andrew Patterson
Clive MilleR
John Rosenberg
The current staff includes:
Michael Kölling
Ian Utting
Davin McCall
Neil Brown
Amjad Altadmri
Fabio Hedayioglu
Sample Copy. Not For Distribution.
ICSE Simplified Java
2
Features of BlueJ:
1. BlueJ is having a smaller and simpler interface unlike NetBeans or Eclipse. This allows
beginners to get started more quickly without any difficulties.
2. BlueJ is designed for teaching with good pedagogy in mind. There are many textbook written
on the BlueJ.
3. Interactive BlueJ allows us to interact with objects. we can inspect their value, call methods
on them, pass them as parameters and more. we can also directly invoke Java expressions
without compiling.
4. Portable BlueJ runs on Windows, Mac OS X, Linux and other platforms which run Java. We
can also run BlueJ directly from our flash drive without any installation.
5. Innovative BlueJ has several features not seen before in other IDEs. Its object bench, code
pad, and scope colorings were all original BlueJ features.
SCREENSHOTS
SPLASH SCREEN
Sample Copy. Not For Distribution.
Kunal Banerjee
3
To create a new project follow the below steps:
1) Open BlueJ
2) Click on project on menu bar
3) Click new project from drop down list
4) A look in box will open click on folder name.
5) Enter the project name.
6) Click create.
CREATING NEW CLASS
Sample Copy. Not For Distribution.
ICSE Simplified Java
4
To create a new class follow the below steps:
1) Click on new class button.
2) A dialogue box will open enter class name in the text box.
3) Click ok.
While doing naming to your class I recommend you to please follow the Camel case rule.
What is Camel Case ?
Camel Case is a naming convention in which a class name is formed of multiple words that are
joined together as a single word with the first letter of each of the multiple words capitalized so
that each word that makes up the name can easily be read.
Example: If you want to give a name sum digit to your class then you can write it as: - SumDigit
Is it necessary to follow camel case rule?
No it is not necessary to follow java camel case rule but as a programmer we should obey the
rules of the java that has been documented.
DIFFERENCE BETWEEN JDK AND JRE
We have heard about JDK and JRE before. We know that before installing BlueJ we need a JDK
to be installed to run our program on the computer where we are going to develop the application
software.so let us elaborate these two things in details.
JDK: - JDK stands for Java development kit. The acronym itself defines the meaning that it is a
development kit use to develop the application software as well as applets. The JDK actually
consist of JRE + development tools (libraries, compiler, loader, archives) etc…..
The developer that develops software‘s doesn‘t only build the software, they also need to run that
software on their machine to check for the errors before delivering to the client so the JDK is
accumulated with JRE.
So we can say JDK= JRE + development tools.
It is to note that JDK is purely made for Java developers.
JRE: - JRE stands for java runtime environment. When a developer build a software and it is
being delivered to the client then the client computer don‘t need JDK because client is not going
to develop a software .Client is only responsible to run that software. So to run the software the
client needs a JRE that provide an environment to run the java applications. We know that java
works on byte code and JVM is responsible to run the program so we can say that:-
JRE = JVM + Java Packages + runtime libraries.
So we can download JRE separately to run on our computer. You don‘t need JDK to make JRE
available for your computer.
Sample Copy. Not For Distribution.
Kunal Banerjee
5
Let‘s discuss about some input and output syntax of java.
OUTPUT STATEMENT:
Whenever we write a program we need to display something on our output screen. The output
can be any number, character or String. But we should always keep in our mind that whatever
the output we get it is always a string. which means it‘s a group of character or may be a simple
character but it will always be in the form of string.
The output statement can be written in two different forms:
System.out.print():- when we need an output on the same line without moving the cursor to the
next line after producing the result we use these function.
Example:- System.out.print(“HI FRIENDS ”);
System.out.print(“WELCOME TO JAVA”);
OUTPUT: - HI FRIENDS WELCOME TO JAVA
System.out.println():- This function is use to pass the cursor to the next line of the screen after
producing the first result.
Example:- System.out.println(“HI FRIENDS ”);
System.out.println(“WELCOME TO JAVA”);
OUTPUT:- HI FRIENDS
WELCOME TO JAVA
While writing System.out.print() or println() always write the System‘s S in capital letter. In java
everything which belongs to class are always start with capital letter.
System.out.print():- System is a class.
out is a static object member.
print() or println() is a method used to print the string as line
Sample Copy. Not For Distribution.
ICSE Simplified Java
6
INPUT STATEMENT USING STREAM READER
Package to be use:- java.io.*
Here io means input/output. io.* is an input output package that is very essential to run a java
program. It is a built in package that has to be imported using the import command.
TAKING INPUT THROUGH BufferReader
Java has two kinds of classes for input and output (I/O): streams and readers/writers.
Streams (InputStream, OutputStream and everything that extends these) are for reading and
writing binary data from files, the network, or whatever other device.
Readers and writers are for reading and writing text (characters). They are a layer on top of
streams, that converts binary data (bytes) to characters and back, using a character encoding.
Reading data from disk byte-by-byte is very time taking. One way to speed it up is to use a
buffer instead of reading one byte at a time, we read a few thousand bytes at once, and put them
in a buffer, in memory. Then we can look at the bytes in the buffer one by one.
We can say a buffer is a temporary storage area within a memory.
Streams: Streams are flows of data you can either read from, or write to. Streams are typically
connected to a data source, or data destination, like a file, network connection etc.
HOW TO USE BufferedReader:
You should declare a bufferReader to store the data values at the time of execution along with
the IOExecption with a main function.
Public static void main (String args []) throws IOException
{
InputStreamReader read=new InputStreamReader (System.in);
BufferedReader in=new BufferedReader (read);
}
Sample Copy. Not For Distribution.
Kunal Banerjee
7
Syntax to accept values using BufferedReader:
1) To accept an integer value
int a=Integer.parseInt(in.readLine());
2) To accept floating value
float a=Float.parseFloat(in.readLine());
3) To accept a double data type value
double a=Double.parseDouble(in.readLine());
4) To accept a character data type value
char a=(char)(in.read());
5) To accept a String value
String a=in.readLine();
Why we should learn Java Programming Language
1) Java is Easy to learn
2) Java is an Object Oriented Programming Language
3) Java has Rich API
4) Powerful development tools e.g. Eclipse , Netbeans
5) Great collection of Open Source libraries
GERNERAL QUESTION & ANSWER
Q1) Why is BlueJ not being displayed in
Windows 7?
ANS:- The latest version of BlueJ is known
to work in Windows 7. Version 3.1.0 is
optimized to run in Windows 2000, XP,
Vista or newer. Java 7 needs to be installed
for this application to run properly.
Q2) Can BlueJ work on Windows 8.1?
ANS:- Yes, BlueJ is compatible with
Windows 8.1. In fact, the developer
mentioned on its official website that the
environment is compatible with Windows
2000, XP, Vista or newer. This means you
have the possibility to install the application
along with JDK in Windows 7, Windows 8,
Windows 8.1, and Windows 10.
ANS:- Latest version of Bluej is 4.0.0.
Q4) What are the new features available
in Bluej 4.0.0?
ANS:- The new features available in java
version 4.0.0 are as follows:-
1)it adds tabbed editors,
2)automatic error-checking,
3)adds display of multiple errors and has
most of the BlueJ interface rewritten into
JavaFX.
Q4) what is javaFX?
ANS: - JavaFX is a set of graphics and
media packages that enables developers to
design, create, test, debug, and deploy rich
client applications that operate consistently
Q3) What is the latest version of Bluej?
across diverse platforms.
JavaFX Script works with integrated
Sample Copy. Not For Distribution.
Kunal Banerjee
8
development environments such as
NetBeans, Eclipse and IntelliJ IDEA.
Q5) How do I clear the terminal?
ANS: - You can also clear the terminal
programmatically from within your
program. Printing a form feed character
(unicode 000C) clears the BlueJ terminal,
for example:
System.out.print('\u000C');
This will work in the BlueJ terminal, but is
not guaranteed to have the same effect in all
terminals.
*****
GUIDE TO INSTALL BLUEJ
Download Bluej form website:- https://www.bluej.org/ (official website)
Installation
Windows:
1. Double-click the install file (bluej-309.msi).
2. This will run a standard installation. Follow the instructions on screen.
The installer will install the executable bluej.exe. Execute this to run
BlueJ.
3. When executing BlueJ you might get dialog from the firewall asking you
whether you want to block or unblock BlueJ; we recommend that you
choose not to block BlueJ.
4. If you have more than one Java version installed, BlueJ will let you select
your preferred version the first time it is executed. This can be changed
later by running the "Select BlueJ VM" utility from the Start menu.
(.msi stands for Microsoft installer)
Sample Copy. Not For Distribution.
ICSE Simplified Java
9
Chapter 1
Object Oriented Programing (OOP) ______________________________________________________________________________
In this chapter, we will learn about basic concepts of OOPs. Object Oriented Programming is a
concept that deals with inheritance, data binding, polymorphism, Encapsulation etc.
The concept of OOPs was first implemented in the programming language Simula67. The
Program where everything is represented as an object is known as truly object-oriented
programming language.
Before going to learn about OOPs let us see that what procedure oriented approach is:
Procedural programming is a type of computer programing language which specifies a series of
well-structured steps and procedures to compose a program. Here all the codes are arranged in a
systematic order and each code get executed one after another in the form of series.
This type of approach is known as top to down approach.
Examples of procedural languages include FORTRAN, COBOL and C, which have been around
since the 1960s and 1970s.
Procedural programming is very complicated as the issue that is obvious in Procedural
Programming is that if an editing is needed to the program, the developer must edit every line of
code that corresponds to the original change in the code. An example would be if at the
beginning of a program a variable was set to equal the value of 5 and if other sub-procedures of
the program rely on that variable equaling 5 to function properly they will also need to be edited.
As more and more changes may be needed to the code, it becomes increasingly difficult to locate
and edit all related elements in the program.
Before writing a procedural program we must have a clear blueprint of our program and we
should clearly know the sequence to execute our program.
DISADVANTAGE OF PROCEDURE ORIENTED PROGRAMING
1) it is not as fast to run compared with code written in a lower-level language.
2) It struggles to handle situations in which a number of possible actions may lead to the desired
result.
3) Programmers need to specialize in a specific procedural programming language, because
each language is suitable for a certain type of application and it is difficult to learn them all.
Diagrammatic representation of procedural programing:-
Sample Copy. Not For Distribution.
Get Complete Book
At Educreation Store
www.educreation.in
Sample Copy. Not For Distribution.
Sample Copy. Not For Distribution.