You are on page 1of 5

HIMAMAYLAN NATIONAL HIGH SCHOOL

TVL – ICT/COMPROG
COMPUTER PROGRAMMING
Programming – Why? Volatile Memory – is memory that when it loses power,
Computers are used for many different purposes in many the contents are erased.
different situations. But, how can they be so versatile?
Secondary Storage
Answer: They can be programmed
Secondary Storage is memory that can hold data for a long
-The ability for a computer to be programmed allows it to
period of time.
do whatever their programs tell them what to do.
Programs are usually stored in secondary storage and
-A program is a set of instructions that tell a computer
loaded into main memory as needed.
what to do.
This forms a hierarchy typically called the memory
-A computer cannot do anything unless it has a program
hierarchy.
to tell it what to do.
Common forms of secondary storage:
Hardware and Software  Hard Drive
Programs can also be called software.  Disk Drive
Software refers to the computer programs that a  Solid State Drive
computer uses to complete a task.  Removable Storage
Hardware refers to the physical components that a  Floppy Disk
computer is made of.  CD-ROM
A computer is not one device, but a system of devices  USB Drives
working in tandem. Each device plays a part. Other files can be stored in secondary storage:
Major components:  Documents
 Central Processing Unit  Pictures
 Main Memory  Whatever else you save on your computer
 Secondary Storage Devices Input Devices
 Input Devices Input is any data the computer collects from the outside
 Output Devices world.
Central Processing Unit (CPU) An Input Device is anything that collects data and sends it
The CPU is the heart and brain of the computer. to the computer.
The CPU continuously does the following things: Common Input Devices:
 Fetch an instruction  Keyboard
 Follow the instruction  Mouse
 Produce some resulting data  Scanner
The CPU has two parts:  Digital Camera
Control Unit - Coordinates the computer’s  Disk Drive
operations Determines where to get the next instruction  USB Drive
Regulates the other major components of the computer
Arithmetic and Logic Unit (ALU) - Designed to Output Devices
perform mathematical operations. Output is any data the computer sends to the outside
world.
Main Memory An Output Device formats data and presents it to the
Main memory holds information that the CPU needs to outside world.
access quickly. Namely, the instructions to be executed. Common Output Devices:
When a program is running, some or all of its instructions  Monitor
are in main memory.  Printer
Memory is divided into sections called bytes that hold  Disk Drive
equal amount of data.  USB Drive
Each section is made up of 8 bits.
A Bit is the most basic unit of information a computer can Software
hold. It is a switch that is either on (1) or off (0) Software refers to the programs that run on a computer.
Each byte is assigned and can be accessed by its address. Two main categories (for this class):
A Memory Address is a unique identifying number  Operating System (OS)
associated with a byte in memory. A set of programs that manages a computer’s
Main memory typically is volatile. hardware devices and controls their processes. Most
modern operating systems are capable of running multiple Assembly language (ASM) is also a type of low-
programs at once. UNIX, Linux, Mac OS X, and Windows level programming language that is designed for specific
are examples processors. It represents the set of instructions in
a symbolic and human-understandable form. It uses an
 Application Software
