Java - Session 1 867480 279015
Java - Session 1 867480 279015
Objectives
The student will understand the following things :
Java - Session 1 1
What is a computer program?
Java - Session 1 2
If someone knows Japanese, then he/she can only communicate with another
person only if they also know Japanese. For communication, we need a common
language through which I can put my request and others will interpret that. If a
german person talking to a French person then it is not possible to communicate
unless they have something known as a translator.
Even the people who don't have any ability to speak, use sign language for
communication. If the other side doesn't know the same language then
communication is not possible.
Java - Session 1 3
A program is something like the language of a computer which a computer
understands. There are many different programming languages like C, Java,
Python, Javascript, etc. Through Program, we can tell computers which task we
want to perform. In our daily life, we use applications to perform some tasks like
VLC for watching videos, Excel Sheet for documents, Skype for video calling, etc.
Every application in its core is a computer program, which is giving a nice beautiful
interface through which we are communicating with the computers.
Coding Environment
If you know any programming language then we can communicate with the
computers but there is one more thing which is also needed that is the coding
environment. Coding Environment is something on which we use to write and
execute our programs.
Suppose If you are hungry, then we generally use to call our mother. If I am able to
communicate to my mother that I am hungry and I need food. For ex: you are
Java - Session 1 4
desiring to eat idli, dosa, pav-bhaji, etc then my mother will understand what I
actually want.
But to make this request successfully complete, Language is not just enough, we
also need a kitchen where my mother can cook the food. Assume If I am on a trip
with my family, During the travel, I put the desire of eating and I ask my mother to
cook something then in that case it is not possible because there is no kitchen or
you can say that there is no suitable environment.
In programming terms, writing Java code in a text editor will not work, because Java
environment is not there.
Setup Replit
Go to https://replit.com
Now choose Node.js and it will open a window asking you to create a repl and Now
press create repl.
A new window will open, On the left side, you will find the code editor and on the
right side is the terminal where we can see our output.
Try a test code: System.out.println("Hello World") and a press run, the output will be
displayed on the right.
Variables
Let's try to understand with a story
There was a child who once decided to leave his home and move to some
different place. He does his packing.
Java - Session 1 5
There was a lot of stuff which needs to be packed. So, What he did, He arrange
some boxes and In each box, he used to put some set of things Forex: Pictures,
Shoes, Shirts, pillows, books, toys, etc.
For Identification, He marked each box with a name Like a box containing pictures
have the name pictures, the box which contains books marked as books, etc.
We relate this story with the concept of variables, The boxes are considered as
variables where you can put your set of things.
Java - Session 1 6
The variable is storage locations with assigned names.
Need of Variable
Different customers who log in to Amazon, Flipkart, or Facebook should see their
name on the top, not a fixed name.
It is like a box holding different values depending on who is visiting and logged in to
the website.
In the frontend, Using Forms we use to take the values for different variables like
Facebook signup form carrying different variables like name, age, etc.
Java - Session 1 7
Apart from the customer's name, a website may also need to know customer's age.
This would be another variable "custAge".
While custAge is also a variable but it holds a number, not a word (called a string in JS).
Variables can have different "data types".
Datatype
We are using different types of containers to store different things. While the bottle
can hold milk or water or juice, it will hold only liquids. Similarly, a variable of
type string (like the variable - custName), can store only strings and a variable of
type number (like the variable - custAge) can store only numbers.
The type of data a variable can hold is called its Data type. It may be number,
string, boolean, etc. (A variable of type Boolean can either be True or False)
Java - Session 1 8
How to declare a variable?
int x = 2;
String y = "masai";
double z = 4.5 ;
Java - Session 1 9
Java variable names must start with a letter, or the $ or _ character
After the first character in a Java variable name, the name can also contain
numbers (in addition to letters, the $, and the _ character)
Variable names cannot be equal to reserved key words in Java. For instance, the
words int or for are reserved words in Java. Therefore you cannot name your
variables int or for .
Java - Session 1 10