Labels

Wednesday, March 9, 2011

Java basics ---Using Java Utilities

Consider a file you have created in java named "Hello.java".
(1) Javac(java compiler) -
used for compiling java file and producing .class file.
--use following  command line at shell prompt
javac Hello.java
--if the code is correct it will compile and it will create "Hello.class" file.
--to see  what javac is doing behindthe scenes use following command line
javac -verbose Hello.java

(2) java(java Interpreter) -
to run a .class file or  runing an application
java Hello
It will give output of your source code.
Note: no extension is needed when  invoking the interpreter.
--to view execution details of comipled code use command line
java-prof Hello

--this will generateThis will generate a profile which shows

->methods called in order of decreasing frequency.
->how memory is used.
->list of variable  and bytes necessary to store them.

(3) javadoc(javadocumentation)- generate source code documention
--To generate this documentation, use thecommand line 
javadoc Hello.java
---it generates four html documents:

1.packages.html,
2.HelloWorld.html,
3.AllNames.html,
4.tree.html.


-All methods including the main method(function) are inside classes.
-Every java application must main method except Applets.
-Signature of main method is:

public static void main (String args[])


• For the main method
– public is the access specifier.
– static is the storage class.
– void is the return type.
 String args[] is an array of strings
(4) jdb(java debugger)-
Sometimes the program compiles but does not work as intended.

• In this situation the java debugger can be used.

– to generate full debugging info use the
javac -g Hello

--> to invoke the  debuggeruse command line.
jdb HelloWorld
--To set a breakpoint, use the command
 stop in HelloWorld.main
followed by run
-- >When the breakpoint is hit, type
list
-- >to see the code,Type
clear HelloWorld.main
followed by cont


Java programs are commonly of two types

– Applications
– Applets
• A piglet is to a pig as an applet is to an application.
• Applications are stand-alone Java programs.
• Applets are programs that require a browser torun. Applets are typically downloaded from the
Internet and run in an applet window within a browser.

No comments:

Post a Comment