0% found this document useful (0 votes)
174 views52 pages

LMC - AEC 09 - Chapter 03

This document provides an introduction to the Java programming language. It defines Java as both an application development platform and programming language that is simple, robust, secure, high-level and general-purpose. It discusses how Java is portable, object-oriented, interpreted and can be considered both a compiled and interpreted language. The document also compares Java to C++ and outlines some key features of Java like its structure, lack of operator overloading, dynamic nature, predefined data types, and open standard status. It provides examples of how Java is used for mobile applications, web applications, desktop applications, games, big data and more.

Uploaded by

Anna Taylor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
174 views52 pages

LMC - AEC 09 - Chapter 03

This document provides an introduction to the Java programming language. It defines Java as both an application development platform and programming language that is simple, robust, secure, high-level and general-purpose. It discusses how Java is portable, object-oriented, interpreted and can be considered both a compiled and interpreted language. The document also compares Java to C++ and outlines some key features of Java like its structure, lack of operator overloading, dynamic nature, predefined data types, and open standard status. It provides examples of how Java is used for mobile applications, web applications, desktop applications, games, big data and more.

Uploaded by

Anna Taylor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Disclaimer

Disclaimer

This learning material is used in compliance with the flexible teaching-learning approach
espoused by CHED in response to the pandemic that has globally affected educational institutions.
Authors and publishers of the contents are well acknowledged. As such, the college and its faculty
do not claim ownership of all sourced information. This learning material will solely be used for
instructional purposes not for commercialization.

College of Information and Communications Technology


Chapter 3: Introduction to Java Programming

3
MODULE 3: INTRODUCTION TO JAVA PROGRAMMING

Chapter
r
Introduction
to
Java
Programming
Chapter 3: Introduction to Java Programming

Module Overview

This module will provide the fundamentals of java programming. It will cover the following
lessons:

Lesson 1: The Java Programming Language

This lesson presents the basics of Java programming language.

Lesson 2: The History of Java

This lesson provides lectures on the evolution of Java programming


language.

Lesson 3: The Java Technology

This lesson provides lecture on the various technologies of Java.

Lesson 4: The Java Platforms

This lesson provides the different platforms to host Java applications.

Lesson 5: The Java Features

This lesson provides a list of important features of Java which is also


known as Java buzzwords.

Lesson 6: Application of Java

This lesson provides the various applications of Java programming


language.

Lesson 7: Java Terminologies

This lesson provides the various terminologies associated with Java


programming language.

Lesson 8: Java Development Environments

This lesson presents lectures on how to create, compile and run a simple
Java program using notepad or an integrated development environment.

Learning Outcomes

At the end of this module, you should be able to:

1. Describe Java Programming


2. Explain the development process of Java Programming
3. Discuss the different Java Platforms
4. Define terminologies associated with Java Programming Examine the Java development
environments

3
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Module Map

Describe Java
Programming
Design, implement, test, and
debug a program, based on a
given specification, that uses
each of the following
fundamental programming
Explain the components: (1) primitive
development process data types, (2} basic
of Java Programming computation, (3) simple I/0,
(4) conditional and iterative
structures, (5) definition of
functions and parameter
passing, and (6) recursion

Discuss the different Introduction to


Java Platforms Java Analyze and simulate results
of algorithms that may be CC102
Programming
implemented as a solution to
a given problem.

Define terminologies Use a suitable programming


associated with Java language, and development
programming environment, to implement,
test and debug algorithms for
solving simple problems.

Examine the Java


development environments

4
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Introduction

Java is the universal programming language used around the world both in
education and in the industry. It is an open source language that is readily available in
the Internet for download and use.
Java is used primarily in school in teaching computer programming concepts among
students. The syntax and commands are easy to understand and teaches the students to
write better because it uses object oriented concepts in writing a program.

5
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

LESSON 1: The Java Programming


Language

What is Java?
JAVA is both an application development platform and a programming language.
It is a simple, robust, secured high-level general-purpose language that is object-oriented,
class-based, and web enabled.
The Java programming language was developed by Sun Microsystems in the
early 1990s. Although it is primarily used for Internet-based applications, Java is a simple,
efficient, general-purpose language. Java was originally designed for embedded network
applications running on multiple platforms. It is a portable, object-oriented, interpreted
language.

Java is extremely portable. The same Java application will run identically on any
computer, regardless of hardware features or operating system, as long as it has a Java
interpreter. Besides portability, another of Java's key advantages is its set of security
features which protect a PC running a Java program not only from problems caused by
erroneous code but also from malicious programs (such as viruses). You can safely run
a Java applet downloaded from the Internet, because Java's security features prevent
these types of applets from accessing a PC's hard drive or network connections.
An applet is typically a small Java program that is embedded within an HTML page.

