Sie sind auf Seite 1von 16

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Introducing the Java


and Oracle Platforms

ns
a
r
t
n-

an
s
ha
)
m ide
o
c

il t Gu
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
Copyright
Oracle and/or its affiliates. All rights reserved.
y t2013,
o
a
s
( nse
a
t
r
lice
aku

Sa

ya

h
T
n

bl
a
r
fe

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Objectives
After completing this lesson, you should be able to do the
following:
Identify the key components of the Java SE Java
Development Kit (known as JDK or SDK)
List Java deployment options
Recognize how the JDeveloper IDE supports the
le
b
a
development of Java applications
er
f
s
n
Understanding how to control the Program Flow
-tra

on
n
a

s
a
h
)

m
e
o
d
i
ilc t Gu
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
Copyright
Oracle and/or its affiliates. All rights reserved.
y t2013,
o
a
s
( nse
a
t
r
u
ice
k
l
Objectives
a
h
T
nThis lesson provides the background to the Java language. It discusses the role of Java in the
aya
Oracle10g platform.

Java is the programming language of choice for Internet applications. It has gained this status
because of its robustness, its object-oriented nature, the depth of its predefined classes, and its
write once, run anywhere deployment model. In this lesson, you learn how Java supports
object-oriented programming and architecture-neutral deployment.

Oracle Java Programming - IBM Graduate Program 1 - 2

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Using Java with Oracle 10g

Client

Web
server

Application
server

Presentation

Business
logic

Data

Oracle ns
a
Database
n-tr

bl
a
r
fe

no
a
s
a
h
)

m
e
o
d
i
ilc t Gu
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
Copyright
Oracle and/or its affiliates. All rights reserved.
y t2013,
o
a
s
( nse
a
t
r
u 10g
ice
k
l
Java and
Oracle
a
h
T
nOracle 10g is a complete and integrated platform that supports all the server-side requirements
aya
Oracle
Application Server

for Java applications. The Oracle 10g platform comprises the following:
Oracle Database 10g

In addition to its database management features, Oracle Database (currently version 10g)
provides support for a variety of Java-based structures, including Java components and Java
stored procedures. These Java structures are executed in the database by its built-in Java
Virtual Machine, called the Enterprise Java Engine (EJE).
Oracle Application Server 10g
Oracle Application Server 10g maintains and executes all your application logic, including
Enterprise JavaBeans, through its own built-in JVM. Oracle Application Server 10g uses the
OC4J Java EE server to execute servlets and JSPs. Oracle Application Server 10g Enterprise
Manager is the tool that is used to manage and distribute applications for ease of use.

Oracle Java Programming - IBM Graduate Program 1 - 3

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Java Software Development Kit


Sun Java SE (known as JDK and Java SDK) provides:
Compiler (javac)

Core class library


rt.jar

Debugger (jdb)
Bytecode interpreter: JVM (java)
Documentation generator (javadoc)
Java Archive utility (jar)

ns
a
r
t
n-

bl
a
r
fe

no
a
Others
s
a
h
)

m
e
o
d
i
ilc t Gu
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
Copyright
Oracle and/or its affiliates. All rights reserved.
y t2013,
o
a
s
( nse
a
t
r
u Development
ice
k
l
Java Software
Kit
a
h
T
nSun provides Java 2, Standard Edition (Java SE), which is also known as the Java Software
aya

Development Kit (Java SDK) or the Java Development Kit (JDK). The components that are
provided by Java SE include the following:
The Java compiler (javac) compiles Java source code into Java bytecodes.
The Java bytecode interpreter (java) is the engine that runs Java applications.

The program that generates documentation in HTML from Java source code
comments is javadoc.
Core Class Library
Java SE provides core Java classes in the following class library files:
rt.jar located in the jdk_home\jre\lib for Java SDK 1.2.x or later

Oracle Java Programming - IBM Graduate Program 1 - 4

Java Software Development Kit (continued)


Other Java SE Tools
jdb is the Java class debugger. It is similar to the dbx and gdb debuggers in UNIX.
jar is used to create Java Archive (JAR) files, which are zipped Java programs.

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

javah is used to generate C files for native methods.


javakey supports the generation of certification keys for trusted Java code.
javap is used to disassemble Java bytecodes into human-readable format.
native2ascii converts Java source code to Latin 1 characters.
serialver is used to generate version numbers for classes.

ns
a
r
t
n-

an
s
ha
)
m ide
o
c

