0% found this document useful (0 votes)
5 views

Java Lesson 1

The document discusses Java programming language including its history, features, and the process of compiling and running a Java program. It covers topics such as algorithms, programming languages, object-oriented programming, and the elements of a programming language.

Uploaded by

Bea Alonzo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Java Lesson 1

The document discusses Java programming language including its history, features, and the process of compiling and running a Java program. It covers topics such as algorithms, programming languages, object-oriented programming, and the elements of a programming language.

Uploaded by

Bea Alonzo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Republic of the Philippines

Department of Education

NAME: ________________________________________ DATE: ________________

GRADE & SECTION: ___________________________ TEACHER: _____________

MODULE IN PROGRAMMING NC III


GRADE 12
FIRST QUARTER
WEEK 1

MOST ESSENTIAL LEARNING COMPETENCY

• Apply basics of Java language. TLE_ICTJAVA11-12POAD-IIf-i-29

OBJECTIVES

1. Demonstrate knowledge of Java technology.


2. Demonstrate knowledge of Java programming.

PRE-TEST IDENTIFICATION (10 Points)

Directions: Read each item carefully and identify concept/terms on every


item. Write your answer on the space provided.

1. What is a set of instructions a computer follows to perform a task?

_________________________________________________________________________________

2. What is a set of well-defined steps for performing a task or solving a


problem?

_________________________________________________________________________________

3. What is an object-oriented program invented at Sun Microsystems and is


now owned by Oracle?

_________________________________________________________________________________

2
4. What are words that have a special meaning in a programming language
which are used for their intended purpose only and usually called reserved
words?

_________________________________________________________________________________

5. What reads the entire program and translates it completely before the
program starts running?

_________________________________________________________________________________

WHAT IS A PROGRAM?

A program is a set of instructions a computer follows to perform a task. A


programming language is a special language used to write computer programs.

Computers are designed to follow instructions. In this example, we want to


calculate an employee’s salary. Below is a list of instructions the computer
should follow to perform this task.

1. Display a message on the monitor: “How many hours did you work?”
2. The user enters the number of hours worked.
3. When the user enters the number, store it in memory.
4. Display a message on the monitor: “How much do you get paid per hour?”
5. The user enters an hourly rate.
6. When the user enters the number, store it in memory.
7. When the number of hours worked and the hourly rate are entered,
multiply the two numbers, and store the result in memory.
8. Display a message on the monitor that shows the amount of earnings
which is the result of the calculation of employee’s salary.

The above instructions are called an algorithm. An algorithm is a set of well-


defined steps for performing a task or solving a problem. The above Instructions
are sequentially ordered, thus, performed in sequence.

Central Processing Unit (CPU) can only process instructions that are written in
machine language. A machine language program is a stream of binary
numbers consisting of 1s and 0s. Binary numbers form low-level instructions
also called machine language instructions, which the CPU interprets as
commands.

3
Programming languages use words instead of numbers to ease the task of
programming. A program can be written in a programming language which is
much easier to understand than machine language, and then translated into
machine language.

DIFFERENT PROGRAMMING LANGUAGES

BASIC or Beginners All-purpose Symbolic Instruction Code is a general-purpose,


procedural programming language designed for beginners in programming.

FORTRAN or Formula Translator is a procedural language designed for


programming complex mathematical algorithms.

COBOL or Common Business-Oriented Language is a procedural language


designed for business applications.

Pascal is a structured, general-purpose, procedural language designed primarily


for teaching programming.

C is a structured, general-purpose, procedural language developed at Bell


Laboratories.

C++ is based on C programming language which offers object-oriented features


not found in C and was also invented at Bell Laboratories.

C# or “C sharp” is a language invented by Microsoft for developing


applications based on the Microsoft .NET platform.

Java is an object-oriented language invented at Sun Microsystems and is now


owned by Oracle. Used for development of stand-alone applications that operate
on a single computer, applications that run over the Internet from a Web server,
and applets that run in a Web browser.

JavaScript is a programming language that is used in a website to perform


simple operations.

PHP is a programming language used primarily for developing web server


applications and dynamic web pages.

4
Python is an object-oriented programming language that is used in both
business and academia. Many popular web sites have features that are
developed in Python.

Ruby is a simple but powerful object-oriented programming language which is


used for creation of small utility programs to large web applications.

Visual Basic is a Microsoft programming language used to create Windows-


based applications.

THE ELEMENTS OF A PROGRAMMING LANGUAGE

