Java tools

27
Java tools Java programming ID1006 20 Sep 2010

description

Java tools. Java programming ID1006 20 Sep 2010. javac – Java compiler. Java source code files: *.java Java byte code files: *.class Java resource archives: *.jar javac compiles .java files into .class files Can be run interactively or from build tools. javac – The Java compiler. .java. - PowerPoint PPT Presentation

Transcript of Java tools

Page 1: Java tools

Java tools

Java programming ID1006

20 Sep 2010

Page 2: Java tools

javac – Java compiler

• Java source code files: *.java

• Java byte code files: *.class

• Java resource archives: *.jar

• javac compiles .java files into .class files

• Can be run interactively or from build tools

Page 3: Java tools

javac – The Java compiler

.java javac .classjava

(JVM)

Source code text Compilation Byte code Execution

Page 4: Java tools

javac – The Java compiler

• javac [options][sourcefiles][classes][@argfiles]

• i.e.: javac Parser.java

• -classpath

• or environment variable CLASSPATH

Page 5: Java tools

Classpath

asg1/ asg2/ asg3/

/

SET CLASSPATH=.;..\asg1;..\asg2;..\asg3

Token.classWordToken.classPunctToken.classTextMeter.classParser.class

LixTest.classLixMeter.class

FleschTest.classFleschMeter.class

SyllableCounter.class

Page 6: Java tools

javadoc

• Compiles documentation from Java source code

.java javadoc.html.css...

Webbrowser

Source code text Compilation HTML pages Reading

Page 7: Java tools

javadoc

• Comments /** ... */ before the documented item

/** * Computes the square of an integer. * @param i The integer to square * @return The squared value of its argument */public int square(int i) { return i*i;}

Page 8: Java tools

javadoc

• @param name desc – documents arguments

• @return desc – documents return value

• @throws exception desc – documents the conditions under which an exception is thrown

Page 9: Java tools

javadoc

• http://download.oracle.com/javase/6/docs/technotes/guides/javadoc/index.html

• http://download.oracle.com/javase/6/docs/technotes/tools/windows/javadoc.html#javadoctags

Page 10: Java tools

apt

• annotation processing tool

• Allows the adding of metadata to code

• Annotations do not alter the meaning of the code, but...

• ...libraries and other tools may alter their behaviour in response to annotations

Page 11: Java tools

apt

/** * Describes the Request-For-Enhancement(RFE) that led * to the presence of the annotated API element. */public @interface RequestForEnhancement { int id(); String synopsis(); String engineer() default "[unassigned]"; String date() default "[unimplemented]";}

This is an annotation type

Page 12: Java tools

apt

/** * Describes the Request-For-Enhancement(RFE) that led * to the presence of the annotated API element. */public @interface RequestForEnhancement { int id(); String synopsis(); String engineer() default "[unassigned]"; String date() default "[unimplemented]";}

@-sign

Page 13: Java tools

apt

/** * Describes the Request-For-Enhancement(RFE) that led * to the presence of the annotated API element. */public @interface RequestForEnhancement { int id(); String synopsis(); String engineer() default "[unassigned]"; String date() default "[unimplemented]";}

@-sign

Default values

Page 14: Java tools

apt

@RequestForEnhancement( id = 2868724, synopsis = "Enable time-travel", engineer = "Mr. Peabody", date = "4/1/3007")public static void travelThroughTime(Date destination) { ... }

Page 15: Java tools

apt

@RequestForEnhancement( id = 2868724, synopsis = "Enable time-travel", engineer = "Mr. Peabody", date = "4/1/3007")public static void travelThroughTime(Date destination) { ... }

The annotation preceeds the

annotated method

Page 16: Java tools

apt

@RequestForEnhancement( id = 2868724, synopsis = "Enable time-travel", engineer = "Mr. Peabody", date = "4/1/3007")public static void travelThroughTime(Date destination) { ... }

The annotation preceeds the

annotated method

Ordinary Java method

Page 17: Java tools

apt

• Annotations can be used to control– Automated software testing– Documentation tools– Automated software configuration– and more...

Page 18: Java tools

apt

• http://download.oracle.com/javase/6/docs/technotes/guides/language/annotations.html

Page 19: Java tools

jar

• Java archive

• Stores class files, images, sounds etc in a single file

• Supports compression

• Used to package libraries and applications

• Fetch-and-run over the Internet

Page 20: Java tools

jar

• Create an archive: jar cf jarfile inputfile ...• jar cf Foo.jar *.class *.jpg

Create Next argumentis the file nameof the archive

Files to be copiedinto the archive

Page 21: Java tools

jar

• Create an archive: jar cf jarfile inputfile ...• jar cf Foo.jar *.class *.jpg

• Unpack an archive: jar xf jarfile

• jar xf Foo.jar

Page 22: Java tools

jar

• Create an archive: jar cf jarfile inputfile ...• jar cf Foo.jar *.class *.jpg

• Unpack an archive: jar xf jarfile• jar xf Foo.jar

• Run from an archive*: java –jar jarfile• java –jar Foo.jar

* Requires jar manifest meta-data: main class and classpath

Page 23: Java tools

jar

• http://download.oracle.com/javase/6/docs/technotes/guides/jar/index.html

• http://download.oracle.com/javase/6/docs/technotes/tools/windows/jar.html

Page 24: Java tools

javap

• Java disassembler

• Shows class fields and methods• javap [options] classname

• -public|-protected|-private|-package• -s show internal signatures

• -c show byte code

Page 25: Java tools

javap

• http://download.oracle.com/javase/6/docs/technotes/tools/windows/javap.html

Page 26: Java tools

RMI

• Remote Method Invocation

• One JVM calls methods on a remote JVM

• Client and service

Page 27: Java tools

Remote Method Invocation

Jvm A Jvm B