You are on page 1of 9

ITE 186: Computer Programming 2

Module #2 Student Activity Sheet

Name: Class number:


Section: Schedule: Date:

Lesson title: Concepts of Java Programming Materials: SAS

Learning Targets: References:

At the end of the module, students will be able to: ● Farrell,Joyce.Java Programming:
Concepts and Applications.
1. Explain the concepts of Java from its history, Second Edition. Cengage
components and platforms. Learning Asia. 2012
2. Explain why python and Java are categorized as ● https://github.com/java-tutorial-for-
interpreted language aside from Java being a beginners
compiler.
3. Demonstrate the installation of a JDK and text
editor compatible version in creating Java
programs
4. Explain the Java virtual machine.

A. LESSON PREVIEW/REVIEW
Introduction
Good day, everyone. Today you will learn about the background of Java as a program, we will also look
at some differences to its competitor python in terms of syntax and semantics. As part of this lesson, I will
also introduce to you all the pre-requisites before making your first program in java. So let us begin your
journey in learning Java Program on its standard edition.

B. MAIN LESSON

What is Java?
The Java language was developed at Sun Microsystems in 1991 as part of a research project to develop
software for consumer electronics devices—television sets, VCRs, toasters, and the other sorts of
machines you can buy at any department store. Java’s goals at that time were to be small, fast, efficient,
and easily portable to a wide range of hardware devices. It is those same goals that made Java an ideal
language for distributing executable programs via the World Wide Web, and also a general-purpose
programming language for developing programs that are easily usable and portable across different
platforms

Sun has released the beta version of the Java Developer’s Kit (JDK), which includes tools for developing
Java applets and applications on Sun systems running Solaris 2.3 or higher for Windows NT and for
Windows 95. Java emerged as a tech juggernaut because of its unique portability and its capability of
operating similarly on any hardware or operating system. The most secure, simple and robust
programming language was first released to the world on May 23, 1995.

This document is the property of PHINMA EDUCATION


ITE 186: Computer Programming 2
Module #2 Student Activity Sheet

Name: Class number:


Section: Schedule: Date:

Figure 1.1 Traditional compiled program

Figure 1.2 Java Programs

To run a Java program, you run a program called a bytecode interpreter, which in turn executes your
Java program (see Figure 1.2). You can either run the interpreter by itself, or—for applets— there is a
bytecode interpreter built into Hot Java and other Java-capable browsers that runs the applet for you

Java as a Program

1. Object Oriented − In Java, everything is an Object. Java can be easily extended since it is based
on the Object model.

2. Platform Independent − Unlike many other programming languages including C and C++, when

This document is the property of PHINMA EDUCATION


ITE 186: Computer Programming 2
Module #2 Student Activity Sheet

Name: Class number:


Section: Schedule: Date:

3. Java is compiled, it is not compiled into platform specific machine, rather into platform
independent.
4. Byte code. This byte code is distributed over the web and interpreted by the Virtual Machine (JVM)
5. on whichever platform it is being run on.
6. Simple − Java is designed to be easy to learn. If you understand the basic concept of OOP Java,
it
7. would be easy to master.
8. Secure − With Java's secure feature, it enables the development of virus-free, tamper-free
systems.
9. Authentication techniques are based on public-key encryption.
10. Architecture-neutral − Java generates an architecture-neutral object file format, which makes the
compiled code executable on many processors, with the presence of Java runtime system.
11. Portable − Being architecture-neutral and having no implementation dependent aspects of the
specification makes Java portable. Compiler in Java is written in ANSI C with a clean portability
boundary, which is a POSIX subset.
12. Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly on
compile time error checking and runtime checking.
13. Multithreaded − With Java's multithreaded feature it is possible to write programs that can
perform many tasks simultaneously. This design feature allows the developers to construct
interactive applications that can run smoothly.
14. Interpreted − Java byte code is translated on the fly to native machine instructions and is not
stored anywhere. The development process is more rapid and analytical since the linking is an
incremental and light-weight process.
15. High Performance − With the use of Just-In-Time compilers, Java enables high performance.
16. Distributed − Java is designed for the distributed environment of the internet.
17. Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt
to an evolving environment. Java programs can carry extensive amount of run-time information
that can be used to verify and resolve accesses to objects on run- time.

Python and Java as Interpreted Language


An interpreted language is a kind of programming language that relies on another piece of software
called an interpreter to run. Most programming languages rely on a compiler, which changes the code
into a set of instructions that are specifically designed for a particular type of machine and operating
system. When writing programs using an interpreted language, the program itself is a text file with code,
and the interpreter acts as an intermediary, translating the instructions into something the machine can
understand on the fly.

This document is the property of PHINMA EDUCATION


ITE 186: Computer Programming 2
Module #2 Student Activity Sheet

Name: Class number:


Section: Schedule: Date:

An interpreter is a kind of program that executes other programs. When you write Python programs, it
converts source code written by the developer into intermediate language which is again translated into
the native language machine language that is executed.

The python code you write is compiled into python bytecode, which creates file with extension .pyc. The
bytecode compilation happened internally, and almost completely hidden from developer. Compilation is
simply a translation step, and byte code is a lower-level, and platform-independent, representation of
your source code. Roughly, each of your source statements is translated into a group of byte code
instructions. This byte code translation is performed to speed execution byte code can be run much
quicker than the original source code statements.

The .pyc file, created in compilation step, is then executed by appropriate virtual machines. The Virtual
Machine just a big loop that iterates through your byte code instructions, one by one, to carry out their
operations. The Virtual Machine is the runtime engine of Python and it is always present as part of the
Python system, and is the component that truly runs the Python scripts. Technically, it's just the last step
of what is called the Python interpreter.