Java can be considered both a compiled and an interpreted language because its
source code is first compiled into a binary byte-code. This byte-code runs on the Java
Virtual Machine (JVM), which is usually a software-based interpreter. The use of compiled
byte-code allows the interpreter (the virtual machine) to be small and efficient (and nearly
as fast as the CPU running native, compiled code). In addition, this byte-code gives Java
its portability: it will run on any JVM that is correctly implemented, regardless of
computer hardware or software configuration. Most Web browsers (such as Microsoft
Internet Explorer or Netscape Communicator) contain a JVM to run Java applets.

Compared to C++ (another object-oriented language), Java code runs a little


slower (because of the JVM) but it is more portable and has much better security features.
The virtual machine provides isolation between an untrusted Java program and the PC
running the software. Java's syntax is similar to C++ but the languages are quite different.
For example, Java does not permit programmers to implement operator overloading while
C++ does. In addition, Java is a dynamic language where you can safely modify a
program while it is running, whereas C++ does not allow it. This is especially important
for network applications that cannot afford any downtime. Also, all basic Java data types
are predefined and not platform-dependent, whereas some data types can change with
the platform used in C or C++ (such as the int type).

Java programs are more highly structured than C++ equivalents. All functions (or
Java methods) and executable statements in Java must reside within a class while C++
allows function definitions and lines of code to exist outside of classes (as in C-style
6
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

programs). Global data and methods cannot reside outside of a class in Java, whereas
C++ allows this. These restrictions, though cumbersome at times, help maintain the
integrity and security of Java programs and forces them to be totally object-oriented.

Another key feature of Java is that it is an open standard with publicly available
source code. Sun Microsystems controls the Java language and its related products but
Sun's liberal license policy contributed to the Internet community embracing Java as a
standard. You can freely download all the tools you need to develop and run Java applets
and applications from Sun's Java Web site

It is used for:

• Mobile applications (specially Android apps)


• Desktop applications
• Web applications
• Web servers and application servers
• Games
• Database connection
• And much, much more!

Why Use Java?

• Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)
• It is one of the most popular programming language in the world
• It is easy to learn and simple to use
• It is open-source and free
• It is secure, fast and powerful
• It has a huge community support (tens of millions of developers)
• Java is an object oriented language which gives a clear structure to programs and
allows code to be reused, lowering development costs
• As Java is close to C++ and C#, it makes it easy for programmers to switch to
Java or vice versa

Supplementary Learning Resources


1. Introduction to Java Programming
[Youtube Video] https://www.youtube.com/watch?v=mG4NLNZ37y4

2. Why Should You Learn Java?


[Youtube Video] https://www.youtube.com/watch?v=Zv8-hrGiGno

7
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

NAME:

PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER3

Test Yourself 3-1

Compare Java, C and C++. Check the similarities (if there is any) and differences.
(15 pts.)

Java C C++

8
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

LESSON 2: The History of Java

Java programming language was created by James Gosling et.al. of Sun


Microsystems in 1991 and it was released in 1995 as core component of Sun
Microsystems’ Java platform, Java 1.0. In January 27, 2010, Sun Microsystems was
acquired by Oracle Corporation.

Java was initially named as Oak, a tree outside of James Gosling’s window. It
was renamed and relaunched to Java when the web and the Internet was becoming
popular by which Java can be used for web programming.

The drive for developing Java language was the desire to have a platform
independent language to be rooted in various electronic products such as toasters and
refrigerators. A personal hand-held remote control named Star 7 was the first project
developed using Java language.

2.1 Versions of Java Programming

Figure 1 below shows the Java versions in its history, for Java Standard
Edition (SE) Development Kit (JDK). The JDK 13 version is set to be released in
September 2019.

JDK 1.0 J2SE 1.2 J2SE 1.4 JDK 6 JDK 8 JDK 10 JDK 12
Oak Playground Merlin Mustang March 2014 March 20, March 19,
December February 2002 December 2018 2019
January 1996
2006
1998

February May 2000 September July 2011 September September September


1997 Kestrel 2004 Dolphin 21, 2017 25, 2018 10, 2019
JDK 1.1 JDK 1.3 Tiger JDK 7 JDK 9 JDK 11 JDK 13
J2SE 5.0

Figure 1 Java Versions History

From the table above we can see that the naming and the version number
have been changing over times:

• Versions 1.0 and 1.1 are named as JDK (Java Development Kit).

9
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

• From versions 1.2 to 1.4, the platform is named as J2SE (Java 2


Standard Edition).
• From versions 1.5, Sun introduces internal and external versions.
Internal version is continuous from previous ones (1.5 after 1.4), but the
external version has a big jump (5.0 for 1.5). This could make confusion
for someone, so keep in mind that version 1.5 and version 5.0 are just
two different version names for only one thing.
• From Java 6, the version name is Java SE X.

