object oriented programming - java

18
Object Oriented Programming – Java By Daniel : - javac -java -javah -javadoc -appletviewer

Upload: daniel-ilunga

Post on 15-Jul-2015

88 views

Category:

Education


2 download

TRANSCRIPT

Object Oriented

Programming – Java

By Daniel :

- javac

-java

-javah

-javadoc

-appletviewer

javac

javac stands for Java Compiler

The javac tool reads class and interface definitions, written in the Java

programming language, and compiles them into bytecode class files.

There are two ways to pass source code file names to javac:

o For a small number of source files, simply list the file names on the

command line.

o For a large number of source files, list the file names in a file,

separated by blanks or line breaks.

javac (Cont..)

Source code file names must have .java suffixes, class file names must have .class

suffixes, and both source and class files must have root names that identify the class.

For example, a class called MyClass would be written in a source file called

MyClass.java and compiled into a bytecode class file called MyClass.class.

Inner class definitions produce additional class files. These class files have names

combining the inner and outer class names, such as MyClass$MyInnerClass.class.

You should arrange source files in a directory tree that reflects their package tree. For

example, if you keep all your source files in /workspace, the source code for

com.mysoft.mypack.MyClass should be in

/workspace/com/mysoft/mypack/MyClass.java.

By default, the compiler puts each class file in the same directory as its source file. You

can specify a separate destination directory with -d option

After using the javac command

as follow:

$ Javac car.java

We get car.class file ready to

be used by the launcher

(Car.class)

The work of the javac

javac

Sets the destination directory for class files. The

destination directory must already exist; javac will not

create the destination directory.

If a class is part of a package, javac puts the class file in a

subdirectory reflecting the package name, creating

directories as needed.

For example, if you specify -d /home/myclasses and the

class is called com.mypackage.MyClass, then the class

file is called

/home/myclasses/com/mypackage/MyClass.class.

java

java - Java application launcher

The java tool launches a Java application. It does this by starting a Javaruntime environment, loading a specified class, and invoking that class's mainmethod.

The method must be declared public and static , it must not return any value, andit must accept a String array as a parameter. The method declaration must looklike the following: public static void main(String dims[]) By default, the firstnon-option argument is the name of the class to be invoked.

A fully-qualified class name should be used. If the -jar option is specified, thefirst non-option argument is the name of a JAR archive containing class andresource files for the application, with the startup class indicated by the Main-Class manifest header.

The Java runtime searches for the startup class, and other classes used, in threesets of locations: the bootstrap class path, the installed extensions, and the userclass path. Non-option arguments after the class name or JAR file name are passedto the main function.

What does the java launcher do?

java is called as ‘java launcher because It does this by starting a Java

runtime environment, loading a specified class, and invoking that class's

main method. This method must have the following signature: public static

void main(String[]). It has to be static and public. This means that it’ll have

the job of loading the .class file and making it ready for execution by the

Java Virtual Machine (JVM).

$ java runCar --runCar if the class with the main method:

javahjavah - C header and stub file generator

The javah command generates C header and source files that

are needed to implement native methods. The generated

header and source files are used by C programs to reference

instance variables of an object from native source code. The

.h file contains a structure definition whose layout parallels

that of the corresponding class. The fields in the structure

correspond to instance variables in the class.

The name of the header file and the structure declared

within it are derived from the name of the class. If the class

passed to javah is inside a package, the package name is

prepended to both the header file name and the structure

name. Underscores ( _ ) are used as name delimiters.

Javah (cont..)

By default, javah creates a header file for each class listed onthe command line and puts the files in the current directory.Use the -stubs option to create source files. Use the -ooption to concatenate the results for all listed classes into asingle file.

The new native method interface, Java Native Interface(JNI), does not require header information or stub files. Thejavah command can still be used to generate native methodfunction prototypes needed for JNI-style native methods.javah produces JNI-style output by default, and places theresult in the .h file.

The javah_g version is a non-optimized version of javahsuitable for use with debuggers like jdb.

$ Javah runCar

This will create an header file for the class runCar that

can help in implementing the java code in C language. And

this command must be done on the class with the main

method, for our case now it is runCar.

After $ javah runCar we get:

Now we’ll try viewing what contained in the runCar.h file

$ cat runCar.h

This is how the runCar.h file looks like. Interesting, isn’t it?

javadocjavadoc - Java API documentation generator

The Javadoc tool parses the declarations and documentation commentsin a set of Java source files and produces a corresponding set of HTMLpages describing (by default) the public and protected classes, nestedclasses (but not anonymous inner classes), interfaces, constructors,methods, and fields.

You can run the Javadoc tool on entire packages, individual source files,or both. In the first case, you pass in as an argument to javadoc a seriesof package names. In the second case, you pass in a series of source(.java) file names. See EXAMPLES at the end of this document.

NOTE - When you pass in package names to the Javadoc tool, itcurrently processes all .java classes in the specified package directories,even if the

java files are code examples or other classes that are not actuallymembers of the specified packages. It does not parse each .java file fora package declaration; we may add this parsing in a future release.

javadoc (cont..)During a run, the Javadoc tool automatically adds cross-reference links to package, class and member names that arebeing documented as part of that run. Links appear in severalplaces:

o Declarations (return types, argument types, field types)

o "See Also" sections generated from @see tags

o In-line text generated from {@link} tags

o Exception names generated from @throws tags

o Specified by links to members in interfaces and Overrides linksto members in classes

o Summary tables listing packages, classes and members

o Package and class inheritance trees

This is an example of a javadoc

class. Note that all the method

and classes are public in

nature. The comments starts as

/** and ends with */. To

generate documentation for

this code, do:

$ Javadoc MyClass.java

The documentation to

generated is per java standards

of documentation.

MyClass.java

After :

$ Javadoc MyClass.java

You should see:

Now our java documentation MyClass.html is ready to use:

appletviewer

appletviewer - Java applet viewer

The appletviewer command connects to the documents orresources designated by urls and displays each applet referencedby that document in its own window.

Note:

if the documents referred to by urls do not reference any appletswith the OBJECT, EMBED, or APPLET tag, appletviewer doesnothing. For details on the HTML tags that appletviewersupports, seehttp://java.sun.com/j2se/1.5.0/docs/tooldocs/appletviewertags.html.

Command:

$ appletviewer MyClass.html

Thank you!

By Daniel Ilunga