il t Gu
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
ay e to
s
(
ta cens
r
u
li
ak

h
T
n

ya

Sa

Oracle Java Programming - IBM Graduate Program 1 - 5

bl
a
r
fe

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Using the Appropriate Development Kit


Java comes in three sizes:
Java ME (Micro Edition): Version specifically targeted to
the consumer space
Java SE (Standard Edition): Complete ground-up
development environment for the Internet
Java EE (Enterprise Edition): Everything in Java SE plus
le
b
a
an application server and prototyping tools
er
f
s
an
Previous releases of Java used the following naming
r
t
convention: J2ME, J2SE, and J2EE.
non

Sa

a
s
a
) h e
m
o
ilc t Guid
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
Copyright
Oracle and/or its affiliates. All rights reserved.
y t2013,
o
a
s
( nse
a
t
r
u Need
kEvery
lice
A Sizehfor
a
T
n
Java, Micro Edition
a
y

The technology that Java Micro Edition (Java ME) uses covers a range from extremely tiny
commodities (such as smart cards and pagers) all the way up to the set-top television box,
which is an appliance that is almost as powerful as a computer. Like the other editions, the
Java ME platform maintains the qualities for which Java technology has become famous.

Java Platform, Standard Edition


Java SE technology has revolutionized computing with the introduction of a stable, secure,
and feature-complete development and deployment environment that is designed from the
ground up for the Web. It provides cross-platform compatibility, safe network delivery, and
smart cardtosupercomputer scalability. It provides software developers with a platform for
rapid application development.
Java Platform, Enterprise Edition
The Java EE platform is a guide for implementations in the application-server marketplace.
The Java EE SDK includes a Java EE application server and various tools to help developers
prototype Java EE applications.

Oracle Java Programming - IBM Graduate Program 1 - 6

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Integrated Development Environment

Development

Debug

UML
Exchange

ADF

JSF
EJB

Database ns

Synchronized changes

-tr
n
o
n

bl
a
r
fe

a
s
HTML
a
XML
) h e
m
o uid
ilc Deployment
Source control
a
m ent G
g
@ tud
a
t
r
u his S
k
a
th se t

n
uOracle and/or its affiliates. All rights reserved.
Copyright
ya t2013,
o
a
s
( nse
a
t
r
uDevelopment
ice Environment
k
l
Integrated
a
h
T
nThe add-in API architecture of the Oracle JDeveloper integrated development environment
aya

(IDE) means that all the tool components (for example, navigator, editor, and modeler) share
memory models and event systems. In this way, an update in one tool is communicated to
another tool so that the latter can refresh its image or take other appropriate actions.
In Oracle 10g, the JDeveloper IDE is developed in pure Java. Synchronization between model
and code can be set so that you can decide to work using one or the other user interface.
Customizable Environment
You can customize the JDeveloper IDE and arrange its look to better suit your project needs
and programming style. To suit the JDeveloper IDE to your individual taste, you can:
Change its look and feel
Create and manipulate custom navigators
Customize the Component Palette, IDE environment
Select JDevelopers embedded Java EE server
Arrange the windows in the IDE

Oracle Java Programming - IBM Graduate Program 1 - 7

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Exploring the JDeveloper Environment

Component
Palette

ns
a
r
t
n-

bl
a
r
fe

no
a
s
a
h
)

m
e
o
d
i
ilc t Gu
a
Applications Navigator
Property
m en
Code g
Editor
d
and Structure window
@
Inspector
ta s Stu
r
u
k thi
a
h
t
use
n
a
Copyright
Oracle and/or its affiliates. All rights reserved.
y t2013,
o
a
s
( nse
a
t
r
ce
ku
li(10.1.3.2.0)
OraclehJDeveloper
Environment
a
T
nOracle JDeveloper (10.1.3.2.0) contains four major user interface components. These
aya

components are what you use to edit code, design and manage the user interface, and navigate
your program.
Component Palette
The Component Palette displays the components available to build user interfaces, models,
navigation diagrams, and so on. The Component Palette in the slide displays Swing
components that you use later in the course to build the user interface to a Java application.
Applications Navigator and Structure window
The Applications Navigator displays a list of files or classes in a project. The files may be
Java source files, .class files, graphics files, HTML, XML documents, and so on. The
associated Structure window shows the detailed structure of the object selected in the
Navigator.

Oracle Java Programming - IBM Graduate Program 1 - 8

Oracle JDeveloper (10.1.3.2.0) Environment (continued)


Code Editor and Design Editor

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Editors are where most of the work takes place; this is where you write code and
design user interfaces. Open an editor by double-clicking the name of the file in the
Navigator that you want to edit or view.
Property Inspector
The Property Inspector shows the properties and events associated with a selected
component in the Design Editor.

ns
a
r
t
n-

an
s
ha
)
m ide
o
c

