1. Mathwhiz India
A Programming module for beginners
Java 1.0 with application
and game development
tutorials
Conceptualized, designed and developed by:
Mathwhiz India
An initiative by graduates of IIT, IIM and BITS Pilani
dedicated to generate youth’s interest in Programming
and Mathematics.
reimagining education
And I thought
It was
difficult !
Let’s learn Java in a playful way
2. A transformed way of learning by providing comic
appearance to a theory book
This is a book having explanation of every single term used
that might seem new and strange to you
A module on the simplest language possible with back to
back counter questions and answers to clarify every single
doubts that might come to your mind while going through
A journey that transforms your dream to reality, that makes
your passion worth pursuing and gives you a stand in this
competitive environment
Step by step explanation of making own games and
applications
Have a look at
what the book
has to offer!!
A game played by five characters to teach you every basic
concept of programming
A solution to the problem that young graduates are facing
due to not having a prior knowledge of programming
3. PREFACE
This book is a revolutionary attempt to exceed the regular pattern of
learning. Keeping in mind the importance of 21st century skills, we are
introducing the most interactive and easy to understand book for the
beginners in the field of programming. Efforts have been made to help
students master programming in a very exclusive and engaging way. We
have introduced fun elements, cartoon characters, doubts, questions
and explanations that maintain the interest of students. Technical
detailing, erudite language and incomprehensible vocabulary is avoided
to make the book student friendly.
The response and feedback from the readers across the country helped
us recognise the problems faced by students in learning a programming
language. Extensive efforts have been made to simplify and present the
content in the most user-friendly way. The book is designed by experts
to help students navigate and conquer the territory of programming.
Good luck in you expedition!
4. Views of trendsetters towards programming
“Learning to write programs stretches your mind, and helps you
think better, creates a way of thinking about things that I think is
helpful in all domains.”
Stephen Hawking
Theoretical Physicist, Cosmologist,
and Author
“Whether you want to uncover the secrets of the
universe, or you just want to pursue a career in the 21st
century, basic computer programming is an essential
skill to learn.”
Steve Jobs
Cofounder, Chairman, and CEO
of Apple Inc.
“Everybody in this country should learn to program a
computer, because it teaches you how to think.”
Mark Zuckerberg
Co-Founder and CEO,
Facebook
“Everyone can learn programming logic, even the primary school kids.”
BillGates
Chairman, Microsoft
Dr. Larry Corey
President, Fred
Hutchinson Cancer
Research Center
“Computers are an increasingly essential part of
understanding cancer and developing new therapies.
Knowledge of computer programming is almost as important
as knowledge of anatomy when it comes to medical research
or clinical care”
The following are the comments on programming by great successful people
who have shaped the world. They are people from different fields supporting
our claim that says “Programming is needed no matter in what field you are”.
5. Views of brands towards this initiative of
Mathwhiz India
Knowing how to program make kids think
computationally and understand and tinker
the world that they are living in. It is essential
that we constantly innovate and while
everyone has ideas, what shall separate those
who will make them a reality is simple: the
ability to code. Coding is an emerging
language and this initiative believes in
investing this in future.
Deepesh Bharani
B.Tech, Computer Science, IIT Delhi
Quantitative Researcher at
WorldQuant
Nice idea. I believe an initiative like this can go
a long way in increasing programming skills and
awareness among kids. A lot of students today
opt for Computer Science, B.Tech without
having a real interest or even being aware of
what it’s about. This can potentially provide
them with good exposure to the same.
Dravyansh Sharma
B.Tech, Computer Science, IIT Delhi
Software Engineer at Google
Computers are already everywhere and
affecting every single part of our lives.
Over the next 10 years, there will be 1.4
million jobs requiring knowledge of
programming and only 400,000 of
students who will graduate with computer
science degree in the period. The world is
changing and its time we catch up with it.
B.Tech, Computer Science, IIIT Hyderabad
Software Engineer at Facebook
Co-founder InterviewBit
A child’s brain is very agile, thus making it a place
where creativity evolves. In order to create new, one
should know the current ones to its depth. Similarly,
coding helps in activating the brain of a child to
transform their ideas into innovation.
Alfateh Mustafa
BCA, Christ University
Network Operation Centre
Engineer, LinkedIn
8. T
b L
a
e
of
ContentsTeam introduction 1
What is programming? 4
The basic operation in a computer 4
Importance of programming 5
The depth of programming 6
What is algorithm 7
What is the necessity of learning programming in schools 8
Let’s start with the types of programming language 8
What is Java 9
Why Java 11
What would you able to do after learning this language 11
Programming recipes 12
History of Java 14
Versions of Java 14
Features of Java programming language 15
Java as a platform independent language 16
Java Virtual Machine (JVM) 17
Java programs 18
Integrated Development Environment (IDE) 21
Object 22
Object Oriented Programming language 23
Class – a basis of all computations 23
Character Set 25
Tokens 26
Data Types 32
Syntax of writing programs 38
Operators 46
Programming section 57
Loop in Java 79
Make your own application 87
Make your own game 90
Have patience, we
will discuss every
topic in detail!!
9. Hello students !!
My name is Mr. Head. I am here to teach
you the programming concepts with the
help of a game. In the game there are
several players playing different roles. Let
us begin with the introduction of all the
players participating in the game.
Hey Dexters !!
I am the wisest player in the game. Since
you know that wise people speak less but
their words are gems, so whenever I
speak, listen to it carefully for it can be an
important lesson. I am also known as the
“Do you know baba”
Hello Folks !!
I am the one who will always be there to
assist you with your doubts or questions. I
speak a lot and therefore people usually
call me the speaker.
Hello Pals !!
My job is to give you the basic
introduction of all the new concepts. So to
understand the subject, you need to
follow me at each and every step. I am
playing the role of a teacher.
Hello Students !!
Meet me; I am a confused student just
like you who doesn’t have any idea of the
programming concepts. So here I am in
the game. As my teacher says that if I
follow him till the end, I will also become
a learned person like him.
Java 1.0
Mathwhiz India An Initiative to change Indian programming culture
P a g e | 1
10. These are the four players of the game who will surely
make your learning of the programming concepts fun
and memorable. So get ready for the journey students,
you will have a great time ahead.
Mathwhiz India An Initiative to change Indian programming culture
Java 1.0 P a g e | 2
11. Yesterday I met one of my friends; he showed me his
smartphone having many varied games and applications. I
asked him how are these cool applications created? He
replied that they are all designed using computer
programming.
My dad showed me a website on which anyone can book railway tickets,
movie tickets, order online food and can do many other interesting things.
I was astonished and when I asked him about the technology behind the
creative world of websites, the reply I got was the same, that they all are
designed with the help of programming codes.
I have been using my computer for quite a long time
but never inquired about the core technology using
which everything in the computer works
automatically. I asked my brother how the
computers work. He informed me about the
programmed chips inside the computer.
Whenever I ask anyone about the technology behind the functioning of most
of the computing devices, I get the same answer that it is all done using
computer programming. Now will someone please tell me what this
programming is?
Mathwhiz India An Initiative to change Indian programming culture
Java 1.0 P a g e | 3
12. Programming is a process of writing computer programs
which contains instructions for the machine or computer
to perform a task automatically. It is an innovative process
done by programmers to instruct the machine/computer
on how to perform a task.
Programming can be inferred as the instruction to a computer on how to
perform a specific function like running games, playing videos and other tasks.
Suppose you are teaching a man prepare tea. You will tell him to put some
water and milk in a kettle and add sugar and tea leaf. In the same way in order
to calculate two numbers you instruct the computer to bring the two
numbers, take one and add another to it and display the result.
The basic operation in a computer
ProcessInput Output
Mathwhiz India An Initiative to change Indian programming culture
What is programming?
The basic operation in a computer is getting the input, processing it and
producing the output and programming is the main thing behind this
processing.
Java 1.0 P a g e | 4
13. The world has changed due to programs. There has been a lot
of automation introduced in almost everything around us.
Programming has completely transformed the world. It has made different
complex tasks simple, efficient and far less time consuming. The offline
markets and transactions have been transformed to online shopping & selling,
money order to online banking or ATM and telephone culture to texting and
video chatting.
Programming has not only changed social life but medical sciences as well.
Now a days, most of the machines are programmed to give accurate and
human error free results.
For example, Programmed Pacemakers, Robotic health check up’s, wrist health
bands, Diabetes check up devices, inoculation modulating device and many
other devices which you may have not heard about but definitely will as you
grow up and learn.
The world of space has become accurate and advance due to programming of
machines in Airplanes, Fighter jets, Rockets and many advance automated
telescopes which are searching for the life on other planets of the universe.
It is the programming which has developed a system to control “ Mars Rover-”
of its own on the land of Mars which is doing research and analysis on the
planet in every aspect which is impossible for a Human to do with that pace
and accuracy.
Mathwhiz India An Initiative to change Indian programming culture
Importance of programming
Java 1.0 P a g e | 5
14. So now since you have understood the importance of
programming, let us understand the interconnection of
programming and our real world. Like it was mentioned
earlier, you can also program for a table fan. So how do
you do it? Suppose you want a table fan to be controlled
with the help of a mobile phone. How would you do that?
You simply design a chip, write the code and voila! It is done. And the best
thing of this is, you can use Java as your language.
The new generation has every dependency on codes. The ATM machines have
programs. The cell towers have it. Also to note, the ease of making a program
can be made is astonishing. You can relate every code to a real world
example.
Oh ! So this is the use of programming in our real world. Now
I can say that every technology in our world is somehow
linked to programming. But how are the codes? Is it very
difficult and time consuming?
The depth of programming
Programming can be of hundreds of thousands of lines
or simply a 5 lines of codes. Different kind of work
requires different set of codes to perform different
action. Programming is nothing but steps to do a task
automatically. You can program to predict the weather
or to calculate the probability to become the richest
person in the world. It just takes your ability and mind
to relate different things to each other and create
something that is innovative.
In programming the most important thing is the algorithm that determines
the path of the written programs.
Mathwhiz India An Initiative to change Indian programming culture
Java 1.0 P a g e | 6
15. What is Algorithm
A finite set of
procedures/formula/steps/instru
ctions written in a sequence to
solve a problem. It must have
recognizable set of stopping
point.
We use algorithm every day. In
the simplest term, algorithm is
the step by step technique of
performing any task. Algorithms
can be expressed in any
language, from natural
languages like English, Hindi,
French etc. to programming
languages like Java.
Do You Know??
Muhammad ibn Musa Al-
Khwarizmi developed the
concept of the algorithm in
mathematics (called as the
father of Computer Science by
some people). Today, people
use algorithms to do addition,
long division etc., principles
that were found in Al-
Khwarizmi were text written
about 1200 years ago.
So now you have understood the importance of
programming, let us start learning a programming language.
No, I have heard that programming is very vast and
tough to learn. Is it necessary to learn programming in
school?
Mathwhiz India An Initiative to change Indian programming culture
Java 1.0 P a g e | 7
16. What is it necessary to learn programming at schools
• Programming can be called as the language of the
present world
• The coding culture of the world is on the rise
• Every field like engineering, medical or commerce is
somewhat related to programming and it would
potentially be better if you have initialized it at an
early stage
• Capability of learning and innovation are more at a
younger age
• It is difficult to have commands on a language in a
short period of time
• Programming is not that difficult to learn
All right teacher, if it is so important, I am ready to learn
programming.
Programming
language
Imperative
Procedural eg.
C
Object
Oriented eg.
Java
Declerative
Functional eg.
Haskell
Logic eg.
Prolog
Let’s start with the types of programming language
Mathwhiz India An Initiative to change Indian programming culture
Java 1.0 P a g e | 8
17. In imperative programming language one needs to provide a step by step
solution to the question “what is to be done?”.
• Procedural eg. C
• Object Oriented eg. Java
Declarative: In declarative language, there is only a need to express what one
wants without specifying the procedure.
• Functional eg. Haskell
• Logic programming language eg. Prolog
You will learn the details of other different languages later on but firstly we
will concentrate on one particular language.
So if there are a lot of different programming languages
which language shall we start with?
We will start with Java, the most important and
commonly used programming language. Let me give
you an introduction to this language.
What is Java?
A common purpose programming language designed to create or produce
programs that will run in any computer system. Java allows you to play games,
to chat with people at different distances, view videos and images in 3D and a
lot more things. There are millions of websites and applications that run with
Java programming language.
Mathwhiz India An Initiative to change Indian programming culture
Java 1.0 P a g e | 9
18. Do You Know??
As per
2014 data
in all over
the world
9 million Java
Developers
1 billion Java
downloads
per year
3 billion
devices run
Java
97% of
enterprise
desktops run
Java
89% of
Desktops (or
Computers)
in the U.S.
run Java
125 million
TV devices
run Java
Yes sir, I understood that the language Java is of great
importance. But what is the reason behind Java being so
popular and successful as a language? There must be
something behind the popularity of this language.
Mathwhiz India An Initiative to change Indian programming culture
Java 1.0 P a g e | 10
19. Why Java?
Unlike other programming language such as C, C++,
the programs in Java don’t interact directly with the
computer Central Processing Unit (CPU) or the
Operating System (OS) and therefore Java is platform
independent meaning they can run on any personal
computer, workstation or any mainframe computer.
What would you be able to do after learning this language?
Every language acts as a medium to communicate. For example English, Hindi,
French, German etc. are languages used for communicating to people of
similar social group but if you are aware of English language, you can say that
it is famous and known to almost every part of the world.
Java is just like the English language of Computer Race that is famous, easy
and very effective to use in any part of the Programming language.
It is the language that gives key to develop Android Applications, Robot
Programmes, Games and many other things that are used to give instruction
or command or a way to communicate between machine and human.
Let us go through some of the recipes of programming language
and some of the terms used frequently in programming
vocabulary.
Mathwhiz India An Initiative to change Indian programming culture
Java 1.0 P a g e | 11
20. What is syntax?
Syntax is rules and symbols for validating the programming language that is
just like the Grammar of language English.
What do you mean by compiling and interpreting a program?
Programmers/users/people write a program in a form called source code. This
source code is basically a high level language that needs to be converted to
object code for the computer to understand the program. This process of
converting source code into machine code is called as compiling a program
which is the function of a compiler. The compiler also checks whether there is
an error in the language of any form and returns the error message after the
whole program is compiled. After making the program error free, a separate
executing command is given to run the program.
Programming recipes
The interpreter basically serves the same purpose as compiler but it directly
executes the program rather than first compiling and then executing leading
to the consumption of lesser time. The interpreter converts high level
language into machine language line by line executing it simultaneously
stopping the translating process the moment it finds the first error. For
example: it translates the first line then execute it if there isn’t any error. Then
it moves to the second line and then to the third and so on. The moment it
finds an error it stops then and there and doesn’t proceed until it gets
corrected.
Mathwhiz India An Initiative to change Indian programming culture
Java 1.0 P a g e | 12
21. Hello students !!
Going through the introduction of programming,
you must have realized the importance and the
advantage of learning the language. Moving on in
the next chapter, you will learn more about Java
programming language and at the end of it you
will be able to write simple and interesting codes.
So stay tuned with the team and enjoy the
learning process.
Mathwhiz India An Initiative to change Indian programming culture
Java 1.0 P a g e | 13