Major versions were released after every 2 years, however the Java SE 7
took 5 years to be available after its predecessor Java SE 6, and 3 years for Java
SE 8 to be available to public afterward.

Since Java SE 10, new versions will be released very six months.
Java versus C, C++ and C#
Java is correlated to C, C++ and C# languages. The syntax of Java was
derived from C and C++. Java is basically the Internet version of C++ and its object
model is adapted from C++.
C# adapted the its features from Java, and both share the same C++ style
syntax, support distributed programming, and apply the same object model. Java is
easy to learn when you are already familiar with C#.

Supplementary Learning Resources


1. javatpoint. (2018). History of Java [YouTube Video]. In YouTube.
https://www.youtube.com/watch?v=DcQPtlFlgzY
2. SyntaxByte. (2018). The History of the Java Programming Language [YouTube
Video]. In YouTube. https://www.youtube.com/watch?v=eX7VnkcXMdM
3. vamsi j. (2020). History and Evaluation of java Programming [YouTube Video]. In
YouTube. https://www.youtube.com/watch?v=aV0VnVc7h48

10
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER3

Test Yourself 3-2

Give the difference of every versions of Java Programming. (20 pts.)

11
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

LESSON 3: The Java Technology

The Java Technology is a/an:


1. programming language. Java can create all kinds of applications that can
be developed using any conventional programming language.

2. development environment. Java provides you with a large suite of


tools: a compiler (javac), an interpreter (java), a documentation generator
(javadoc), a class file packaging tool, and so on.

3. application environment. Java technology applications are typically


general-purpose programs that run on any machine where the Java
Runtime Environment (JRE) is installed.

4. deployment environment. There are two (2) main deployment environments


in Java: (1) JRE supplied by the Java 2 Software Development Kit (SDK)
containing the broad set of class files for all the Java technology packages
including basic language classes, Graphical User Interface (GUI) component
classes, and others; and (2) The web browser. Most browsers today have
built-in Java technology interpreter and runtime environment.

3.1 Java Virtual Machine

The Java Virtual Machine is an engine that executes the java code. When
java programs are compiled, the bytecode is generated. The bytecode is converted
into a machine language.
The JVM is both a specification and an implementation. It is a specification
because it provides runtime environment in which java bytecode can be executed.
And that the implementation of JVM is through the Java Runtime Environment
(JRE). An instance of JVM is created every time java command is written on the
command prompt to run the java class which is known as Runtime Instance.

Java Source Code Compilation and Execution in JVM


There are three (3) main functions of the JVM. These are: 1) reading or
loading the bytecode; 2) verifying the bytecode; and 3) linking the code with the
Java libraries.
To better understand how JVM works, the diagrams below show the
process of compiling (see figure 2) and executing (see figure 3) the Java codes in
JVM.

12
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Java Source Bytecode


Code
compute.java
main() {
getsum(); compute.class
getProduct();
}

getProduct.java

getProduct() { COMPILER
getProduct.class
}

getSum.java

getSum() {
getSum.class
}

Figure 2 Process of Compiling Java Codes

In the diagram above, the main java program is stored in compute.java.


It contains getProduct(); and getSum(); methods. getProduct method is
stored in a file named getProduct.java; and getSum method is stored in a file
getSum.java. The Java complier will compile the java files and produce its
equivalent .class files that consists of the bytecode.

RAM
JVM

Class
Loader
compute.class

JVM Memory

JVM Native
Class PC
Heap Language Method
Area Stack
Register
Stacks
getProduct.class
Java Runtime Access

getSum.class Native Java


Execution
JIT Native
The JVMEngine
basically resides on the Random Method
Garbage
Compiler Collector
Access Memory Method
(RAM).
Interface
Interface

Figure 3 JVM Architecture

13
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

As shown in figure 3, the internal architecture of JVM contains the class


loader, memory area, execution engine and others. The JVM loads code, verifies
code, executes code and provides runtime environment. It also provides the
definitions for the memory area, class file format, register set, garbage-collected
heap, fatal error reporting and others.
During execution, the class files (compute.class,
getProduct.class, and getSum.class) are brought on the RAM using
Class Loader. After loading the class and lay outing the memory, the bytecode is
verified using bytecode verifier to test the format of the code fragments and checks
the code for illegal codes that could violate access rights to objects and/or any
security bridges. Once it’s done, the execution engine converts the bytecode into
a machine language of the computer you are using through the Java Interpreter,
the Just In Time (JIT) Interpreter.

The Bytecode
Bytecode is a special machine language that can be understood
and interpreted by the JVM. The bytecode is not computer hardware
dependent. Java programs can be compiled into bytecodes on any
platforms that contains Java Compiler. Using the bytecode resolves
security and portability issues for Internet programming.

