Beruflich Dokumente
Kultur Dokumente
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.
Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates
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.
Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates
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
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
h
T
n
ya
Sa
bl
a
r
fe
Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates
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.
Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates
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
Unauthorized reproduction or distribution prohibited Copyright 2013, Oracle and/or its affiliates
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.
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
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.
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
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
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.
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
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.
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.
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
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