Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

MODULE 1

Computer Programming 1 with LAB

Task 1: Able to analyze the Importance and Advantage of Java programming.


1. On your own opinion, what will be the advantage of using Java as your programming
language in creating your Programs?
- Compared to other languages and environments, Java has major benefits that
make it ideal for just about any programming activity.
Advantages of Java:
1. It is easy to understand Java.
Java was built to be convenient to use and is thus simpler than other programming languages to
write, compile, debug, and understand.
2. Java is object-oriented.
This helps you to create modular programs and code that can be reused.
3. Java is separate from the platform.
One of Java's most valuable benefits is the ability to seamlessly switch from one operating
device to another. World Wide Web software is important for the ability to execute the same
program on several different platforms, and Java succeeds at this by being platform-independent
at both the source and binary stages.

2. What does the Java Compiler do base on your understanding?


- The key functionality of the compiler is to translate high-level language to low-
level language that is interpreted by the computer, for example in the programming language
C/C++, the compiler explicitly translates source code into machine language code that relies on a
given platform. In the case of Java, where it is entirely different. As a Javac, Java has a compiler
name that translates source code to intermediate code known as java bytecode. If you compile
your source code on a Windows platform using a Javac compiler, this Java bytecode does not
rely on any platform, so you can run this code on any other platforms such as Linux, Mac.
Currently, this bytecode is not a native code; it is an intermediate code. There is a virtual
machine in Java that transforms intermediate code into the JVM (Java Virtual Machine) native
code. In reality, the JVM functions like an interpreter, and the first feature is to check bytecode,
and JVM has a compiler known as the JIT (Just In Time) Compiler. Therefore, JVM takes
bytecode and directly compiles the bytecode and transforms it to computer based native code by
sending it to the JIT and JIT compiler.
3. Does the role of Garbage Collector vital? Prove your answer?
- Java applications store objects in memory as required. The Garbage Collection
(GC) duty of the Java Virtual Machine (JVM) is to automatically evaluate which memory is no
longer used by the Java program and to recycle this memory for other purposes. Since memory is
immediately restored in JVM, Java program developers are not burdened with the need to
manually free memory objects that are not being used. The GC operation assumes that most
objects used in the Java code are short-lived and can be retrieved shortly after their production.
Since unreferenced objects are immediately deleted from the heap memory, GC makes Java
memory efficient.
Task 2: Understand and Identify the features of Java Program
1. Choose at least 5 features of Java and give your own understanding based on the Reading
Material No. 2. Give the importance and site an example for each as you discuss.
5 Features of Java
Simple
The Java Language greatly simplify several programming features

➢ Simpler data types (including Boolean types), built-in String type, etc.

➢ No C/C++ pointers, no explicit memory management (such as malloc and free in C)

➢ Allows programmers to be able to produce programs without extensive programming training

➢ Already provides a lot of high-level Application Programming Interface (API) to simplify


various tasks, such as:
▪ Basic Input/Output
▪ String manipulation
▪ Networking / Socket programming
▪ Multithreading
▪ Database Access

Object-Oriented
Java has been built as an Object-Oriented Programming (OOP) language from the ground up
Modern systems such as distributed, client-server systems, networked systems, even Service
Oriented Architecture (SOA) are object-oriented
Java supports basic object-oriented principle, such as:

➢ Abstraction

➢ Encapsulation

➢ Inheritance

➢ Polymorphism

➢ Classes and Objects

➢ Dynamic Binding
Multithreaded
Java has built-in support for multithreading:

➢ Has built-in APIs for threads

➢ Supports integrated thread synchronization

➢ Java threads are pre-emptive and can be time-sliced


Dynamic
Java programs are not statically compiled and linked, unlike other programming languages such
as C and C++
Java has the capability to dynamically run modules during run-time, also called late binding (or
dynamic binding).

Portable
With Java, you can create a program in one platform, and run on different platforms

➢But even so, you still need to test the program on different platforms due to possible
differences in OS specific behavior
Java supports primitive data types that are platform-independent

➢Java’s data types have the same sizes, regardless of the hardware platform (i.e Mac vs
Linux vs Windows, 32-bit vs 64-bit etc.)
Java’s bytecode can be generated on one platform and run on any platform that has a Java
Runtime Environment (JRE) on it.
Task 3: Set Up Java IDE: Setting up the Java Project
1. Create a flowchart on how to setup your First Java Project
Task 4: Able to create your First Project: Hello World Program
1. Create your first application “HELLO WORLD”.
Task 5: Able to Save, Compiling and Run the Program
1. How to Save your file?
- Save your modifications by clicking File | Save.

2. How to Compile and Run Java Program?


- Before Java was created, applications created in other programming languages
were either compiled or interpreted. When a program is compiled, the source code is first
translated into machine language called object code, and then it is linked to that programming
language’s built-in libraries, which are hardware- and OS- dependent. When the object code is
successfully linked with the required libraries, it produces an executable code or a binary.
Interpreted programs, on the other hand, are translated line-by-line by an interpreter, converting
each line into machine language and executed on-the-fly. Java uses a slightly different approach
as it combines compiled and interpreted programs. When a Java source code (whose filename
ends in .java) is compiled, the Java compiler translates the source code into a bytecode—which
is similar to an object code but instead of a hardware- and OS-specific machine language, the
bytecode contains machine language that is specific to the JVM. The resulting bytecode is saved
with a filename ending in .class. The bytecode can now be executed on any machine and
operating system where the JVM is installed. The JVM now interprets each byte in the bytecode,
translates it into native machine instructions and executes it. This makes Java a portable
application—you don’t have to re-compile your source code to different machines and operating
systems; all you need is to install the JVM on different machines, and it will take care of
executing your bytecode.

You might also like