INTERPRETER

Windows

INTERPRETER
compute.java COMPILER

Macintosh

INTERPRETER

Macintosh

Figure 4 Process of Compiling Java Programs into Bytecodes on Any Platform

Figure 4 illustrates how java program is compiled into bytecodes


on any platform that has a Java interpreter. The compilation process is
done once while interpretation happens each time the program is
executed.

14
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

3.2 Java Runtime Environment

The Java Runtime Environment (JRE) runs the codes compiled for JVM
and performs class loading, code verification and code execution. It does provide
set of libraries, JVM and other components to run Java applications. JRE can be
downloaded from java.sun.com and www.oracle.com/technetwork/java.

3.3 Java Development Kit (JDK)

The Java Development Kit (JDK) is a software development environment


which is used to develop Java applications and applets. It contains JRE, the JVM
and development tools such as an java – an interpreter/loader, javac – a compiler,
jar – an achiver, Javadoc – a documentation generator and other tools that plays
important role in developing a Java application.
JDK is an implementation of any one of the Java Platforms released by
Oracle Corporation: 1) Java Standard Edition, 2) Java Enterprise Edition, and 3)
Micro Edition Java Platform.

Supplementary Learning Resources


1. What is JVM (Java Virtual Machine)? with Architecture: Java programming
Tutorial [Youtube video] https://www.youtube.com/watch?v=G1ubVOl9IBw

2. Difference between JDK, JRE and JVM


[youtube] https://www.youtube.com/watch?v=7tndaxgk1E8

3. JDK, JRE, JVM: What Are They and What Are Their Differences?
[youtube] https://www.youtube.com/watch?v=BXFHuaQNnLo

15
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER3

Test Yourself 3-3

Discuss the differences of JVM, JRE and JDK. (15 pts.)

16
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

LESSON 4: The Java Platforms

Java is basically an application development platform. Platform is defined as a


combination of hardware and software environment where a program runs such as
Windows 10 on Intel processors, IOS on iPad, and android on hummingbird processors.
All Java platforms consists of a Java Virtual Machine (JVM) and an Application
Programming Interface (API). Java is an environment in which Java programming
language applications runs.

These are four (4) platforms or editions of Java Programming Language:

1. Java Platform Standard Edition (Java SE)


The JAVA SE’s API provides the core functionality of the Java language. It
includes Java programming APIs such as java.lang, java.io, java.net, java.util, java.sql,
java.math etc. and core topics such as OOPs, String, Regex, Exception, Inner classes,
Multithreading, I/O Stream, Networking, AWT, Swing, Reflection, Collection, etc.
The Java SE platform also consists of a virtual machine, development tools,
deployment technologies, and other class libraries and toolkits used in Java
applications.

Figure 5 The Java Standard Edition (Java SE)


17
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

2. Java Platform Enterprise Edition (Java EE)

The Java EE is used to develop web and enterprise applications. It is built on


the top of the Java SE platform and it is used for developing server-side applications.
The Java EE applications is made up of components such as Java Servlets, Java
Server Pages (JSP), Web Services, Enterprise Java Beans (EJB), Java Archive (JAR)
Files JPA, etc.

Client J2EE Server

browser Java JSP


Servlet Page

Web Container
Database
Application
Client
Enterprise Enterprise
Bean Bean
Application
Client Container
EJB Container

Figure 6 Java Platform EE Architecture Diagram

3. Java Platform Micro Edition (Java ME)


Java ME platform is used to develop mobile applications. It provides an API
and a virtual machine for running Java programming language applications on small
devices, like mobile phones, pagers and personal organizers. The API is basically a
subset of the Java SE API, along with special class libraries useful for small device
application development. Java ME applications are clients of Java EE platform
services.

Application
Vendor
Optional
Profile Specific
Packages
Classes-
OEM

Configuration
Native Operating System
Device/Hardware

Figure 7 Java Platform ME Architecture


Diagram

The Java ME is composed of the following elements:

18
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

1. Configuration: it defines a minimum platform including the java language,


virtual machine features and minimum class libraries for a grouping of
devices. E.g. CLDC
2. Profile: it supports higher-level services common to a more specific class of
devices. A profile builds on a configuration but adds more specific APIs to
make a complete environment for building applications. E.g. MIDP
3. Optional Package: it provides specialized service or functionality that may
not be associated with a specific configuration or profile. The following table
lists some of the available packages:

Packages Description
JSR 75 PIM PDA Package
JSR 82 BTAPI Java APIs for Bluetooth
JSR 120 WMA Wireless Messaging API
JSR 172 J2ME Web Service
JSR 179 Location API for J2ME 12

It includes two kinds of platforms:

• High-end platform for high-end consumer devices such as TV set-top


