Grade 8 Java Icse 8thstd
Grade 8 Java Icse 8thstd
CHAPTER 2
FAMOUS PERSONALITY
Introduction to JAVA: James Gosling, founder and lead designer of JAVA
programming language.
JAVA is a high level object oriented
programming language. It was created Worked at Sun Microsystems. He was a passionate
programmer from early graduate – student days. He
by James Arthur Gosling a Canadian
had developed P-Code Virtual Machine for his professor
computer scientist. during those days.
Features of JAVA:
1. Object oriented
2. Modular
3. Platform independent
4. Both compiled and interpreted
5. case sensitive
The building blocks of JAVA program : Object and class are the building
blocks of a java program. They are like two sides of a coin, which are
integrated with one another.
Object <h3>is a unique entity which contains data (characteristics) and
functions (Behavior) bound together.
Let us consider the chalk used to write on the black board. It is white in
colour (Characteristic). It is used to write (Behavior) on the board.
All the objects seen above are real time objects, which can be seen and their
features can be described.
All of them are having unique state (characteristics) and functions(behaviour).
Let us consider the example of book
Characteristics:
• It has brown wrapper
• It is rectangular in shape
Behaviour:
• It is used to write
• Its contents can be read
Class : <h3> Class is a group of similar objects , having similar
characteristic and behavior. Class is known as object factory as it is used
to create objects.
Let us consider the example of a Vehicle as a class. If vehicle is a class, it
can have objects like TwoWheelers, ThreeWheelers, FourWheelers.
Keywords (Reserved words): These are the JAVA tokens, that are reserved by
the language. They cannot be used to name variables.
Some of the frequently used Keywords are:
int double private next import
float String main static java
if short class case Scanner
else while void switch new
for public char break default
Table 2.1 Keywords in JAVA
Constants (Literals): It is a fixed value that does not change during the execution
of the program. Different types of literals are:
STRING LITERAL
REAL LITERAL
BOOLEAN LITERAL
INTEGER LITERAL
String literal: Alphanumeric characters and special characters enclosed with in
double quotes.
ex: “Coding is fun !!!!!!”
Character literal: An alphabet , a number or a special character stored with
single quotes .
Ex: ‘a’, ‘7’
Boolean literals: Special constants true or false.
Integer literals : Positive or negative whole numbers
ex: 23, -89
Real Literals: Positive or negative decimal numbers
ex: 34.9, -0.78
Variables (Identifiers) : It is a named memory location used to store values.
Rules for naming variables:
➢ JAVA is case sensitive, upper case and lower case letters are treated
different
➢ reserved words cannot be used as identifiers
➢ _ and $ are the only two special characters, that can be used in identifier.
But $ can be used only after the first character.
➢ Though numbers can be used, they can be used only after the first
alphabet
Types of variables:
STRING VARIABLES
REAL VARIABLES
BOOLEAN VARIABLES
INTEGER VARIABLES
REAL VARIABLES:
Named reserved memory location used to store positive or negative
decimal values/ constants. Represented by the datatype float.
Initialization:
float ans=5.9;
float cost= -0.8;
here ans and cost are float variables used to store real (decimal) values
Introduction to BlueJ :
JAVA programs are created as classes in BlueJ project. Every Class created will
have a sample program to guide the user. Bluej window looks like
Figure 2.1 BlueJ window
Steps to create a new Project
Step 1: Select Project
Step 2: Choose New... from the menu.
Step 3: A file selection dialogue opens that lets you specify a name and location
for the new project.
Step 4: Choose name for project. After you click OK, a directory will be created
with the name you specified, and the main window shows the new, empty
project as shown in Figure 2.2
Step 7 : Right Click on the object to see a drop down menu, choose the second
option void main() to execute the program
Figure 2.8 Object creation
Step 8: The output appears on the output window as shown in Figure 2.9
KNOW MORE
Applet is a small Java program that can be embedded
into a web page. It runs inside the web browser , can
be accessed on an Internet server, transported over
Internet, and can be automatically installed and run as
apart of a web document.
Applets run on web browser or an applet viewer. JDK
provides a standard applet viewer tool called applet
viewer.
Demonstrate the concept of Object and Class in comparison with real life
examples.
Lab exercises:
Write the JAVA program and the output generated for the following
1. To calculate the amount payable by accepting cost of the product and
number of products purchased.
2. Display the Biodata by accepting the name, age and school from the
user.
3. Accept a number and display its Square and Cube.
4. Accept the marks obtained by a student in 5 different subjects.
Calculate the percentage of marks obtained.
Online Links:
to download JDK
https://download.cnet.com/Java-Development-Kit-64-Bit
to download BlueJ
https://www.bluej.org/