il t Gu
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
ay e to
s
(
ta cens
r
u
li
ak

h
T
n

ya

Sa

Oracle Java Programming - IBM Graduate Program 1 - 9

bl
a
r
fe

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Oracle10g Products

an
s
ha
)
m ide
o
c

il t Gu
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
Copyright
Oracle and/or its affiliates. All rights reserved.
y t2013,
o
a
s
( nse
a
t
r
kuProducts
lice
Oracleh10g
a
T
n
Oracle Database 10g
a
ay

ns
a
r
t
n-

bl
a
r
fe

Oracle Database manages all your information: Word documents, Excel spreadsheets, XML,
images, and so on. Oracle Development Suite 10g tools can automatically reuse the database
structure and its integrity constraints, which reduces the amount of manual coding.

Oracle Application Server 10g


Oracle Application Server 10g runs all your applications: Java EE applications, forms,
wireless, portals, and business intelligence. Using Oracle Application Server 10g, all
applications that are developed with Oracle Development Suite 10g can be deployed and
managed in a single application server.
Oracle Developer Suite 10g
Oracle Developer Suite 10g leverages the infrastructure that is offered by Oracle Application
Server 10g and Oracle Database 10g, enabling developers to build scalable, secure, and
reliable e-business applications quickly and easily. The suite provides a complete and highly
productive development environment for building applications. Oracle JDeveloper is now
available as a separate product rather than only as part of the Oracle Developer Suite product.

Oracle Java Programming - IBM Graduate Program 1 - 10

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Summary
In this lesson, you should have learned the following:
Java code is compiled into platform-independent
bytecodes.
Bytecodes are interpreted by the JVM.
Java applications can be stand-alone or implemented
across an Internet-computing model.

ns
a
r
t
n-

an
s
ha
)
m ide
o
c

il t Gu
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
Copyright
Oracle and/or its affiliates. All rights reserved.
y t2013,
o
a
s
( nse
a
t
r
lice
aku

h
T
n

ya

Sa

Oracle Java Programming - IBM Graduate Program 1 - 11

bl
a
r
fe

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

Practice 1 Overview:
Controlling Program Flow
This practice covers the following topics:
Performing tests by using ifelse statements

Using loops to perform iterative operations


Using the break statement to exit a loop
Using the &&, ||, and ! operators in Boolean expressions

ns
a
r
t
n-

bl
a
r
fe

no
a
s
a
h
)

m
e
o
d
i
ilc t Gu
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
Copyright
Oracle and/or its affiliates. All rights reserved.
y t2013,
o
a
s
( nse
a
t
r
u
iceControlling Program Flow
k
l
Practice
1
Overview:
a
h
T
nThe goal of this practice is to make use of flow-control constructs that provide methods to
aya
determine the number of days in a month and to handle leap years.

Note: If you have successfully completed the previous practice, continue using the same
directory and files. If the compilation from the previous practice was unsuccessful and you
want to move on to this practice, change to the les04 directory and continue with this practice.
Remember that if you close a DOS window or change the location of the .class files,
you must set the CLASSPATH variable again.

Oracle Java Programming - IBM Graduate Program 1 - 12

Practice 1: Controlling Program Flow


Your Assignment

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

In this practice, you create a simple program to get the user input values for date (dd), month
(mm) and year (yyyy) and perform the following. Create a new java file and save it as
Util.java.
1. Determine the number of days in a month. You use a switch statement to set an integer
value to the number of days in the month you specify. For now, add all the code in the
main() method of the Util.java application.
a. Declare three integers to hold the day, month, and year. Initialize these variables with a
date of your choice.
b. Add a simple statement to display the date. Choose a format that you prefer, such as
day/month/year or month/day/year.

ns
a
r
t
n-

no
a
s
a
h
)