boxes, Internet TVs, auto-mobile navigation systems. It does include
elements such as MIDP, CLDC, and KWM.
• Low-end platform for low-end consumer devices such as cell phones,
and pagers. It does include personal profile, foundation profile, CDC,
JVM.

4. JavaFX
JavaFX platform is used to create rich internet applications. It uses a light-
weight user interface API and hardware-accelerated graphics and media engines to
take advantage of higher-performance clients and a modern look-and-feel as well as
high-level APIs for connecting to networked data sources. JavaFX applications may
be clients of Java EE platform services.

JavaFX API Scene Graph

Quantum Toolkit

Web
Prism Glass Media
view

Win32 OpenGL G
Web kit streams
GTK D3D

JDK API and Tools

Java Virtual Machine

19
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Figure 8 JavaFX Architecture Diagram

Supplementary Learning Resources


1. What is Java Platform? Java Tutorial [youtube videos]
https://www.youtube.com/watch?v=uicd3mMEBf0\

2. Java vs Java EE : What’s the Differences? [youtube videos]


https://www.youtube.com/watch?v=jmLfIZw2WWY

3. Java Enterprise vs Java SE vs Java ME vs Java FX [youtube videos]


https://www.youtube.com/watch?v=gGwGR90ypFc

20
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER3

Test Yourself 3-4

Give the differences of the four Java platforms. (20 pts.)

Java SE Java EE Java ME Java FX

21
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

LESSON 5: Java Features

1. Simple 2.
14. Platform
Dynamic Indepen-
dent

13. 3.
Distribute Object-
d Oriented

12. Multi-
4. Fast
Threaded

JAVA
Features
11. High
Perfor- 5. Secure
mance

10. 6. Large
Interprete Standard
d Library

9.
Architec- 7.
ture Portable
Neutral 8. Robust

Figure 9 The Java Features

1. Simple

Java language is a simple programming language. The language is simple


and its syntax is easy to understand and learn since the syntax is based on C++.

2. Java is platform independent


The Java codes written on one platform or operating system can be run on
other platforms without altering or modifying any codes.
JVM is used to run java programs. It executes the Java bytecode. Then, JVM
is executed by the computer’s central processing unit.
All JVMs work the same way having the same codes works on multiple
platforms or operating system such as Windows, Linux, Sun Solaris, Mac/OS, etc.
which makes Java a platform independent.

3. An object-oriented Language
Java is an object-oriented programming language just like C++ and Python
languages. Writing programs using object-oriented style is a popular one. Object-

22
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Oriented Programming (OOP) language is a model where programs are organized


around data or objects. It combines different types of objects that has unique
attributed and behavior.
OOP streamlines software development and makes codes easier to
maintain. The three (3) major features of object-oriented are polymorphism,
encapsulation and inheritance.

4. Java is fast
Java is one of the fastest programming languages like C or C++ languages
and even faster that Python and PHP languages.

5. Java is secure
Java provides a secure platform for developing and running virus-free
applications. It handles automatic memory management, reduces memory corruption
and vulnerability and provides secure communication by protecting the integrity and
privacy of data transmitted.

6. Large Standard Library


Java environment provides a rich set of classes and methods in different
packages. Some of the java packages are: java.lang which has advanced features
of strings, arrays and others; java.util for data structures, expressions, date and time
functions; and java.io for input and output file, exception handling, etc.

7. Portable

Java is portable because it facilitates you to carry the Java bytecode to any
platform. It doesn't require any implementation.

8. Robust

Java is robust or strong because it uses strong memory management,


there is a lack of pointers that avoids security problems; there is automatic garbage
collection in java which runs on JVM to get rid of objects which are not being used by
a Java application anymore and there are exception handling and the type checking
mechanism in Java.

9. Architecture Neutral

Java is architecture neutral because there are no implementation


dependent features, for example, the size of primitive types is fixed.

23
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

In C programming, int data type occupies 2 bytes of memory for 32-bit


architecture and 4 bytes of memory for 64-bit architecture. However, it occupies 4
bytes of memory for both 32 and 64-bit architectures in Java.

10. Interpreted

Java supports cross-platform code by Java bytecode. Programs in Java


are written only once but can run on different platforms without modifications.

11. High Performance

Java is faster than other traditional interpreted programming languages


because Java bytecode is "close" to native code. It is still a little bit slower than a
compiled language (e.g., C++). Java is an interpreted language that is why it is slower
than compiled languages, e.g., C, C++, etc.

12. Multi-Threaded

A thread is like a separate program, executing concurrently. We can write Java


programs that deal with many tasks at once by defining multiple threads. The main
advantage of multi-threading is that it doesn't occupy memory for each thread. It
shares a common memory area. Threads are important for multi-media, Web
applications, etc.

