Week 1 - CM - MDL - CS213
Week 1 - CM - MDL - CS213
Learning Outcomes:
After completing this course you are expected to demonstrate the following:
1. Discuss the core concepts and main features of OOP and explain the object oriented
approach. Discover the history of Java, its key features, and how the Java technology
works.
A. Engage
Trivia
The earliest version of Java was known as Oak. This was inspired by a big oak tree that grew
outside the window of the lead creator of Java, James Gosling. It was later changed to Java
by Sun’s marketing department when Sun lawyers found that there was already a computer
company registered as Oak.
B. Explore
Video Titles:
1. What’s a Programming Language?
2. OOP
3. History of Java
YouTube Links:
1. https://youtu.be/NUl8lcbeN2Y
2. https://youtu.be/qwS-BCOCB-A
3. https://youtu.be/DcQPtlFlgzY
Module Video Filenames:
1. Introducing object-oriented programming_WEEK1
2. OOP Infographic Animation_WEEK1
3. History of Java_WEEK1
C. Explain
D. Elaborate
Figure1.1
Benefits of OOP
Application of OOP
OOP is now one of the programming buzzwords today. There seems to be a great deal
of interest and excitement in using OOP among software engineers. Uses of OOP are
beginning to get value in many places. The most popular application of object
object-oriented
programming, up to now, has been in the place of user interface design for example
window. Hundreds of windowing systems are developed, using the OOP techniques.
Prepared and
nd Validated By: Ms. Ruth L. Tarraya, B
BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 2 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
Real-Business System
Are generally much more complex and contain many more objects with complicated
attributes and approach. OOP is useful in these types of application because it can
simplify a complex problem. The bright areas of application of OOP include:
Since the 1980s the word ‘object’ has appeared in relation to programming languages, with
almost all languages developed since 1990 having object-oriented features. Some languages
have even had object oriented features retro-fitted. It is widely accepted that object-oriented
programming is the most important and powerful way of creating software.
Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 3 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
If we think of a real-world object, such as a television (as in Figure 1.2), it will have several
features and properties:
1. We do not have to open the case to use it.
2. We have some controls to use it (buttons on the box, or a remote control).
3. We can still understand the concept of a television, even if it is connected to a DVD
player.
4. It is complete when we purchase it, with any external requirements well documented.
5. The TV will not crash
A class should:
- Provide a well-defined interface - such as the remote control of the television.
- Represent a clear concept - such as the concept of a television.
- Be complete and well-documented - the television should have a plug and
should have a manual that documents all features.
- The code should be robust - it should not crash, like the television.
The object-oriented model should provide advantages over the other models, especially as the
library of components that is developed grows over time.
Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 4 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
Figure 1.3
In 1991, Sun Microsystems funded the research project called “Green” to design a
programming language to be used in intelligent consumer electronic devices, like televisions,
VCRs, and washing machines. Since home appliance processor chips change on a continuous
basis, the programming language used needed to be extremely portable. Existing
programming languages such as C++ were clearly not suitable. Often, the embedded language
was tied closely to the appliance processor, an
and
d a new language needed to be developed. This
new language was originally termed Oak (referring to the tree that was outside the main
developer’s, James Gosling’s, window), but was quickly renamed Java. The use of Java for
home appliance applications turne
turned
d out to be initially unsuccessful, but the emergence of the
Web gave it a new future. In 1994, the first Java
Java-enabled
enabled web browser HotJava was developed.
A year later, Netscape incorporated Java support into its web browser. Other companies
quickly followed
d and Java’s popularity rapidly rose. Sun released Java 1.0 to the public in 1995.
In 2007, Sun made Java’s core code available as open source under the terms of the GNU
General Public License (GPL). In 2009, Sun was acquired by Oracle, which is currently
continuing the development of Java. Table 22-1 1 gives an overview of the major releases,
together with some key characteristics. Note that the versions were originally referred to as
JDKs (Java Development Kits) and later rebranded into J2SE (Java 2 Platform Platform, Standard
Edition).
Prepared and
nd Validated By: Ms. Ruth L. Tarraya, B
BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 5 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
Features of Java
The key characteristics of the Java programming language that have made it so popular include
the following:
1. Simple: Java omits some of the vaguely defined features of C++. It has facilities for
automatic garbage collection to automatically release unused memory while a program
is running. It also includes a rich predefined set of packages (such as for mathematics,
statistics,
istics, database access, GUI design, and so on) that can be easily reused by
application developers. Its syntax looks very similar to C/C++, making it easy for
experienced programmers to learn and use.
2. Platform independent and portable: By using a hybrid compilation/interpretation
c
approach, Java programs can be executed in a networked environment with different
hardware platforms and architectures. This also makes Java applications extremely
portable, effectively realizing the “write once, run everywhere” pphilosophy.
3. Object-oriented: Java implements the object-oriented oriented programming paradigm by
grouping data and operations into classes and/or objects.
4. Secure: Java has many facilities to guarantee security in a networked environment. It
imposes various types of access restrictions to (networked) resources and carefully
supervises memory allocation. It allows code to be downloaded over a network and
executed safely in the confined spaces of memory. It also foresees extensive capabilities
for configuring security levels.
5. Multi-threaded: Java delivers the power of advanced multi multi-threaded capabilities to the
developer in an environment without complexity. More specifically, Java code can be
run concurrently as multiple threads in a process, in order to improve its ex execution
performance.
Prepared and
nd Validated By: Ms. Ruth L. Tarraya, B
BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 6 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
6. Dynamic: Java allows code to be added to libraries dynamically and then can determine
which code should run at execution time. It also foresees a strict separation between
interface and implementation.
Looking Under The Hood take a look under the hood of Java. (Java bytecode, the Java Runtime
Environment (JRE), and Java platforms and applications)
Bytecode
every Java source program (BMI.java) is compiled into an intermediate language called
bytecode (BMI.class), which is platform independent. During this compilation step,
errors in the code can be reported.
Java bytecode is not native machine code, so it cannot be run as such on a host
computer.
Instead, the bytecode will be parsed by a platform-specific interpreter in order to run it
on a particular architecture, such as on Windows, Linux, Mac OS, Sun Solaris, and so on.
Can be considered as machine code for the JVM.
Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 7 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
When developing new Java applications, it is important to consider the API to see if you can use
some of the functionalities that are already implemented. This saves you from having to
program every aspect yourself, and it can also make your program more recognizable and
usable to other programmers. The API is flexible and open, which means that new packages or
libraries can be added to it on an ongoing basis.
Class Loader
The class loader locates and reads the *.class files needed to execute the Java program
and loads the bytecodes into memory. To safeguard a secure execution, it can assign
different portions (namespaces) of memory to locally versus remotely obtained classes.
Classes are typically assembled into libraries that are stored physically in JAR (Java
Archive) files. The libraries may have been written by the user or obtained externally. In
order to locate the classes, the class loader will first find the corresponding libraries and
then load the classes as they are needed by the program (called ondemand loading).
Bytecode Verifier
The bytecode verifier checks to make sure the bytecodes are valid without breaching
any of Java’s security rules. It pays special attention to type checking all the variables
and expressions in the code and ensures that there is no unauthorized access to
Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 8 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
memory. Note that when a Java program is invoked, you can choose to disable the
bytecode verifier (which will make it run slightly faster), enable it only for code that was
downloaded remotely from the network, or enable it for all the code. Once the code is
verified, it will be offered to the Java Virtual Machine (JVM) for interpretation.
Java platforms
A Java platform or edition consists of a JRE with a specific set of libraries for a specific
application environment.
Java applications
standalone applications
Java applets
Java servlets
Java beans
Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 9 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
The program contains several statements, each ending with a semicolon (;). A statement
performs a specific action and can span multiple lines.
First, note that Java is a form-free language and does not require special
indentation.
Any statement can start at any place of indentation.
Also, extra whitespace, tabs, and new lines are ignored by the compiler. The
program can thus be formatted in many ways. To improve the readability of your
code, it is highly recommended that you use a consistent formatting style.
Classes
Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 10 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
Variables
Methods
Is a piece of code within a class definition, and it performs a specific kind of
functionality.
Java Data Types
Java is a strongly typed language. This means that every variable should first
be carefully declared upfront before it can be used.
Primitive Data Types
Java supports eight built-in primitive data types. If the user has not initialized
a variable, the compiler will automatically assign the default value. Note that
the ranges and default values are uniform and do not depend on the
underlying machine architecture on which the Java program runs.
Table 1.5 defines each of these and specifies the range and default value.
Table 1.5 Java Primitive Data Types
Literals
Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 11 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
Note that literals of type long, float, and double can end with the letters L/l, F/f, and D/d,
respectively. Floating point literals can also be expressed in scientific notation using E or e.
Character literals (char) are always enclosed in single quotes and may contain any Unicode
character (see www.unicode.org for more details).
Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 12 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester
E. Evaluation
ASSESSMENT:
Instructions: You may write your answer on the Answer Sheet (AS) provided in this module.
References:
Facilitated By:
Name :
MS Teams Account (email) :
Smart Phone Number :
Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 13 of 13