assembler to convert the assembly language to machine
Programs that make the computer useful for the user
language.
Solve specific problems or supply a service Word
The advantage of assembly language is that it
processors, spreadsheets, databases, etc. This is what we
requires less memory and less execution time to execute a
will be developing in this class.
program.
PROGRAMMING LANGUAGES Below is an example of Assembly Language Code:
As we know, to communicate with a person, we
need a specific language, similarly to communicate with
computers, programmers also need a language is called
Programming language.
What is Language? 2. High-level programming language
Language is a mode of communication that is used High-level programming language (HLL) is
to share ideas, opinions with each other. For example, if designed for developing user-friendly software programs
we want to teach someone, we need a language that is and websites. This programming language requires a
understandable by both communicators. compiler or interpreter to translate the program into
machine language (execute the program).
What is a Programming Language? The main advantage of a high-level language is
A programming language is a computer that it is easy to read, write, and maintain.
language that is used by programmers (developers) to
communicate with computers. It is a set of instructions What is Java?
written in any specific language ( C, C++, Java, Python) to -Java is a programming language and a platform.
perform a specific task. -Java is a high level, robust, object-oriented and secure
A programming language is mainly used programming language.
to develop desktop applications, websites, and mobile -Java was developed by Sun Microsystems (which is now
applications. the subsidiary of Oracle) in the year 1995.
James Gosling is known as the father of Java.
TYPES OF PROGRAMMING LANGUAGE Before Java, its name was Oak. Since Oak was already a
1. Low-level programming language registered company, so James Gosling and his team
Low-level language is machine-dependent (0s and changed the name from Oak to Java.
1s) programming language. The processor runs low- level Platform: Any hardware or software environment in which
programs directly without the need of a compiler or a program runs, is known as a platform. Since Java has a
interpreter, so the programs written in low-level language runtime environment (JRE) and API, it is called a platform.
can be run very fast.
Application
Low-level language is further divided into two parts : According to Sun, 3 billion devices run Java. There are
1. Machine Language many devices where Java is currently used. Some of them
Machine language is a type of low-level are as follows:
programming language. It is also called as machine code 1. Desktop Applications such as acrobat reader,
or object code. Machine language is easier to read media player, antivirus, etc.
because it is normally displayed in binary or hexadecimal 2. Web Applications such as irctc.co.in,
form (base 16) form. It does not require a translator to javatpoint.com, etc.
convert the programs because computers directly 3. Enterprise Applications such as banking
understand the machine language programs. applications.
The advantage of machine language is that it helps 4. Mobile
the programmer to execute the programs faster than the 5. Embedded System
high-level programming language. 6. Smart Card
Below is an example of Machine Language 7. Robotics
(binary) for the text “Hello World”. 8. Games, etc.
Types of Java Applications
There are mainly 4 types of applications that can
be created using Java programming:
2. Assembly Language
1) Standalone Application
Standalone applications are also known as  Portable
desktop applications or window-based applications. These  Platform independent
are traditional software that we need to install on every  Secured
machine. Examples of standalone application are Media  Robust
player, antivirus, etc. AWT and Swing are used in Java for  Architecture neutral
creating standalone applications.  Interpreted
2) Web Application  High Performance
An application that runs on the server side and  Multithreaded
creates a dynamic page is called a web application.  Distributed
Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc.  Dynamic
technologies are used for creating web applications in
First Java Program | Hello World Example
Java.
3) Enterprise Application Creating Hello World Example
An application that is distributed in nature, such
as banking applications, etc. is called an enterprise
application. It has advantages like high-level security, load
balancing, and clustering. In Java, EJB is used for creating
enterprise applications.
4) Mobile Application
An application which is created for mobile devices Compilation Flow:
is called a mobile application. Currently, Android and Java When we compile Java program using javac tool, the Java
ME are used for creating mobile applications. compiler converts the source code into byte code.

History of Java
Currently, Java is used in internet programming,
mobile devices, games, e-business solutions, etc.
Following are given significant points that describe the
history of Java.
Parameters used in First Java Program
1) James Gosling, Mike Sheridan, and Patrick
 class keyword is used to declare a class in Java.
Naughton initiated the Java language project in June 1991.
 public keyword is an access modifier that
The small team of sun engineers called Green Team.
represents visibility. It means it is visible to all.
2) Initially it was designed for small, embedded systems in
 static is a keyword. If we declare any method as
electronic appliances like set-top boxes.
static, it is known as the static method. The core
3) Firstly, it was called "Greentalk" by James Gosling, and
advantage of the static method is that there is no
the file extension was .gt.
need to create an object to invoke the static
4) After that, it was called Oak and was developed as a
method. The main() method is executed by the
part of the Green project.
JVM, so it doesn't require creating an object to
Why Java was named as "Oak"?
invoke the main() method. So, it saves memory.
5) Why Oak? Oak is a symbol of strength and chosen as a
 void is the return type of the method. It means it
national tree of many countries like the U.S.A., France,
doesn't return any value.
Germany, Romania, etc.
 main represents the starting point of the program.
6) In 1995, Oak was renamed as "Java" because it was
 String[] args or String args[] is used