13. Distributed

Java is distributed because it facilitates users to create distributed applications


in Java. RMI and EJB are used for creating distributed applications. This feature of
Java makes us able to access files by calling the methods from any machine on the
internet.

14. Dynamic
Java is a dynamic language. It supports dynamic loading of classes. It means
classes are loaded on demand. It also supports functions from its native languages,
i.e., C and C++.
Java supports dynamic compilation and automatic memory management
(garbage collection).

24
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Supplementary Learning Resources


1. Features of Java [youtube videos]
https://www.youtube.com/watch?v=O5hShUO6wxs

2. Features of Java [youtube videos]


https://www.youtube.com/watch?v=y-Ti5HAL_YM

PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER3

Test Yourself 3-5

Choose 3 features of Java and briefly discuss. (15 pts.)


1.

2.

3.

25
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

LESSON 6: Applications of Java

Some of the applications of Java are:


1. Android Applications. Java programming language uses Android
Software Development Kit (SDK) to develop Android applications.

2. Web Applications. Java is used to create Web applications through


Servlets, Struts or Java Server Pages (JSP). Google.com,
Facebook.com, eBay.com, LinkedIn.com was written in Java.

3. Software Development. Eclipse, OpenOffice, Vuze and MATLAB


software uses Java.

4. Big Data Processing. Hadoop, a software framework written in Java,


processes Big Data. When using Hadoop, you need to have knowledge
in Java programming.

5. Trading System. Software developers can create trading applications


having low latency using the Oracle Extreme Java Trading Platform.

6. Embedded Devices. Oracle's Java Embedded technologies provide


platform and runtime for billions of embedded devices like televisions,
SIM card, Blu-ray Disc players etc.
Aside from the above list, Java can also be used for game development,
scientific applications and many others.

1. Desktop GUI Applications: Abstract Windowing Toolkit (AWT) such as


menu, button, list, and numerous third-party components, SWING, scroll
panes, tabbed panel and lists. JavaFX, 3D graphic features and self-
contained deployment model which facilitates quick scripting of Java
applets and applications.

2. Mobile Applications: one of the most popular mobile operating systems,


are usually scripted in Java using the Android Software Development Kit
(SDK).

3. Embedded Systems: SIM cards, blue-ray disk players, utility meters and
televisions, use embedded Java technologies.

4. Web Applications: eCommerce

5. Web Servers and Application Servers: While Apache Tomcat, dominate


the web server space, and Jboss dominate commercial application server
space.

26
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

6. Enterprise Applications: Java EE: the backbone for a variety of banking


applications which have Java running from front user end to back server
end.

7. Scientific Applications: Java is the choice of many software developers


for writing applications involving scientific calculations and mathematical
operations.

Supplementary Learning Resources


1. Applications of Java [youtube videos]
https://www.youtube.com/watch?v=GIIimPGRJh8

2. What are types of java applications | Ask Java |Code Bode


[youtube videos] https://www.youtube.com/watch?v=CadxM2B6zy8

PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER3

Test Yourself 3-6

Choose four applications of Java and discuss. (20 pts.)

1.

2.

3.

4.

27
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

LESSON 7: Java Terminologies

Some of the list of terms you should know before you start learning Java
programming.

Java Class A Java class is a template definition of the methods and variables in
a particular kind of object. An object can be a specific instance of a
class and can contain real values instead of variables.
Class Instance A specific implementation of the Java class.

Static Class A class method that can be called without instantiating the class.
Method

Static Class A class variable that can be accessed without instantiating the class.
Variable

Constructor Initiates the variables and method for a new class instance.
Method

Pseudo- An identifier representing the values from a class instance in a BLOB


Reference variable. Programs must pass this identifier to access the methods
and variables of a class instance.
Java Native Lets non-Java programs interact with Java programs.
Interface

Java Virtual Interprets the bytecode into code that will run on actual computer
Machine hardware.

Java Name Enables Java platform-based applications to access multiple naming


Directory and directory services.
Interface

J2EE Enterprise A Java platform enterprise server that creates standardized, reusable
Server modular components.

Enterprise An architecture for defining Java program components that run on a


JavaBeans client/server network.

Java A program development environment for writing Java applets and


Development Kit applications.

28
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Supplementary Learning Resources


1. 03 - Java Terminology - Learn Java Terms & Definitions [youtube videos]
https://www.youtube.com/watch?v=NUy_wOxOM8E

2. Java Tutorial for Beginners 1 - Basic keywords explained [youtube videos]


https://www.youtube.com/watch?v=f8lCiYquj28

PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER3

Test Yourself 3-7

1. Object-oriented programming uses classes and objects. What are classes and
what are objects? What is the relationship between classes and objects?