Keywords are words that have a special meaning in a programming language.


Keywords are used for their intended purpose only and are also called reserved
words.

Operators are symbols or words that perform operations on one or more


operands. An operand is usually an item of data like a number.

Punctuation in most programming languages require the use of punctuation


characters. These characters serve specific purposes, such as marking the
beginning or ending of a statement or separating items in a list.

Programmer-Defined Names are words or names that are defined by the


programmer. They are used to identify storage locations in memory.
Programmer-defined names are often called identifiers.

Syntax are rules that must be followed when writing a program. Syntax
dictates how keywords and operators may be used, and where punctuation
symbols must appear.

THE JAVA PROGRAMMING LANGUAGE

Java is a general-purpose programming language and one of the most popular


programming languages developed by James Gosling in the early years of
1990’s.

5
Owned by Oracle and used for desktop applications, mobile applications, web
applications, games development and more.

Java is popular because it is platform independent which means that the same
compiled program can run on any computer in the world.

Java applications are typically compiled to bytecode that can run on any Java
virtual machine (JVM) regardless of the computer architecture.

Java support for true OOP or Object-Oriented Programming.

The process of designing, coding, testing, debugging, documenting, maintaining,


and upgrading computer programs is software development. Generally,
beginners have two options for developing programs: use an integrated
development environment or use the command line.

An integrated development environment (IDE) is a collection of


internetworking programs that facilitate software development.

OBJECT-ORIENTED PROGRAMMING

There are primarily two methods of programming in use today: procedural and
object-oriented. The earliest programming languages were procedural,
meaning a program was made of one or more procedures. A procedure is a set
of programming statements that perform a specific task.

In a procedural program, the data items are commonly passed from one
procedure to another as shown below.

Data
Item

Procedure A Procedure B

6
If procedural programming is centered on creating procedures, object-
oriented programming is centered on creating objects. An object is a
programming entity that contains data and procedures. The data contained
within an object is known as the object’s attributes. The procedures that an
object performs are known as the object’s methods. An object in concept
consists of data (attributes) and procedures (methods).

COMPILING AND RUNNING A JAVA PROGRAM

Java is a high-level language. Other high-level languages we hear in the


programming community include Python, C and C++, Ruby, and JavaScript.
Before programs are run, programs in high-level languages must be translated
into a low-level language, also called “machine language”. Two kinds of programs
translate high-level languages into low-level languages: interpreters and
compilers. An interpreter reads a high-level program and executes it, meaning
that it does what the program says. It processes the program at a time,
alternately reading lines and performing computations.

In contrast, a compiler reads the entire program and translates it completely


before the program starts running. In this context, the high-level program is
called the source code, and the translated program is called the object code.
Once a program is compiled, it can be repeatedly executed without further
translation. As a result, compiled programs often run faster than interpreted
programs. Java is both compiled and interpreted. Instead of translating
programs directly into machine language, the Java compiler generates byte
code. Similar to machine language, byte code is easy and fast to interpret. But
it is also portable, so it is possible to compile a Java program on one machine,
transfer the byte code to another machine, and run the byte code on the other
machine. The interpreter that runs byte code is called a “Java Virtual Machine”
(JVM).

Source Compiler Byte code Interpreter


code javac Output
Hello.class java Hello
Hello.java Hello.java

7
The following program is called the hello world program. All it does is display
the words “Hello, World!” on the screen. In Java, it looks like this:

public class Hello


{
public static void main(String[ ] args)
{
// generate some simple output
System.out.println("Hello, World!");
}
}

HOW JAVA WORKS:

1. We write a list of commands in English language, creating a Java program.

2. The program then is converted into an intermediate version, called


bytecode.

3. The bytecode is then read by a special software called a Java interpreter,


which translates it to a machine friendly language.

4. The computer reads the translated code and performs the tasks requested.

POST-TEST DEFINITION (10 Points)

Directions: Define the following and write your answers on the space
provided.

1. What is a program and how does it differ with an algorithm?

_________________________________________________________________________________

_________________________________________________________________________________

2. What is procedural programming and how does it differ from object-


oriented programming?

_________________________________________________________________________________

_________________________________________________________________________________

8
3. What is a compiler and how does it differ from an interpreter?

_________________________________________________________________________________

_________________________________________________________________________________

4. What is an object?

_________________________________________________________________________________

_________________________________________________________________________________

5. What is Java Virtual Machine?

_________________________________________________________________________________

_________________________________________________________________________________

You might also like