m
e
o
d
i
ilc t Gu
a
n for the current month:
d. Add a simple statement to display the number
gm ofdedays
@
ta s Stu + " days in month");
System.out.println(daysInMonth
r
u
k thi
a
h
2. Ensure that your CLASSPATH
t
ecorrectly:
isuset
s
n
a
(E:\labs\EmpEntry\classes)
ay e to
s
(
s
ta test ctheenprogram.
Compile
and
Experiment with different values for the month. What
r
u
i
k
l
a
happens
if
you
initialize
the
month
with an invalid value, such as 13?
h
T
yan For January 27, 2000, the output should look something like the following:

Sa

Note: The hardest part of this exercise is remembering how many days there really are in
each month. Here is a reminder if you need it: There are 30 days in September, April,
June, and November. All other months have 31 days, except for February, which has 28
days (ignore leap years for now).

27/1/2000

31 days in the month

Oracle Java Programming - IBM Graduate Program 1 - 13

bl
a
r
fe

c. Declare a variable to hold the number of days in the current month. Then, using a
switch statement, determine the value to store in this variable. Use daysInMonth as
the name of the variable.

3. Use a for loop to display dates.

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

a. Using a for loop, extend your program so that it prints out all the dates between your
specified day/month/year and the end of the month. Here is an example:
If your day variable is 27, your month variable is 1 (January), and your year
variable is 2000, then your program must display all the dates between January
27 and January 31 (inclusive) as follows:
27/1/2000
28/1/2000
29/1/2000
30/1/2000
31/1/2000

ns
a
r
t
- dates.
Compile and test your program, making sure that it works with a varietynof
o
n
Modify your program so that it outputs a maximum of 10 dates. a
For example, if your
s
day/month/year variables are 19/1/2000, the output must
now
ha beas follows:
)
m ide
o
19/1/2000
c

il t Gu
a
20/1/2000
gm den
@
tu
21/1/2000 rta
S
u
s
k thi
a
22/1/2000
h
t
use
n
a
to
ay 23/1/2000
s
e
(
ta cens24/1/2000
r
u
li
ak
25/1/2000

b.
c.

ya
Sa

h
T
n

26/1/2000
27/1/2000
28/1/2000

Make sure your program works for dates near the end of the month, such as 30/1/2000.
In this situation, it must output only the following:
30/1/2000
31/1/2000
d. Compile your program. Then, test it with a variety of dates to make sure it still
works.

Oracle Java Programming - IBM Graduate Program 1 - 14

bl
a
r
fe

Hint: You must use the result of the switch statement in step 2 to determine the last day
in the month.

4. Determine whether the year you specify is a leap year. You use the boolean operators &&
and ||.

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

a. Build a boolean statement that tests year to see whether it is a leap year. A year is
a leap year if it is divisible by 4, and if it is either not divisible by 100 or it is
divisible by 400.
b. Modify your switch statement from step 2 to apply to leap years. Remember that
February has 29 days in leap years and 28 days in nonleap years.
c. Build and test your program with a variety of dates. The following table includes
some sample leap years and nonleap years that you may want to use as test data:
Leap years

Nonleap years

1996

1997

1984

2001

2000

1900

1964

1967

ns
a
r
t
n-

no
a
s
a
age of the employee is less than 58
h
)

m
e
o
d
salary of the employee should be greater than 5000
i
ilc t Gu
a
rating of the employee != 0
gm den
@
tu these validations in the Employee
You can create new member functions
ta forsperforming
r
S
u
i main class while creating new instances of
k EmpEntry
class and invoke them fromathe
h
t
h
t
e
Employee.
n us
a
y
to to your Department class also.
aadd validations
s
6. Similarly you (can
e
ta cens
r
u
k
li
a
h
nT
5. Modify the EmpEntry.java to validate the user inputs.

ya

Sa

bl
a
r
fe

Oracle Java Programming - IBM Graduate Program 1 - 15

Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates

ns
a
r
t
n-

an
s
ha
)
m ide
o
c

il t Gu
a
gm den
@
ta s Stu
r
u
k thi
a
h
t
use
n
a
ay e to
s
(
ta cens
r
u
li
ak

Sa

ya

h
T
n

bl
a
r
fe

Das könnte Ihnen auch gefallen