2. What is a constructor? What is the purpose of a constructor in a class?

29
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

LESSON 8: Java Development


Environments

Java Applications can be created in any text editors such as Notepad, Wordpad,
TextPad and Notepad++ to name a few.

1.1 Text Editor and Console

Getting started with Text Editor:


Step 1: Check if Java Development Kit (JDK) and Java Runtime Environment
(JRE) are installed.
Step 2: Open a command-line window (cmd). Type cmd from the search box on
the taskbar then click the Command Prompt.
Start → Run → Type “cmd” → Press Ok

Step 3: Type: java – version in the command prompt to know the version of
JDK/JRE installed. If successful, the following shall appear:

30
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Java Version: 1.8.0_131


Java SE Runtime Environment (build
1.8.0_131-b11)

➢ If the message is: java’ is not recognized as an internal or


external command. Then JDK is not installed.

Writing and Compiling your first Java program

4. Open a text editor, the Notepad++,

31
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Then type the following java codes:

5. Save the file as C:\myjavaprograms\HelloWorld.java.


▪ Select File → Save
▪ Type “HelloWorld.java” in the filename field
▪ Click the Save.

Note: Java is case-sensitive. The filename must be the same as the


class name. HelloWorld is not the same as Helloworld.

6. Open the command prompt window.

Start → Run → Type “cmd” → Press Ok

7. Compile the java program to bytecode using javac.


▪ Go to myjavaprograms folder by typing:
cd c:/myjavaprograms
▪ Then, type javac HelloWorld.java to compile the
program.

32
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

If you get a message: ‘javac’ is not recognized as an internal or


external command, operable program or batch file.

To resolve the issue, do the following:

a. Find the java path, it looks like: C:\Program


Files\Java\jdk1.8.0_131

b. Start-menu search for "environment variable" to open the


options dialog.

33
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Click to open
the environment
variable window

Click Edit to
open the Edit
Environment
Variable window

c. Add the new Java path to PATH.


Click New to
add the path

34
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Add the java path:

C:\Program
Files\Java\jdk
1.8.0_131\bin

d. Click Ok, Close and re-open console/IDE

8. Check for the generated bytecode.


Type: dir *.*

9. Run the program using the Java launcher

Syntax: java <programname>


Example: java HelloWorld

Output of the
program

35
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

1.2 Graphical User Interface Environment (Eclipse-Window Builder)

Eclipse IDE
Eclipse is an excellent open source IDE for Java developed by
International Business Machines (IBM) team and was written in Java itself.
Eclipse is written in Java and will thus need an installed JRE or JDK in
which to execute. Check for the java version installed.

Installing Eclipse
1. Download Eclipse IDE on www.eclipse.org.
2. Unzip the downloaded file on Program Files.
3. Create a Desktop shortcut.

Selecting Your Workspace

• A workspace is nothing more than a location where you will store


your source code and where Eclipse will write out preferences;
• Eclipse allows you to have multiple workspaces – each tailored in
its own way.

36
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Welcome to Eclipse

Eclipse IDE Workbench

37
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Eclipse IDE Components

Creating a New Project

• All code in Eclipse


needs to live under a
project
• To create a project:
File → New → Java
Project
• Enter a name for the
project, then click
Finish
• The newly created
project should then
appear under the
Package Explorer

38
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Creating a Class

• To create a class,
simply click on the
New button, then
select Class
• This brings up the
new class wizard
• From here you can
specify the
following...
– Package
– Class name
– Whether or
not to include
a main
– Etc…
• Fill in necessary
information then
click Finish to
continue

The Created Class

39
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Compiling Source Code

▪ One huge feature of Eclipse is that it automatically compiles


your code in the background
- You no longer need to go to the command prompt and
compile code directly

▪ This means that errors can be corrected when made


- We all know that iterative development is the best approach
to developing code, but going to shell to do a compile can
interrupt the normal course of development
- This prevents going to compile and being surprised with
100+ errors

An example of a compilation error:

The codes below contain a typographical error in the


println statement

• When clicking on the light bulb, Eclipse suggests changing


printn to either print to println

40
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Running the Code

To run the code, right click on the class and select Run As →
Java Application

41
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

• The output of running the code can be seen in the Console tab in
the bottom pane

Re-Running the Code

• After you run the code a first time, you can re-run it just by
selecting it from the run drop down menu

42
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Debugging Code

• Eclipse
comes with a
pretty good
built-in
debugger

• You can set


break points
in your code
by double
clicking in the
left-hand
margin –
break points
are
represented
by these blue
bubbles.

• An easy way to enter debug mode is to right click on the class and
select Debug As → Java Application

43
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

• The first time you try to debug code you will be presented with the
following dialog

• Eclipse is asking if you want to switch to a perspective that is


