Beruflich Dokumente
Kultur Dokumente
5 hrs)
Chapter Objective:
Describe the key features of Java
List the three flavors of Java
Describe the function of the Java Virtual Machine (JVM)
Describe the function of the Java Runtime Environment (JRE)
Describe the job of Garbage Collector
Describe the three task performed by Java in handling code security.
Create Your First Java Application. The HelloWorld Program.
Debugging compile time errors and runtime errors
Examine Java Classes.
Java key features
Object Oriented
Object Oriented Programming Languages supports three main features: encapsulation,
Inheritance, and polymorphism. In Java, we create programs that is patterned to real life objects.
These objects may interact with other objects like a Student object can interact with a Teacher
object. Also, the nice thing about object oriented programming is its capability to reuse code. You
can create an object that will be used in a project and reuse it in another. Like if you've created an
application you can reuse the same classes for a web application.
Let's say in a Banking Application, you may write a code that represents a Bank
Customer calling it Customer class. This Customer class can actually be reused in other
Application not related to a Banking Project, let's say in an Order and Purchasing Application
System. You don't have to reinvent the wheel or rewrite the Customer class code. What you can
do is to reuse them as they fit in your system.
Simple
Most of the Java syntax was based from C and C++, so if you are a C or C++
programmer, migrating to Java would be very easy.
Java made it easier for C programmers to absorb the concepts of pointers. Instead of
pointers, Java uses the concept of references.
Multi threaded
Java applications can run several threads. A thread is a Virtual CPU. It contains three
things, the CPU (Thread Class), Code and Data.
Page 1 of 9
Network aware
Java applications can run across most types of network.
Cross Platform
Java can run in most popular platform. This feature is valuable to a lot of customers who
have invested on a lot of hardware like minicomputers, mainframes or even desktop computers.
They do not want to throw away these investments when they use another set of standards.
One of the nice things about Java is its capability to run in most platforms once you've
compiled it. You need to compile your *.java file to produce a *.class file which also contains your
Java byte code. Then you can let your *.class run in any Java Runtime Environment on any
platform.
Page 2 of 9
Secure
Java is said to be secured because it runs the applications on top of the Java Virtual
Machine (JVM) and your JVM sits on top of your operating system. It simply means that your
Java application does not have a direct attachment or a direct contact with your operating system.
Supports GUI
Using Java, you can also create Graphical User Interface (GUI) Applications which
enables the user to make use of Buttons, Frames and TextFields. Java has a built-in Abstract
Window Toolkit (AWT) which makes use of the standard GUI components. Besides AWT, Java
also supports Java Foundation Classes (JFC) / Swing, which is supported under the javax (java
extension) package. JFC / Swing is the second generation GUI toolkit and it is light weight as
well.
Using JFC / Swing, you can customize your look and feel of your GUI application and it
has a wider range of GUI components that you can choose from.
Three (3) Flavors of Java
Page 3 of 9
Page 4 of 9
Page 5 of 9
void is the return type of the main method. It means that the main method should not return any
type of value.
main this is the name of the method. However, the main method is a special type of method that
tells Java that this is the starting point of your application. All Java application starts its execution
at the main method and its method signature should be public static void main(String
args[]).
String args[] this goes inside the parameter list of your main method. This means that your
main method should accept an array of String objects as its parameter.
RULE: The execution of any Java Application always starts with your main method.
The signature of your main method should be:
public static void main(String args[])
Line 11: HelloWorld hw = new HelloWorld();
Line11 can be rewritten this way:
1a
2a
HelloWorld hw;
hw = new HelloWorld();
Page 7 of 9
Page 8 of 9
TestHelloWorld.java
HelloWorld.java
Also
compiles
Javac
Java
TestHelloWorld.class
HelloWorld.class
J VM
You only need to compile one file TestHelloWorld.java and the other file
HelloWorld.java will automatically compile. This is because before TestHelloWorld.java
can successfully compile Java looks for a compiled version of HelloWorld.java first. Thus
HelloWorld.java will be the first file that will be compiled before TestHelloWorld.java
completes its compilation.
Page 9 of 9