Sie sind auf Seite 1von 21

Introduction to

Objectives
• Learn the Java program structure and the essential
methods
• Learn how to compile and run a simple Java program
• Learn the different characteristics of Object-oriented
Java.

Copyright 2018 Aimee Theresa A. Fontanilla


The Java Programming Language

• Java technology is both a programming language and a


platform.
• Developed by Sun Microsystems and came out in 1995 and
has since then become the fastest growing programming
language ever.
• Has similarity with C and C++.
• Platform independent

Copyright 2018 Aimee Theresa A. Fontanilla


The Java Programming Language
• developed by James Gosling, Patrick Naughton, Chris
Warth, Ed Frank & Mike Sheridan at Sun Microsystems,
Inc. in 1991.
• created for the world wide web.
• made an enormous effect on the Internet around the
year 1995.
• expands the universe of objects that can move freely on
the web.
• created the applet, a small program that is
embedded in an HTML code.

Copyright 2018 Aimee Theresa A. Fontanilla


Java Versions

• Java 1.0 compiler was re-written in Java by Arthur van Hoff


to comply strictly with the Java 1.0 language specification.
• With Java 2, new versions had multiple configurations built
for different types of platforms.
 J2EE included technologies and APIs for enterprise
applications typically run in server environments
 J2ME featured APIs optimized for mobile applications.
 J2SE is the desktop version was renamed.

 In 2006, Sun renamed new J2 versions as Java EE, Java


ME, and Java SE

Copyright 2018 Aimee Theresa A. Fontanilla


Java Versions

As of 2015, only Java 8 is supported ("publicly"). Major release versions


of Java, along with their release dates:
• JDK 1.0 (January 21, 1996)
• JDK 1.1 (February 19, 1997)
• J2SE 1.2 (December 8, 1998)
• J2SE 1.3 (May 8, 2000)
• J2SE 1.4 (February 6, 2002)
• J2SE 5.0 (September 30, 2004)
• Java SE 6 (December 11, 2006)
• Java SE 7 (July 28, 2011)
• Java SE 8 (March 18, 2014)

Copyright 2018 Aimee Theresa A. Fontanilla


Java Owner

• Oracle Corporation bought Sun Microsystems on January 27,


2010
• Oracle is now the owner of the official implementation of
the Java SE platform
• "steward of Java technology with a relentless commitment
to fostering a community of participation and transparency”
• lawsuit against Google which used Java inside the Android
SDK

Copyright 2018 Aimee Theresa A. Fontanilla


Helloworld.java

public class Helloworld {


public static void main (String arg[ ]) {
System.out.println (“Hello world”);
} // end of main method
} // end of class

Copyright 2018 Aimee Theresa A. Fontanilla


Helloworld.java

• public: an access modifier for class and methods which


indicates that a particular class or method can be accessed
by anything and anywhere

• Helloworld: this is the class name. For an Application class,


the class name is the same as the filename.

• static: a keyword that tells the compiler that this is a method


that is usable in the context of the class Helloworld. It
makes possible the application class to be standalone.

Copyright 2018 Aimee Theresa A. Fontanilla


Helloworld.java

• void: indicates that this method does not return anything

• String arg[ ]: declares the String array arg. It contains


arguments typed on the command line

• System.out.println( ): a built-in method used to display any


string value on the screen

• “Hello World”: a string value or constant to be displayed on


the screen

Copyright 2018 Aimee Theresa A. Fontanilla


Class, Objects and Methods

System.out.println (“Hello world”);

Class
Object
Method
Actual Parameter

Copyright 2018 Aimee Theresa A. Fontanilla


Running Java Programs
(using the command line)
• First and foremost write the source code of the program
using any text editor
• After completion save the file as <class_name>.java
• Run command prompt and go to the file's directory
• To compile, type "javac <class_name>.java"
• To run, type "java <class_name>"

javac java
Helloworld.java Helloworld.class

Java source code Bytecode or class file

