introduction to java for lotus script programmers
TRANSCRIPT
![Page 1: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/1.jpg)
JMP106: Introduction to Java for LotusScript Programmers
Steve Brown, Iris AssociatesGary Devendorf, Lotus Development
![Page 2: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/2.jpg)
PrerequisiteLotusScript
After this PresentationJava basicsDomino Java ClassesDomino Java agentDomino JSP
RecommendJava programming courseOO design course
This Presentation
![Page 3: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/3.jpg)
Why Java ?Basic Java concepts
Syntax / semanticsClass methodsClass packages, jar files
Accessing Domino via JavaDomino Objects
Agents, Applications, Applets, Servlets, JSPs
Demos throughout
Agenda
![Page 4: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/4.jpg)
JavaThe Java programming language is a modern,evolutionary computing language that combines an elegant language design with powerful features that were previously available primarilyin specialty languages. In addition to the corelanguage components, Java platform softwaredistributions include many powerful, supportingsoftware libraries for tasks such as database, network, and graphical user interface programming.
![Page 5: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/5.jpg)
LotusScriptLotusScript is an embedded, BASIC scripting
language with a powerful set of language extensions that enable object-oriented application development within and across Lotus products.
![Page 6: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/6.jpg)
LotusScript's Future
LotusScript is going nowhere! Gary Devendorf - 1998
![Page 7: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/7.jpg)
AdvantagesCross PlatformNonproprietaryRicher class libraryMultithreadingCode reuse
across Agents, Applications, Applets, ServletsIntegrates with 3rd party Java applicationsObject Oriented Language Features
advanced architectureinheritancedesign patterns
Why Java?Why Java ?
![Page 8: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/8.jpg)
Some Backend Classes are only JavaString Handling abilities are superior to LSUtility Classes for Web, Networking and XMLJDBC to integrate with SQL dataEveryone today has a Java APIHelp is everywhere : Books, usergroups, ListServers, etc.Scalable Data Structures no arbitrary limitsCollection Classes - Vector, Hashtable, etc.Lots of IDEs to choose from
Why Java ?
![Page 9: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/9.jpg)
How about URL encoding and unencoding ?
Ok, Give me one good example of why I would
choose Java.
![Page 10: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/10.jpg)
Call an @function cmd = {@URLEncode("Platform"; "} + doc.myLink(0) + {")} encURL = Evaluate( cmd ) *************************************************************Encode a Link in LotusScript using a reentrant functionfunction URLEncode(query As String) As String Dim c As Integer Dim x As Integer For x = 1 To Len(query) c = Asc(Right(Left(query,x),1)) If (c < 48) Or (c > 57 And c < 65) Or (c > 90 And c < 97) Or (c > 122) Then URLEncode = URLEncode & "%" & Hex(c) Else URLEncode = URLEncode & Chr(c) End If NextEnd Function
URL Encoding LS
![Page 11: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/11.jpg)
String encURL = URLEncoder.encode(doc.getItemValueString(myLink);
Encode a URL in Java
![Page 12: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/12.jpg)
Source Filese.g. *.C++
Objects e.g. *.obj
Executablee.g. myprog.exe
Compiler Linker
Class Libraries (e.g. *.lib)
Your Machine at Runtime
Executablee.g. myprog.exe
Operating System
O/S Specific Machine Code
Traditional Programming Environment
![Page 13: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/13.jpg)
*.java *.class
Compiler
Win32 JavaOs OthersMacSolaris
Runtime
Source Files
Java ByteCode Files
Java Virtual Machine (JVM)
"Write Once "Write Once Run Anywhere"Run Anywhere"
Class Packages(analogy - script libraries)
Java Environment
![Page 14: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/14.jpg)
Your Machine
Forms execute Applets Agents
imported Java Classescode Java directly
compiled in Designer
DominoServer
RPC .NSF.NSF
OS
JVM 1.1.x & Core Classes
Notes 4.6 / 5.0
Notes Form1
12
2
3
4
56
7
8
9
10
11
Notes Agent
Applet *.class
Notes Java Classes
(Notes.jar)
Notes Client API
4.6.5 / 5.0
Notes Client
![Page 15: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/15.jpg)
Server
JVM 1.1.x & Core Classes
Domino 4.6/5.0
Notes Agent
*.class
Agents execute HTTP, Agent ManagerImported Java ClassesWritten Java in Agent
compiled in DesignerServlets
Domino Servlet EngineUse Domino Classes **
Notes Client API RPCRPC .NSF.NSF
Domino Server
Servlets
*.class
Notes Java Classes
(Notes.jar)
OS
Servlets
![Page 16: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/16.jpg)
Introduced in 4.6Java language binding to backend CAPIAgents, stand-alone apps, Servlets, AppletsJVM 1.1.1
Enhanced in 5.0JVM 1.1.8 (5.06)New and enhanced classes Agents, stand-alone apps*, Servlets*, Applets*
retrieval of Session object different
Domino Java Classes
![Page 17: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/17.jpg)
Agent: AgentBase.getSession()Applet: AppletBase.openSession()Application, Servlet, JSP: NotesFactory.createSession()
Session please!
![Page 18: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/18.jpg)
Brief Description:* Java agent crashes when creating a large number of documents-------------------------------------------------------------------------------------------------------------------Steps to Reproduce:If you create a Java agent to create large number of documents in a database,the agent will fail with error message: MemAlloc: OUT OF PRIVATE HANDLES! -- pid 0000035C Handles used so far 16415,In my environment the problem occurs consistently after 10331 documents.
I include the agent to reproduce the problem here since it is so short.It runs in an endless loop creating documents.It prints Ping! to the console every 1000 documents, and Poing! every 10 000 documents.
Work Around:None, apart from writing the script in LotusScriptImpact:Potentially large. Currently none.
Bug Report
![Page 19: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/19.jpg)
Database db = agentContext.getCurrentDatabase(); while (true)
{ doc = db.createDocument();
doc.appendItemValue("Address", "1.2.3.4"); doc.appendItemValue("Form","Entry");
a++; if (a % 1000 == 0 )
System.out.println("Ping!"); if (a % 10000 == 0 ) System.out.println("Poing!");
if (!doc.save()) System.out.println("Unable to save document");
}
Bug Report Code
![Page 20: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/20.jpg)
In LotusScript you don't worry about it, in C you do.In Java you don't get Memory leaks but you can get yourself in to trouble with "unCollected" memory.
Java has a Garbage Collector that runs when Java thinks it should. But Java can only see the wrappersnot the code under them.
Memory Management
![Page 21: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/21.jpg)
AgentsEvents
Agents*Applications
ServletsApplets
Notes Backend "C" API
( nlsxbe.dll )
LotusScriptBinding
Java Binding
LotusScript
Java
OLE
COM
Notes 4.6/5.0 Java Notes Classes
![Page 22: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/22.jpg)
Actual memory usage is like an iceberg.The part that Java can see is the visible partof the iceberg. The 7/8 under the water part is theback end classes.Your application is the Titanic if you are not careful
Like an Iceberg
![Page 23: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/23.jpg)
use doc.recycle() after .doc.save(). stopped your script after 120K docs.
The answer is : Recycle()
![Page 24: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/24.jpg)
Garbage collection has no effect on Domino objects unless you first explicitly recycle them.If you appear to have memory problems, try recycle but adhere to the following guidelines:
Recycle an object only if it is no longer needed.Recycle an object in the same thread in which it is created.Recycling a parent recycles all the children.In Session, call recycle only after all threads exit.Loops enumerating documents or items are good candidates for recycling
Recycle()
![Page 25: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/25.jpg)
Recycle().Suggestion
Go to :www.notes.net www.looseleaf.netand do a search on recycle.
![Page 26: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/26.jpg)
NotesViewNotesACL
NotesDocument
NotesAgent
NotesACLEntry
NotesItem NotesRichTextItem NotesEmbeddedObject
NotesDocumentCollection
inherits
Database
NotesViewColumn
NotesInternational
NotesForm
NotesSessionNotesLogNotesDateTime
NotesNewsletter
NotesDbDirectory
NotesName
NotesDateRange
NotesRegistration
NotesRichTextStyle
Forms ACL Agents
create ...
get ...
NotesRichTextTab
NotesRichTextParagraphStyle
NotesViewEntry
NotesViewEntryCollection
NotesViewNavigator
NotesReplication
getViewViews
NotesOutline
NotesOutlineEntry
Outline
NotesTimerNotesUIWorkspace
NotesUIDocument
NotesUIView
NotesUIDatabase
FRONT END CLASSESBACK END CLASSES
ContainsNew Method
R5 LotusScript
AllDocumentsFTSearch
SearchReplication
![Page 27: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/27.jpg)
ViewACL
Document
Agent
NotesACLEntry
Item RichTextItem EmbeddedObject
NotesDocumentCollection
inherits
Database
ViewColumn
International
Form
SessionLogDateTime
Newsletter
DbDirectory
Name
DateRange Registration
RichTextStyle
getForms getACL getAgents
create ...
get ...
RichTextTab
RichTextParagraphStyle
ViewEntry
ViewEntryCollection
ViewNavigator
Replication
getViewgetViews
Outline
OutlineEntry
getOutline
BACK END CLASSES
getAllDocumentsFTSearch
Search
getReplication
createDocument
NO FRONT END CLASSESNO NEW CLASS METHODNO DIRECT PROPERTY ACCESSNO NOTESTIMER CLASS
R5 Java
AgentContextgetDocumentContext
getAgentContext
![Page 28: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/28.jpg)
Property accessing methodsisOnServergetNotesVersiongetPlatformgetUserNamegetUserNameObject
MethodscreateDateRangecreateDateTimecreateLogcreateNamecreateNewslettercreateRegistrationcreateRichTextStyle
*** evaluatefreeTimeSearchgetDatabasegetDbDirectorygetEnvironmentStringgetEnvironmentValuesetEnvironmentVaropenURLDatabase
getAddressBooks
getAgentContext
getCommonUserNamegetInternational
Property accessing MethodsgetCurrentAgent** getCurrentDatabase** getDocumentContextgetEffectiveUserNamegetLastExitStatusgetLastRungetSavedData** getUnprocessedDocuments
MethodsunprocessedFTSearchunprocessedSearchupdateProcessedDoc
Session Class AgentContext Class
AgentContext() Class
![Page 29: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/29.jpg)
All properties are accessed via methodsis or has properties are accessed via the same method namedoc.isNewNote is accessed via doc.isNewNote( )
remaining properties are accessed via get or set prefixed to the property name as a methoddb.title is accessed via db.getTitle( )db.title is modified via db.setTitle( )
Domino Java Classes
![Page 30: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/30.jpg)
NO extended notation methodi.e. doc.subject or doc.subject(0)
Single value methods per datatypedoc.getItemValueString( "fname" )doc.getItemValueInteger( "fname" )doc.getItemValueDouble( "fname" )
Multi value methodsdoc.getItemValue( "fname" )
returns a vector ( ~ dynamic array )
Accessing Domino Data
![Page 31: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/31.jpg)
ClassThe class construct supports the creation of user-defined data types, that represent both data and the methods used to manipulate thedata.
You can represent real world objects with theseuser-defined classes.
![Page 32: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/32.jpg)
Dogclass Dog { void bark() { System.out.println("Woof"); } }
MyAgent code: Dog Lassie = new Dog(); Lassie.bark();
![Page 33: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/33.jpg)
public class Demo { private int v1, v2 ; public Demo( int v1, int v2 ) {
v1 = v1; v2 = v2;
} public int getMax( ) { return getMaximum( ); } private int getMaximum( ) {
if ( v1>v2) return v1;
else return v2;
}}
Demo d = new Demo( 20, 10 ); System.out.println ( d.getMax( ) );
Sample Code
private instance propertiesconstructorpublic instance methodprivate instance method
Basic Java Class
![Page 34: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/34.jpg)
LotusScriptDim doc as NotesDocumentset doc = view.getfirstdocument
while Not( doc Is Nothing ) ' code set doc = thisview.getNextDocument(doc)wend
Java Document doc = thisview.getFirstDocument( );
while ( doc != null ){ // code doc = thisview.getNextDocument(doc);}
Object Reference Variables
![Page 35: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/35.jpg)
In LotusScript the NotesRichTextItem class inherits properties and methods of the NotesItem Class
This is called Inheritance or subclassingIn Java inheritance is represented by the extends keyword
class myapplet extends Applet mandatory for Applet classes
class myagent extends AgentBasemandatory for Domino Java Agent classes
Inheritance
![Page 36: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/36.jpg)
AgentContext
Database
BACK END CLASSES
Session
getAgentContext
getDatabase
getCurrentDatabase
import lotus.domino.* public class Demo1 extends AgentBase {
public void NotesMain( ) { try {
Session s = getSession( );AgentContext ac = s.getAgentContext( );Database db = ac.getCurrentDatabase( )System.out.println(db.getTitle());
} catch( NotesException e ) { e.printStackTrace(); } } }
Instance method of AgentBase Class
Dim s as new NotesSession Dim db as NotesDatabase Set db = s.CurrentDatabase print( db.Title )
LotusScript
Simple Java Agent
![Page 37: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/37.jpg)
Create instance of Java classCreate and initialize AgentBase classCall the NotesMain() method
Loading a Java Agent
![Page 38: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/38.jpg)
Output to console or Notes Log:setDebug (boolean debug);dbgMsg ("Some helpful text");
Output to Web Browser:import java.io.PrintWriter;PrintWriter pw = getAgentOutput();pw.print("Output Text to Browser");
AgentBase Debugging Methods
![Page 39: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/39.jpg)
Domino methods throw exceptions( NotesException Object)
import lotus.domino.*public class Demo1 extends AgentBase {
public void NotesMain( ) { try {
Session s = getSession( ); AgentContext ac = s.getAgentContext( ); Database db = ac.getCurrentDatabase( ); } catch( NotesException e ) { System.out.println(e.id + " " + e.text); e.printStackTrace(); } } }
Demo1.java
Exception Handling
![Page 40: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/40.jpg)
Exception throwing methods contained in a try block
All Domino methods throw exceptionssend exception object to runtime system
Catching an ExceptionRuntime finds a routine to handle exception
defined by catch blocklooks in current and calling methods
program terminates if unsuccessful
Java insists that you do it right !
Exception Handling
![Page 41: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/41.jpg)
LotusScript Java Bytes
byte 1integer short 2long int 4single float 4double double 8currency N/A 8string N/Avariant N/A
char 2 (unicode)
boolean true or false
Java Primitive Datatypes
![Page 42: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/42.jpg)
LotusScript
- explicit declarations- implicit declarations- default values
Dim value1 as integer, value 2 as integer
value2 = 100value3 = 100
Java
- explicit declarations - NO implicit- NO default values- CASE SENSITIVE
int value1 = 100, value2 ;
value2 = 100 ;
char initial ;initial = 'J' ; SEMI- COLONSSEMI- COLONS
Java Variables
![Page 43: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/43.jpg)
Another customer report for Gary.The Java compiler is complaining about the line highlighted in red on the next slide.
Initializing variables
![Page 44: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/44.jpg)
Session session = getSession();AgentContext ac = session.getAgentContext();Double cRate;String sRate;int x;x =1; if (x==1){
sRate = "345.983";cRate = Double.valueOf(sRate);
} Database db=ac.getCurrentDatabase();
Document doc = db.createDocument();doc.replaceItemValue("Form","Test");doc.replaceItemValue("Value",cRate);doc.save(true,true);
Variable cRate may not have been initialized.
![Page 45: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/45.jpg)
Session session = getSession();AgentContext ac = session.getAgentContext();Double cRate = 0;String sRate = "0";int x;x =1; if (x==1){
sRate = "345.983";cRate = Double.valueOf(sRate);
} Database db=ac.getCurrentDatabase();
Document doc = db.createDocument();doc.replaceItemValue("Form","Test");doc.replaceItemValue("Value",cRate);doc.save(true,true);
This will compile
![Page 46: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/46.jpg)
IF StatementLotusScript Java
Dim i, j, found as Integer
if i=10 or j=30 then age = "Young" found = Trueelseif i=20 then found = Trueelse found = Falseend if
short i , j;boolean found;String age;
i=0;j=0;if (i ==10 || j == 30) { age = "Young"; found = true;}else if (i == 20) found = true;else found = false;
Comparison / Logical OperatorsLotusScript = or and != , <, <=, >, >=Java == || && same
![Page 47: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/47.jpg)
LotusScript Java
for ( i = 1 to 10 ) ' statementsNext i
for ( i = 1; i <= 10; i++ ){ // statements with ;}
while ( found = True ) ' statementswend
while ( found == true ) { // statements with ;}
do ' statementsLoop while (found = True )
do{ // statements} while (found == true )
Select Case age Case 20 : person = "young" Case 70 : person = "old" Case Else : person = "dead"end select
switch ( age ){ case 20 : person = "young"; break; case 70 : person = "Old"; break; default : person = "dead";}
Loops and Select
![Page 48: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/48.jpg)
Instantiating objectsGroup common Methods and Properties
never instantiatedreferenced via Class Nameclass methods and class properties
Math ClassMath.PI, Math.EMath.abs( 2.78 )Math.max ( 100, 90 )Math.min ( 44, 999 )Math.round ( 2.34 ) Class Methods
( static methods )
Class Properties
Class Uses
![Page 49: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/49.jpg)
int x = 100;int a = 0;int myValue = 50;if ( x == 100) { MyValue = x; b = a } System.out.println("The value of b is:" + b);
Semicolons, semicolons semicolons !Capitalization Matters !!!!
Stump Garyx = 100 , b = ?
![Page 50: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/50.jpg)
int a = 0;int b = 50;if ( x == 100) a = x; b = a;System.out.println("The value of b is:" + b);
int a = 0;int b = 50;if ( x == 100) { // Always use braces a = x; b = a; } System.out.println("The value of b is:" + b);
What is the value of "b" if x is 45
![Page 51: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/51.jpg)
int a = 0;If x = 100 { a = 300; }System.out.println("The value of a is" + a);
int a = 0;If 100 == x // "=" is not the same as "==" { a = 300; }System.out.println("The value of a is" + a);
What is the value of "a" if x is 100
![Page 52: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/52.jpg)
Standard I/O ClassCannot be instantiated.
System.out.println("Hello World");
The above java code prints to standard output Server Console, Notes Log - background agentsJava Debugger Console - foreground agents
SystemClass System Class Property
- PrintStream Class Object
PrintStream Instance Method
System Class
![Page 53: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/53.jpg)
Classes for primitive datatypes double, float, int, longmethods to manipulate primitives
creation via passing primitive in constructorInteger i = new Integer( 10 );Double i = new Double( "10" );Float i = new Float(12.89);
Double, Float, Integer, Long Class
![Page 54: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/54.jpg)
instance methods to manipulate native datai.toString(); // returns String representationi.intValue(); // returns int value
class methodsInteger.valueof( String s ) returns Integer objectInteger.toString( int d ) converts native data to String
Domino ObjectsSome methods require Objectsdocument.replaceItemValue ( "fieldname", object )
new Double( 12.3 )"Becky Gibson"
Double, Float, Integer, Long Class
![Page 55: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/55.jpg)
NO string datatype but a String classAssignment via "="
String s = "hello world";Comparison via instance methods
s.equals("HELLO WORLD") returns falses.equalsIgnoreCase("Hello World") returns true
Instance methodsreplace, toLowerCase, toUpperCase, trim, etc ..
CIass methodsString.valueOf ( primitives or objects )
Pay attention this is important !String Class
![Page 56: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/56.jpg)
The Java platform provides two classes, String and StringBuffer, that store and manipulate strings-character data consisting of more than one character.
The String class provides for strings whose value will not change. The StringBuffer class provides for strings that will be modified; you use string buffers when you know that the value of the character data will change. You typically use string buffers for constructing character data dynamically.
Why Two String Classes ?
![Page 57: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/57.jpg)
Strings DemoReverse the characters of a string. This program uses both a string and a string buffer.
public class StringsDemo { public static void main(String[] args) { String palindrome = "Dot saw I was Tod"; int len = palindrome.length(); StringBuffer dest = new StringBuffer(len); for (int i = (len - 1); i >= 0; i--) { dest.append(palindrome.charAt(i)); } System.out.println(dest.toString()); }}
![Page 58: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/58.jpg)
The output from this program is:
doT saw I was toD
Strings Demo Output
![Page 59: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/59.jpg)
Create a report document of Sales by the person running the agent (i.e. SalesPerson = UserName )
SalesPerson : SalesPerson
Sales Report 1
TotalSalesTotal Sales :
Demo : Report 1
![Page 60: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/60.jpg)
LotusScript Java
myArray( ) as IntegerREDIM myArray(2)
myArray(0) = 10myArray(1) = 20myArray(2) = 30
REDIM PRESERVE myArray(3)myArray(3) = 40
import java.util.Vector;Vector myVector = new Vector( );
myVector.addElement( new Integer(10) );myVector.addElement( new Integer(20) );myVector.addElement( new Integer(30) );myVector.addElement( new Integer(40) );
System.out.println( "elements : " + myVector.size() );
import java.util.Vector;Vector contains OBJECTS
automatically increase in size on add
Vectors ( dynamic arrays )
![Page 61: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/61.jpg)
Store customer values from all matching documents in Customers multivalue text field
item.appendToTextList( String s );Store each double sales amount value for customer
create a Vector of Double objects
SalesPerson : SalesPerson
Customer SalesSalesCustomers
Sales Report 2
TotalSalesTotal Sales :
SalesPerson : Doctor Notes
Customer Sales
1000.002000.003456.90
Mary SmithMary SmithGary Martin
Sales Report 2
6456.90Total Sales :
Demo : Report 2
![Page 62: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/62.jpg)
*.java *.class
Compiler
Source Files
Java ByteCode Files
Class Packages(analogy - script libraries)
Class PackagesClass Packages
![Page 63: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/63.jpg)
The Import statement is used to find class files at compile and runtime
.class extension not required
import Window1import Window2
MyApp.java
c:\work\ibm\input\Window1.classc:\work\ibm\input\Window2.class
CLASSPATH Environment variablesearched at COMPILE / RUNTIME for imported classesContains Imported Class filepaths CLASSPATH = c:\work\ibm\input
Classes and Classpath
![Page 64: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/64.jpg)
Classes of the same context can be grouped together Referenced easily as a wholeSimplifies CLASSPATH
This container is called a Package Relates to directory path of the class filedefined at the top of source file via Package name
package lotus.domino ;. . .
Database.java Database.class
c:\notes\lotus\domino\import lotus.domino.* ;. . . MyApp.java
CLASSPATH = C:\NOTES
COMPILING
Class Packages
COMPILE Database.class
Class Packages
![Page 65: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/65.jpg)
Not Applicable for Java Agents
Core Java Packagesjava.applet
applet classesjava.lang
Java language related classesdefault package automatically imported
java.utiluseful utility classes
java.iofile input and output classes
java.netnetwork related classes
java.awt **windowing and graphic classes
Core Java Packages
![Page 66: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/66.jpg)
Packages can be saved to zip or JAR fileJava ARchive File
Domino Java classes lotus.domino packageNotes.jar ( installed Notes directory )
SET CLASSPATH= .;C:\NOTES\NOTES.JAR
\lotus\domino\Session.class \lotus\domino\Database.class \lotus\domino\View.class \lotus\domino\Document.class
The path + jar filename is placed in the Classpathcompiling / executing outside Domino
NOTES.JARNOTES.JAR
Archive FilesArchive Files
![Page 67: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/67.jpg)
Domino has internal CLASSPATH Find Domino & JVM classes @ compile / runtime
notes.jari18n.jar, icsclass.jar, rt.jar
Notes.ini variable extends internal CLASSPATHAdd your own Classes and Jar filesJavaUserClasses= ... ;c:\jdk\work\toolkit.jarClasses that access 'C' must be on disk
Domino Internal Classpath
![Page 68: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/68.jpg)
JavaServer Pages (JSP) technology provides a simplified, fast way to create web pages that display dynamically-generated content. They are HTML documents that include special tags and Java. JSPs run on a server and work with requests and responses. The response is usually in the form of an HTML document but can also be XML. A JSP is compiled into a Servlet the first time it is accessed.
What is a JSP ?
![Page 69: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/69.jpg)
Web Server hands the request off to Web App Server The JSP source code turned into Servlet source codeThe Servlet source code is compiled and runHTML response is sent back to the Web Server and then to the browserThe compiled servlet remains in memory
What happens when my browser hits a URL with a .jsp
extension ?
![Page 70: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/70.jpg)
Domino does not currently provide integrated JSP supportUse a third party JSP container
Tomcat, WebSphereInstall JSP containerRun Domino & JSP containerFor JSP support access JSP container directly
http://bgibsontpad:8080/Hello.jsp?user Name=Becky
Using JSPs with Domino
![Page 71: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/71.jpg)
Code name for the new web programming model in the next release of Domino (Rnext)Garnet consists of:
A Standard Servlet/JSP containerA Custom tag library and Java classes over Domino Data"Template" applicationsThird Party Tool integration
"Garnet"
![Page 72: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/72.jpg)
JSP 1.1 - Custom TagsDomino Custom Tags
SessionDatabaseViewDocumentCollectionLoopMail Message
Custom Tag Libraries
![Page 73: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/73.jpg)
Simple.JSP
![Page 74: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/74.jpg)
Let's take those LotusScript/Java reportsand turn them into JSPs.
report1.jsp
![Page 75: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/75.jpg)
Ever want to build an application thatcould interact with SQL data ?
SQLdemo.jsp
![Page 76: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/76.jpg)
Java Applications 1Java Applications 1SetupSetup
Notes.jar in CLASSPATHNotes.jar in CLASSPATHJava ClassesJava Classes
Include Notes installed directory in pathInclude Notes installed directory in pathload DLLsload DLLs
SessionSessionNotesThread.sinitThread(); NotesThread.sinitThread(); Session s = NotesFactory.createSession([user, Session s = NotesFactory.createSession([user, password]); password]); NotesThread.stermThread();NotesThread.stermThread();
Demo 4
![Page 77: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/77.jpg)
Your MachineYour Machine
OS
JVM + Core Classes
BrowserHTML Page
112
2
3
4
56
7
8
9
10
11
Applets / BrowserDemo 6
IIOP
R5.0 CORBA Classes
HTTPHTTP
DIIOPDIIOP2
1
SetupSelect "Applet uses Notes CORBA Classes" property
SessionAppletBase.getSession( ) instance AppletBase.getSession( ) instance method
HTTP
DominoServer
![Page 78: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/78.jpg)
Your MachineYour Machine
OS
Executed by Java interpreter (e.g. java.exe) at OSAccess the Java Notes Classes Notes Client/Server Installed
access local API
Stand Alone Java
Application
JVM 1.1 & Core Classes
Notes 4.6/5.0 Java Classes
RPC
Java Applications 1
Notes Client API DominoServer
![Page 79: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/79.jpg)
Your MachineYour Machine
OS
NO Local Client/ServerExecuted by Java interpreter (e.g. java.exe) at OSSetup
NCSO.jar in CLASSPATHSession
NotesFactory.createSession( host )NotesFactory.createSession( host )
Stand Alone Java
Application
JVM Classes
Notes 5.0 CORBA Classes ( NCSO.JAR) IIOP
Java Applications 2
DominoServer
Demo 5
![Page 80: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/80.jpg)
OS
JVM Classes
Notes 5.0Notes Form
112
2
3
4
56
7
8
9
10
11
Applet
Notes Java Classes
(Notes.jar)
Notes Client API
Applets / Notes ClientDemo 7
SetupSetupJava Applet Security options in UserJava Applet Security options in UserPreferencesPreferencesSessionNotesThread.sinitThread(); NotesThread.sinitThread(); Session s = this.getSession();Session s = this.getSession();NotesThread.stermThread();NotesThread.stermThread();
![Page 81: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/81.jpg)
Graphical Java AgentsDemo 8
Build your agent with a GUI (or not)Use AWT or Swing
Swing.jar not included with Dominoimport into agent or reference in Notes.ini
Attach your agent to an eventUse Simple Action: Run AgentUse Formula @Command([ToolsRunMacro];"AgentName")
![Page 82: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/82.jpg)
Domino Java Objectsnew Package, new Classes, methods and propertiesCORBA implementation of Backend Classes
Remote access of DominoJava Agents
new programmers pane, Script LibraryDomino UI Applets
Outline, Editor, View, Action
Domino 5.x and Java
![Page 83: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/83.jpg)
Servlets4.6 & enhanced for 5.0
Attend AD109 - Java Programming with Domino: A look at Servlets & JSPs
Enterprise IntegrationJava Lotus ConnectorsDomino JDBC driver
Attend AD203 - Know the Code: Integrating Relational Data Using Java
Domino 5.x and Java (continued)
![Page 84: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/84.jpg)
JavaServletsJava Server PagesJ2EE Technologies
Let's update your resumes
![Page 85: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/85.jpg)
TS102: Building and Deploying Java Web Applications on a Domino ServerTS113: The Architecture of the New Web Programming Model in RnextHC103: Building R5 Web Applications using JavaServer Pages and WebSphereHC109: Implementing the Domino Rnext JSP Tag LibraryHC114: Tools and Tips for Working with the Rnext JSP Tag Library
Please complete your evaluationsPlease complete your evaluations
Other JSP Related Sessions
![Page 86: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/86.jpg)
Why Java ?Basic Java conceptsAccessing Domino via JavaJSP and Servlets
Summary
![Page 87: Introduction to Java for Lotus Script Programmers](https://reader036.vdocument.in/reader036/viewer/2022081715/54481e65b1af9f28268b4ce3/html5/thumbnails/87.jpg)
Please complete your evaluationsQuestions?