Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Developing Environment Olivier de Pertat IT GROUP Developing In Java Text Editors Java Compilers Building Tools Setting Your Environment Logging Capabilities Unit Testing Java Compilers Latest Java Version : 1.5 Latest J2EE Version : 1.4 (1.5 is comming) Many Providers : SUN : Solaris, Win32, Linux x86 IBM : AIX, Linux x86, Win32, Solaris, HP-UX, OS/390, z/Linux… BEA : Linux iA64, Win32 HP : HP-UX Non Compliant JVM : Microsoft J++ & Many old JVM Warning : For JAKARTA products on Linux Operating Systems it might be useful to use IBM JDK’s. Old Microsoft JVM are not completely Java Compliant. Building Tool : ANT Command Line not suited to projects. ANT : Managed by XML File (build.xml). Tag based Architecture. Fully written in Java. Runs on every OS that supports Java. Extensible Application by development. Not limitations like : Makefile, nmake, jam… Developed by Jakarta from Apache Group. An Industry Standard : Used in IDE for Java Compilation : JBuilder, Jext, Emacs, JDE, NetBeans, JEdit, Eclipse, Visual Age For Java, WSAD AS : WebLogic (deployment handled by ANT) ANT (1) Tag Structure : Main tag : Project One “project” tag by build file. Specifies the default task to perform. Specifies the working directory. Default file : Build.xml <project name="j2ee-lesson" default="sys-about" basedir="."> <target name="sys-about"> <echo>Hello World ! </echo> </target> </project> Command line : ant <target> ANT (2) Variable declaration : <project name="j2ee-lesson" default="sys-about" basedir="."> <!-- System variables --> <property environment="myenv" /> <property name=" PATH“ value="${myenv.PATH}" /> <property name="SQL_FILE" value="test.tmp.sql" /> Java Compilation : <target name="j2ee-mk-class" depends=""> <buildnumber /> <echo>Compiling Java Source</echo> <javac srcdir="${src}" debug="yes“ destdir="${build}“ classpath="${PROJECT_CLASSPATH}"/> </target> ANT (3) Java Execution : <target name="run-MyHello" depends="j2ee-mk-class"> <java classname="mytest.MyHello" fork="yes"> <jvmarg value="${RUN_OPTION_1}" /> <classpath> <pathelement path="${PROJECT_RUN_CLASSPATH}"/> </classpath> </java> </target> File Manipulation : Create Directory : <mkdir dir="${build}" /> Delete files & directories : <delete dir="${build}" /> Copy, Move files & directories Compression : gzip, zip, jar, bzip2, tar Security : chmod Others : checksum, basename, concat, touch ANT (4) System Tasks Execution : <exec executable="j2ee.bat"> <env key="CLASSPATH" value="${J2EE_CLASSPATH}" /> <arg line="-verbose" /> </exec> Network Services : Mailing : mail FTP : File transfer RCS & CVS Management : cvs… ANT (5) SQL Commands (JDBC Way) : <target name="sys-OracleSQL" depends=""> <sql driver="${ORACLE_DRIVER}" url="${ORACLE_URL}" userid="${ORACLE_USER}" password="${ORACLE_PASSWORD}" classpath="${ORACLE_CLASSPATH}" src="${SQL_SCRIPT}" print="true" /> </target> SQL Commands (SQL*Plus Way) : <property name="DB_EXEC_ARGS" value="${ORACLE_USER}/${ORACLE_PASSWORD}@${ORACLE_NAME} @${SQL_SCRIPT}" /> <echo file="${SQL_SCRIPT}" append="true">exit;</echo> <echo>${DB_EXEC_ARGS}</echo> <exec dir="." executable="${ORACLE_SQLCMD}"> <arg line="${DB_EXEC_ARGS}" /> </exec> Logging Capabilities Traces are needed : Development Debugging Production & problem tracking System.out : is limited and not persistent (#define) Logging APIs: Jakarta’s Log4J: Production reference Most used in projects Powerful JDK 1.4 logging APIs (JSR-47): Standard Java API since 1.4 VMs Sun’s reference Jakarta Common Logging (JCL): Wrapper API for : Log4J, JDK 1.4, Avalon LogKit, Pre 1.4 JDKs, Common functionalities present but not specifics Log4J LOG4J : Developed JAKARTA (Apache Group) Logging system dynamically & statically configurable high-performance Java API Defined levels : FATAL : logger.fatal(“string”) ERROR : logger.error(“string”) WARNING : logger.warn(“string”) INFO : logger.info(“string”); DEBUG : logger.debug(“string”) LOG4J (2) Import needed : org.apache.log4j.*; Sample In Java : static Logger logger = Logger.getLogger(mytest.MyLoggedHello.class.getName()); public MyLoggedHello() { logger.fatal("FATAL : Constructor called !"); logger.error("ERROR : Constructor called !"); logger.warn( "WARN : Constructor called !"); logger.info( "INFO : Constructor called !"); logger.debug("DEBUG : Constructor called !"); } LOG4J (3) File configuration : Log4J.properties (Console) log4j.rootCategory=DEBUG, A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout File configuration : Log4J.properties (File) log4j.rootCategory=INFO,R log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=wstools-debug.log log4j.appender.R.MaxFileSize=100KB log4j.appender.R.MaxBackupIndex=1 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n JVM Arguments : java -Dlog4j.configuration=file:/Log4J.properties MyProgam JDK Logging Sun’s Flogging Framework Logger / LogManager Architecture Package: java.util.logging. Levels are: Level.SEVERE Level.WARNING Level.INFO Level.CONFIG Level.FINE Level.FINER Level.FINEST JDK Logging (2) Handlers: StreamHandlers Console Handlers File Handler SocketHandler MemoryHandler Formatters: SimpleFormatter: simple chars output XMLFormatter: XML File format output JVM Parameter: java -Djava.util.logging.config.file=monLogging.properties Unit Testing : JUnit Unit Testing : Non-regression tests Improve quality Speed-up code writing JUnit : Developed JAKARTA Command-Line or Graphical. Simple Java API. Package : junit.framework JUnit (2) JUnit Java Sample : public class CheckMyHello extends TestCase { ….. public void testAssertPosInfinityEqualsInfinity() { assertEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 0.0); } public static Test suite() { TestSuite suite= new TestSuite(); suite.addTest(new TestSuite("testItSays")); suite.addTest(new TestSuite(CheckMyHello.class)); suite.addTest(new TestSuite(CheckAssertTest.class)); return suite; } } JUnit (3) Running JUnit (Command Line) : public static void main(String [] args) { junit.textui.TestRunner.run(suite()); } Running JUnit (Graphical) : java junit.swingui.TestRunner mytest.CheckMyHello JUnit (4) Using Standard Output : public void testItSays() { String lineSeparator = System.getProperty("line.separator"); ByteArrayOutputStream out4debug = new ByteArrayOutputStream(); PrintStream out_new = new PrintStream(out4debug); PrintStream out_bkp = System.out; MyHello objectTested = null; String outputExcepted = "Hello Object Built !" + lineSeparator; System.setOut(out_new); objectTested = new MyHello(); System.setOut(out_bkp); assertTrue((out4debug.toString()).equals(outputExcepted)); } ODP’s JavaBox (1) Tool Box packaged for Java programming: Everything is included! Nothing more is needed. Java Standard Edition 1.4.2 (J2SE) Java Entreprise Edition 1.4: SUN Application Server: Tools, libs… 2 Database Engine: PointBase Server HSQL DB Java Text Editor: JExt (Color highlight) ANT: asant Some useful utilities: Custom Windows Shell UNIX Basic utilities: tail, zip, md5sum.. Why? Simple. No complex to understand IDE to learn. Easy to install at work, at home… No special authorizations are needed to install it. Even in a cyber coffee as a guest user it works! Can be used for large projects. ODP’s JavaBox (2) Installation: Unzip the archive to anywhere you want. Run the SHELL named “JavaShell.cmd”. It automatically detects whether or not installation has been processed. Installation process is run once. Installation is fast but can be slow down by Antivirus software ODP’s JavaBox (3) A virtual J: drive is mapped to your installation Directory. Every source file should be placed in J:\src To write your first program you should: Launch a JavaShell Launch JExt (thro ugh the shortcut placed in J:\bin) Write your program Save it to J:\src directory Compile it by typing in the JavaShell: J:\>asant make Run it by typing in the JavaShell J:\>java MyFirstProgram Enjoy!