Java is both a compiled language as well as an interpreted language. The Java code is written in files
with the extension .java. This source file is compiled by javac, i.e., the Java compiler into a class file.
However, unlike C or C++, the Java compiler generates bytecode instead of native machine code.
Java code is written in .java files (also known as the source file), which is compiled by javac, a Java
compiler into class files. Unlike C or C++ compiler, Java compiler doesn't generate native code. These
class files contain byte-code, which is different than machine or native code. Java virtual machine or
JVM interprets byte codes during the execution of the Java program.

Java Virtual Machine (JVM)


The Java Virtual Machine is a program whose purpose is to execute other programs. The JVM has two
primary functions: to allow Java programs to run on any device or operating system (known as the "Write
once, run anywhere" principle), and to manage and optimize program memory. When Java was released
in 1995, all computer programs were written to a specific operating system, and program memory was
managed by the software developer.

The JVM performs following operation:


● Loads code

This document is the property of PHINMA EDUCATION


ITE 186: Computer Programming 2
Module #2 Student Activity Sheet

Name: Class number:


Section: Schedule: Date:

● Verifies code
● Executes code
● Provides runtime environment

Figure 1.3 Java Virtual Machine Architecture

Java Syntax
The syntax of Java is largely derived from C++. Unlike C++, which combines the syntax for structured,
generic, and object- oriented programming, Java was built almost exclusively as an object-oriented
language. All code is written inside a class, and everything is an object, with the exception of the primitive
data types (e.g., integers, floating-point numbers, boolean values, and characters), which are not classes
for performance reasons. Unlike C++, Java does not support operator overloading or multiple inheritance
for classes. This simplifies the language and aids in preventing potential errors and anti-pattern design.
Java uses similar commenting methods to C++. There are three different styles of comments: a single
line style marked with two slashes (//), a multiple line style opened with /* and closed with */, and the
Javadoc commenting style opened with /** and closed with */. The Javadoc style of commenting allows
the user to run the Javadoc executable to compile documentation for the program.

Java Reserved Words

This document is the property of PHINMA EDUCATION


ITE 186: Computer Programming 2
Module #2 Student Activity Sheet

Name: Class number:


Section: Schedule: Date:

Java sample Program

Note: Class name should start in uppercase.

class HelloWorld
{
public static void main (String [] args)
{
System.out.println("Hello world!!!");
}
}

OUTPUT: Hello World!!!


Understanding the Statement:

public class Welcome


• public is an access specifier
• Welcome is the name of the class
System.out.println(“First Java Application”);
● The dots or periods are used to separate the name of the components in the
statement.
● System is a class.
● out is an object defined in the System class.
● println () is a method. Method names are always followed by parentheses.
● First Java Application is a literal string that is the argument to the println() method.
● (semicolon) is used to end a Java statement.
Skill-building Activities
Let us practice! After completing each exercise, you may refer to the Key to Corrections for feedback. Try
to complete each exercise before looking at the feedback.

1. Download the java development kit version 1.7 to your machine


2. Perform the installation
3. Perform a command check with command line to verify the installation
4. Make a screenshot of your version installed to your machine

This document is the property of PHINMA EDUCATION


ITE 186: Computer Programming 2
Module #2 Student Activity Sheet

Name: Class number:


Section: Schedule: Date:

Check for Understanding


What is the output of the following program?

Code Output
class Welcome
{
public static void main(String args){
System.out.print("Welcome to Computer
Programming 2");

}
}

class Welcome2
{
public static void main(String args){
System.out.print("Welcome to ");
}
System.out.print("Welcome to Computer
Programming 2 ");

class Welcome3
{
public static void main(String args){
System.out.println("Welcome to ");
System.out.print("Welcome to Computer
Programming 2 ");
}

This document is the property of PHINMA EDUCATION


ITE 186: Computer Programming 2
Module #2 Student Activity Sheet

Name: Class number:


Section: Schedule: Date:

C. LESSON WRAP-UP
FAQs
1. Is there a case sensitivity in Java programming?
Ans: Yes, Java is case sensitive, which means identifier Hello and hello would have a different
meaning in Java.
2. What is the rule in setting class names ? For all class names, the first letter should be in Upper
Ans: Case. If several words are used to form the class's name, each inner word's first letter should
be in Upper Case.
3. What is the rule in setting method names and program file name?
Ans: All method names should start with a lowercase letter. If several words are used to form the
method's name, then each inner word's first letter should be in Upper Case while the program file's
name should exactly match the class name.

Thinking about Learning


a) Mark your place in the work tracker which is simply a visual to help you track how much work you
have accomplished and how much work there is left to do.
Period 1 Period 2 Period 3

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 2
5 6

b) Think about your learning by filling up “My Learning Tracker”. Write the learning targets, score,
and learning experience for the session and deliberately plan for the next session.
Date Learning Target/Topic Scores Action Panel

This document is the property of PHINMA EDUCATION


ITE 186: Computer Programming 2
Module #2 Student Activity Sheet

Name: Class number:


Section: Schedule: Date:

What’s the What module # did you do? Whatwere What contributed to the quality of
date today? your scores in your performance today? What will
What were the learning targets?
the activities? you do next session to maintain your
What activities did you do? performance or improve it?

Answer Key
Skill Building Activities: Refer to the video resources on “Installing JDK”

This document is the property of PHINMA EDUCATION

You might also like