Copyright 2018 Aimee Theresa A. Fontanilla


Elements of Java Programming
• Java programming language/Java program
• Java Virtual Machine (JVM)
• Java Application Programming Interface(API)
• Java Runtime Environment (JRE)

JAVA PROGRAM
API

JRE

JVM

INSTALL JDK (Java Development Kit)


Copyright 2018 Aimee Theresa A. Fontanilla
Elements of a Java Source file
• optional package declaration
• import statements
• class and interface definitions

package mypackage;
import java.io.*;
public class helloworld{
// class body here ...
}

Copyright 2018 Aimee Theresa A. Fontanilla


Java Virtual Machine (JVM)
• The JVM is an imaginary
machine that is implemented
by emulating it in software on
a real machine.
• It provides the hardware
platform specifications.
• The JVM also takes care of
reading compiled byte codes
that are platform
independent.

Copyright 2018 Aimee Theresa A. Fontanilla


Application Programming Interface (API)
• a large collection of ready-made software components
(built-in classes and methods) that provide many useful
capabilities.
• provides standard ways to read and write files, manipulate
strings, Build GUI, & other essential functions.

• The components of the Java API are grouped into libraries


called packages.
• standard across all implementations of Java, so the
program that uses them to implement some function will
run properly on any computer system that implements
Java.
• already debugged, so using them reduces the total effort
to write and debug a program.

Copyright 2018 Aimee Theresa A. Fontanilla


Java Runtime Environment

• The JRE does the following tasks loads the code, verifies the
code and executes the code. It allows Java to be a
programming language that is well suited to designing
software that works in conjunction with the Internet.

• Thus, Java is a cross-platform language, which means its


programs can be designed to run the same way on Microsoft
Windows, Apple Macintosh, UNIX, etc. Java extends beyond
desktops to run devices such as televisions, wristwatches,
and cell phones.

Copyright 2018 Aimee Theresa A. Fontanilla


Characteristics of Java
• Object-oriented
An object-oriented language deals with objects. Objects contain both data
and code. Objects are instances of a particular class, which is a definition
of the member variables and methods the object offers.

• Portable
Java code is compiled into a platform-independent machine code called
bytecode. Java makes use of the JVM – Java Virtual Machine, a special
kind of interpreter.
JAVA bytecode

JVM JVM JVM

Windows Copyright 2018 Aimee Theresa A. Fontanilla


Linux
Mac OS
Characteristics of Java
• Multithreaded
Java is capable of running several
applications simultaneously using threads.
A thread is a part of the Java program that
is set up to run on its own. Threads can
share data and code and usually used for
controlling animation.

• Automatic Garbage Collection


Java allows for reclaiming unused memory
space. This is to ensure that the space
allocated by the JVM when objects are
created are freed when these objects are
no longer in use.

Copyright 2018 Aimee Theresa A. Fontanilla


Characteristics of Java
• Secure
Java provides a mechanism for protecting the system against inadvertent security
violations. This is done both at the documentation and bytecode level.
• Network and Internet available
Java supports network programming and provides extensive
support for internet applications.
• Simple
Java is rooted in C++ but is considered to be much simpler since it does not make use of
pointers and provides a comprehensive library of classes and methods.
C Java
include <stdlib.h int [] intarray = new int [100];
int *ip, ar[100];
ip = (int *)malloc(sizeof ar);
Copyright 2018 Aimee Theresa A. Fontanilla
Java Principles

There were five primary goals in the creation of the Java


language:
• It must be "simple, object-oriented, and familiar".
• It must be "robust and secure".
• It must be "architecture-neutral and portable".
• It must execute with "high performance".
• It must be "interpreted, threaded, and dynamic".

Copyright 2018 Aimee Theresa A. Fontanilla


Ciao!

Sources:
SL-275 Sun Microsystems
Oracle
Wikipedia

Aimee Theresa Avanceña Fontanilla


August 2018

Copyright 2018 Aimee Theresa A. Fontanilla