already a trademark by Oak Technologies.
for command line argument. We will discuss it in
Why Java Programming named "Java"?
coming section.
7) Why had they chose the name Java for Java language?
 System.out.println() is used to print statement.
The team gathered to choose a new name. The suggested
Here, System is a class, out is an object of the
words were "dynamic", "revolutionary", "Silk", "jolt",
PrintStream class, println() is a method of the
"DNA", etc. They wanted something that reflected the
PrintStream class. We will discuss the internal
essence of the technology: revolutionary, dynamic, lively,
working of System.out.println() statement in the
cool, unique, and easy to spell, and fun to say.
coming section.
Features of Java Java Variables
A list of the most important features of the Java language A variable is a container which holds the value while
is given below. the Java program is executed. A variable is assigned with a
 Simple data type.
 Object-Oriented
Variable is a name of memory location. There are three  double data type
types of variables in java: local, instance and static. Boolean Data Type
There are two types of data types in Java: primitive and The Boolean data type is used to store only two
non-primitive. possible values: true and false. This data type is used for
simple flags that track true/false conditions.
The Boolean data type specifies one bit of information,
Variable but its "size" can't be defined precisely.
A variable is the name of a reserved area allocated in
Byte Data Type
memory. In other words, it is a name of the memory
The byte data type is an example of primitive data
location. It is a combination of "vary + able" which means
type. It isan 8-bit signed two's complement integer. Its
its value can be changed.
value-range lies between -128 to 127 (inclusive). Its
Types of Variables minimum value is -128 and maximum value is 127. Its
There are three types of variables in Java: default value is 0.
 local variable
Short Data Type
 instance variable
The short data type is a 16-bit signed two's
 static variable
complement integer. Its value-range lies between -32,768
1) Local Variable
to 32,767 (inclusive). Its minimum value is -32,768 and
A variable declared inside the body of the method
maximum value is 32,767. Its default value is 0.
is called local variable. You can use this variable only
within that method and the other methods in the class Int Data Type
aren't even aware that the variable exists. The int data type is a 32-bit signed two's
A local variable cannot be defined with "static" keyword. complement integer. Its value-range lies between -
2) Instance Variable 2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1)
A variable declared inside the class but outside (inclusive). Its minimum value is - 2,147,483,648and
the body of the method, is called an instance variable. It is maximum value is 2,147,483,647. Its default value is 0.
not declared as static. Long Data Type
It is called an instance variable because its value is The long data type is a 64-bit two's complement
instance-specific and is not shared among instances. integer. Its value-range lies between -
3) Static variable 9,223,372,036,854,775,808(-2^63) to
A variable that is declared as static is called a static 9,223,372,036,854,775,807(2^63 -1)(inclusive). Its
variable. It cannot be local. You can create a single copy of minimum value is - 9,223,372,036,854,775,808and
the static variable and share it among all the instances of maximum value is 9,223,372,036,854,775,807.
the class. Memory allocation for static variables happens
only once when the class is loaded in the memory. Float Data Type
The float data type is a single-precision 32-bit IEEE 754
Data Types in Java floating point.Its value range is unlimited. It is
Data types specify the different sizes and values recommended to use a float (instead of double) if you
that can be stored in the variable. There are two types of need to save memory in large arrays of floating point
data types in Java: numbers. The float data type should never be used for
Primitive data types: The primitive data types include precise values, such as currency. Its default value is 0.0F.
boolean, char, byte, short, int, long, float and double.
Non-primitive data types: The non-primitive data types Double Data Type
include Classes, Interfaces, and Arrays. The double data type is a double-precision 64-bit IEEE 754
Java Primitive Data Types floating point. Its value range is unlimited. The double
In Java language, primitive data types are the data type is generally used for decimal values just like
building blocks of data manipulation. These are the most float. The double data type also should never be used for
basic data types available in Java language. precise values, such as currency. Its default value is 0.0d.

There are 8 types of primitive data types: Char Data Type


 boolean data type The char data type is a single 16-bit Unicode character. Its
 byte data type value-range lies between '\u0000' (or 0) to '\uffff' (or
 char data type 65,535 inclusive).The char data type is used to store
 short data type characters.
 int data type
 long data type
 float data type

You might also like