more suited for debugging, click Yes
• Eclipse has many perspectives based on what you are doing (by
default we get the Java perspective)

Debug Perspective

44
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Javadoc Assist

• Eclipse can also help generate javadoc comments for you,


simply place the cursor before the method and then type “/**”
then Enter

• Eclipse will automatically generate a javadoc header for the


method all stubbed out with the parameters, return type and
exceptions

45
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Tasks

• Eclipse allows you to insert reminders into your code and stores
them for you to come back and revisit them

• Eclipse recognizes the following tags inside comments…


- TODO
- FIXME
- XXX

• You can even add your own custom tasks through the
preferences menu

46
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

• To add a table of all reminders in all of your source code you can
add the Tasks view by clicking on Window → Show View →
Tasks

• This neatly displays all tasks in a tabular form

47
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Local History
• Eclipse maintains a local history of file revisions which can be
accessed by right clicking on the class, then selecting
Compare With → Local History…

• Previous saved revisions are displayed in the History pane, double click a
revision to view in the built-in diff viewer

48
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

Synthesis

This module has given a tour inside Java, digging the corners of Java internal
architecture. You now have a grasp on how to create, run and compile java programs
using a text editor such as notepad.
What was covered in this module are the components of Java’s architecture, what
Java Virtual Machine (JVM) is and how it functions, the internals of the JVM architecture,
and the Java class file format.
Given the foundations of Java, you are now ready to begin learning how to use
all the various components of the Java platform in detail, starting with library, class, and
method design.

Supplementary Learning Resources

1. Tutorials Point (India( Ltd, I. (2018). Java - Environment Setup [YouTube Video]. In
YouTube. https://www.youtube.com/watch?v=bxIZ1GVWYkQ

2. thecoderworld. (2019). How to Setup Eclipse IDE on Windows For Java


Development. In YouTube. https://www.youtube.com/watch?v=rSFraftR4I4

3. edureka. (2020). edureka! [YouTube Video]. In YouTube.


https://www.youtube.com/watch?v=JbHFCQ66jRg

49
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER3

Test Yourself 3-8

1. Create a class named happiness. The program should output the following lines
on the screen:

“May the God of hope fill you with all joy


and peace as you trust in him, so that you
may overflow with hope by the power of the
Holy Spirit.” ~ Roman 15:13

2. Write a Java program to print 'Hello' on screen and then print your name on a
separate line.

3. Write a Java program to print the sum of two numbers.

4. Write a Java program to divide two numbers and print on the screen.

5. Write a Java program that takes two numbers as input and display the product of
two numbers.

50
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

PROGRAM / YR / BLK:
COURSE CODE / TITLE: AEC9 – Business Logic
TIME / DAY:
CHAPTER3

Assignment

Using the Eclipse IDE, solve the following programs.

1. Write a Java program to print the sum (addition), multiply, subtract, divide and
remainder of two numbers.

2. Write a Java program that takes a number as input and prints its multiplication
table up to 10.

3. Write a Java program to print the area and perimeter of a circle.

4. Write a Java program that takes three numbers as input to calculate and print the
average of the numbers.

5. Write a Java program to print the area and perimeter of a rectangle.

51
Catanduanes State University College of Information and Communications
Technology
Chapter 3: Introduction to Java Programming

References

www.codejava.net. (2020, April 2). Java SE versions history. CodeJava.net - Java


Tutorials, Code Examples and Sample Projects. Retrieved May 6, 2020, from
https://www.codejava.net/java-se/java-se-versions-history

Farrell, J. (2017). Programming logic & design, comprehensive (9th ed.). Cengage
Learning.

Java (2006) Education and Development Initiatives. Introduction to Programming


Student’s Manual.

Javatpoint. (2018). Features of Java. www.javatpoint.com. Retrieved May 22, 2020,


from https://www.javatpoint.com/features-of-java

Linda DeMichiel, Bill Shannon (2017). Oracle: Java Platform, Enterprise Edition (Java
EE) Specification, v8 Oracle America, Inc.

Oracle. (2012, April 1). Differences between Java EE and Java SE - Your first cup: An
introduction to the Java EE platform. Moved.
https://docs.oracle.com/javaee/6/firstcup/doc/gkhoy.html

Oracle. (2020). Java(TM) web start. Oracle | Integrated Cloud Applications and Platform
Services. Retrieved May 11, 2020, from
https://www.oracle.com/technetwork/java/javase/tech/index

Parewa Labs Pvt. Ltd. (n.d.). Learn Java programming. Programiz: Learn to Code for
Free. Retrieved June 2, 2020, from https://www.programiz.com/java-programming

Shildt, Herbert (2005). Java: A Beginner’s Guide, Third Edition, McGraw-Hill

52
Catanduanes State University College of Information and Communications
Technology

You might also like