Java Utilities - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

demo-image

java vs. javaw

When a Java application is launched with java command, JVM uses the command window as a console.

If you don't want this console window, you can use javaw command to launch the application. The difference between java and javaw is javaw does not create any console whereas java does.

Here is what I did to test the javaw tool.

1. Write and compile Test.java

2. Open a command window to run Test.class using java Test.

3. Look at the output shown in the window, which is not showing any more. Because the window is being used as console for java tool.

4. Now, run the program using javaw Test.

5. Look at the output again, the command prompt is asking to provide any new commands.

6. To understand what happens to this program? Check the process list for both java and javaw. In both case they are listed in process list.

Hope, you understand that javaw is used to launch an application where console window is not needed. So javaw is good tool for the applications like GUI applications and server applications.

In both case file redirexction is supported. Let us test it.

1
2
3
4
5
6
7
public class Test {
public static void main(String args[]) {
System.out.println("Hello");
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


1
2
3
4
5
#javac Test.java
#java Test > my1.log
#javaw Test > my2.log
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


1
2
3
4
5
6
7
8
public class Test {
public static void main(String args[]) {
Scanner c = new Scanner(System.in);
System.out.println("Hello" + c.nextInt());
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


1
2
3
#javac Test.java
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Create a file containing a integer number


1
2
3
4
5
#vi myInput.file
#java Test < myInput.file
#javaw Test < myInput.file
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Now you can understand that I/O can be associated with both.

As javaw.exe does not need command line window to appear. If error occurs at the time of execution, the error is shown in a dialog box.

java.exe can be used when input and output texts are read from or shown on console.

As IDEs (like Netbeans, Eclipse etc.) are using their internal console instead of system console they are using javaw instead of java.

javap

The javap command is used to disassemble one or more class files and prints the output to stdout. You can use different options according to your requirements. If you receive a class file, you can check name of the package, methods, variables etc. as shown below.


1
2
3
4
5
6
7
8
9
10
package com.abcbank.account;
public abstract class Account {
private int _accountNo;
private String _customerName;
private String _customerAddress;
private String _branchName;
private String _branchAddress;
private float _amount;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The output of javap command without any option.

javap_1

The output of javap command with -c option.

javap_2

jconsole

jconsole is monitoring and management tool for local and remote processes.

jconsole_1

Select a process from the list and connect. You will see the following screen.

jconsole_2



Happy Exploring!

Comment Using!!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.