Professional Documents
Culture Documents
• Hello World!
• Running Java on the JVM
• Language basics: Methods, Variables & simple Types
• Debugging
• Quiz
• Dinner
• Introduction to Java Objects
• A little inheritance
• Scratching the surface of
– Java to Database communication (JDBC)
– Http to Java communication (Servlet)
HELLO WORLD
begin
welcome.hello_world;
end;
PL/SQL VM
(Oracle7, 1993)
PL/SQL VM
PL/SQL VIRTUAL MACHINE
}
VARIABLES
Java
java.exe public class Factorials {
-classpath
C:\JavaAintScary\classes private static int factorial(int i) {
nl.amis.Factorials if (i<2)
return 1;
else
return i * factorial(i-1);
}
}
PRINT THE FACTORIALS FOR 1..10
PL/SQL Java
create package body factorials as public class Factorials {
• PL/SQL • Java
declare
l_gender varchar2(1):= 'F';
begin
dbms_output.put_line
( decode( l_gender
, 'F','FEMALE'
,'MALE'
// using a ternary expression
)
...
);
{
end;
String gender ="F";
System.out.println
( gender=="F" ? "FEMALE" : "MALE"
declare );
l_gender varchar2(1):= 'F'; }
begin ...
dbms_output.put_line
( case l_gender
when 'F' then 'FEMALE'
else 'MALE'
end
);
end;
THAT BIG THING ABOUT JAVA…
Objects….
THE PERSON CLASS:
“MOTHER OF MANY OBJECTS”
}
QUIZ TIME
}
java.exe
-classpath
C:\JavaAintScary\classes
nl.amis.DoIt
DINNER
JAVA OBJECTS
create or replace package thing as begin
procedure set_value dbms_output.put_line
(p_value in varchar2); ('value = '||thing.get_value);
end;
function get_value
return varchar2;
procedure set_value
(p_value in varchar2) is
begin
g_value := p_value;
end set_value; begin
dbms_output.put_line
function get_value return varchar2 is ('value = '||thing.get_value);
begin end;
return g_value;
end get_value;
begin
g_value:= 'initialized value';
end thing;
Package THING
get_value
set_value
procedure set_value
(p_value in varchar2) is
begin
g_value := p_value;
end set_value;
public Thing() {
value = "initialized value";
}
}
MULTIPLE THING INSTANCES WITH
EACH ITS INSTANCE DATA
public class Thing { public class ThingRunner {
}
SEPARATION OF (SHARED) CODE AND
INSTANCE DATA
SHARED
Class THING
getValue
setValue
INSTANCES
thing thing 2
value value
[Hello World] [Goodbye World]
CLASS AND OBJECTS
SHARED
Class THING
static value
INSTANCES
thing thing 2
value value
TRUE GLOBAL IN JAVA
public class Thing {
public Thing() {
value = "initialized value";
}
}
Object thing
Class THING value
Object thing2
static value
value
INSTANTIATING A PERSON (OBJECT)
public class Person {
...
PersonalAssistant.printPersonalLabel(p);
}
vs.
public static void main(String[] args) {
...
PersonalAssistant pa = new PersonalAssistant();
pa.printPersonalLabel(p);
}
MULTIPLE PEOPLE Class Person
…
displayLabel
• Methods on a String
METHOD CHAINING
59182 255
<pointer> Person
<pointer> Person
Social Profile
Social Profile
Social Profile
Social Profile
Social Profile
Social Profile
Employee Customer
ENTITY RELATIONSHIP MODELING
PERSON SOCIAL_PROFILE
EMPLOYEE EMAIL_ADDRESS
CUSTOMER
OBJECT ORIENTED DESIGN
1 0..1
PERSON SOCIAL_PROFILE
1 0..*
EMAIL_ADDRESS
EMPLOYEE CUSTOMER
CODE FOR SUB CLASSES
}
PERSONAL ASSISTANT: CAN IT DEAL
WITH EMPLOYEES AND CUSTOMERS?
package nl.amis;
begin
dbms_output.put_line(add(i,21));
end;
create or replace
package calculator
as
end calculator;
DESIGN BY CONTRACT IN JAVA
INTRODUCING THE JAVA INTERFACE
• The contract dictating functionality in Java is called an
Interface
– It defines methods – without providing implementations
for those methods
package nl.amis
• Hello World!
• Running Java on the JVM
• Language basics: Methods, Variables & simple Types
• Debugging
• Quiz
• Dinner
• Introduction to Java Objects
• A little inheritance
• Scratching the surface of
– Java to Database communication (JDBC)
– Http to Java communication (Servlet)
JAVA APPLICATIONS & DATABASE
Cache
“NO SQL”
JPA
Plain JDBC Ibatis, Spring EJB (CMP) WS* Data Grid
(Hibernate)
JDBC
RDBMS
JDBC – JAVA DATABASE CONNECTIVITY
E htp
P
G Custom
PL/SQL
package
JAVA CLASS PROCESSING AN HTTP
REQUEST: THE SERVLET
• The JVM can handle HTTP requests via the Servlet
Container
• HTTP requests are routed to a custom Java Class that
writes the (usually HTML response)
• The Servlet infrastructure handles the actual HTTP
response to the invoker
JVM
Greeter
WebLogic Server
HELLO WORLD SERVLET
public class HelloWorldServlet extends HttpServlet {
• Internet
• AMIS Training
“Java for PL/SQL Developers”
(5 day)
BUT FIRST…