Linux command for java

DESCRIPTION

The java tool launches a Java application. It does this by starting a Java runtime environment, loading a specified class, and invoking that class’s main method. The method must be declared public and static , it must not return any value, and it must accept a String array as a parameter. The method declaration must look like the following:

public static void main(String args[])

By default, the first non-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, the first non-option argument is the name of a JAR archive containing class and resource 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 three sets of locations: the bootstrap class path, the installed extensions, and the user class path.

Non-option arguments after the class name or JAR file name are passed to the main function.

OPTIONS

The launcher has a set of standard options that are supported on the current runtime environment and will be supported in future releases. In addition, the current impletmentations of the virtual machines support a set of non-standard options that are subject to change in future releases.

Standard Options

Tag Description
-client Selects the Java HotSpot Client VM . For more information see Server-Class Machine Detection at http://java.sun.com/j2se/1.5.0/docs/guide/vm/server-class.html
-server Selects the Java HotSpot Server VM . For more information see Server-Class Machine Detection at http://java.sun.com/j2se/1.5.0/docs/guide/vm/server-class.html
-agentlib:libname[=options]
Load native agent library libname , e.g.,
-agentlib:hprof -agentlib:jdwp=help -agentlib:hprof=help

With no arguments, enableassertions or -ea enable assertions. With one argument ending in «. «, the switch enables assertions in the specified package and any subpackages. If the argument is simply «. «, the switch enables assertions in the unnamed package in the current working directory. With one argument not ending in «. «, the switch enables assertions in the specified class.

If a single command line contains multiple instances of these switches, they are processed in order before loading any classes. So, for example, to run a program with assertions enabled only in packagecom.wombat.fruitbat (and any subpackages), the following command could be used:

The -enableassertions and -ea switches apply to all s loaders and to system classes (which do not have a class loader). There is one exception to this rule: in their no-argument form, the switches do not apply to system. This makes it easy to turn on asserts in all classes except for system classes. A separate switch is provided to enable asserts in all system classes; see -enablesystemassertions below.

With no arguments, disableassertions or -da disables assertions. With one argument ending in «. «, the switch disables assertions in the specified package and any subpackages. If the argument is simply «. «, the switch disables assertions in the unnamed package in the rent working directory. With one argument not ending in «. «, the switch disables assertions in the specified class.

To run a program with assertions enabled in package com.wombat.fruitbat but disabled in class com.wombat.fruitbat.Brickbat, the following command could be used:

java -ea:com.wombat.fruitbat. -da:com.wombat.fruitbat.Brickbat

The -disableassertions and -da switches apply to all ss loaders and to system classes (which do not have a class loader). There is one exception to this rule: in their no-argument form, the switches do not apply to system. This makes it easy to turn on asserts in all classes except for system classes. A separate switch is provided to enable asserts in all system classes; see -disablesystemassertions below.

Non-Standard Options

Tag Description
-Xint Operates in interpreted-only mode. Compilation to native code is disabled, and all bytecodes are executed by the interpreter. The performance benefits offered by the Java HotSpot VMs’ adaptive compiler will not be present in this mode.
-Xbatch Disable background compilation. Normally the VM will compile the method as a background task, running the method in interpreter mode until the background compilation is finished. The -Xbatch flag disables background compilation so that compilation of all methods proceeds as a foreground task until completed.
-Xdebug Start with support for JVMDI enabled. JVMDI has been deprecated and is not used for debugging in J2SE 5.0, so this option isn’t needed for debugging in J2SE 5.0.
-Xbootclasspath:bootclasspath
Specify a colon-separated list of directories, JAR archives, and ZIP archives to search for boot class files. These are used in place of the boot class files included in the Java 2 SDK. Note: Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license.
-Xbootclasspath/a:path Specifies a colon-separated path of directories, JAR archives, and ZIP archives to append to the default bootstrap class path.
-Xbootclasspath/p:path Specifies a colon-separated path of directories, JAR archives, and ZIP archives to prepend in front of the default bootstrap class path. Note: Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed, as doing so would contravene the Java 2 Runtime Environment binary code license.
-Xcheck:jni Perform additional checks for Java Native Interface (JNI) functions. Specifically, the Java Virtual Machine validates the parameters passed to the JNI function as well as the runtime environment data before processing the JNI request. Any invalid data encountered indicates a problem in the native code, and the Java Virtual Machine will terminate with a fatal error in such cases. Expect a performance degradation when this option is used.
-Xfuture Performs strict class-file format checks. For purposes of backwards compatibility, the default format checks performed by the Java 2 SDK’s virtual machine are no stricter than the checks performed by 1.1.x versions of the JDK software. The -Xfuture flag turns on stricter class-file format checks that enforce closer conformance to the class-file format specification. Developers are encouraged to use this flag when developing new code because the stricter checks will become the default in future releases of the Java application launcher.
-Xnoclassgc Disables class garbage collection
-Xincgc Enable the incremental garbage collector. The incremental garbage collector, which is off by default, will reduce the occasional garbage-collection pauses during program execution. The incremental garbage collector will at times execute concurrently with the program and during such times will reduce the processor capacity available to the program.
-Xloggc: file Report on each garbage collection event, as with -verbose:gc, but log this data to file . In addition to the information -verbose:gc gives, each reported event will be preceeded by the time (in seconds) since the first garbage-collection event.
-Xms6291456 -Xms6144k -Xms6m
-Xmx83886080 -Xmx81920k -Xmx80m

n a previous release, the Shutdown Hooks facility was added to allow orderly shutdown of a Java application. The intent was to allow user cleanup code (such as closing database connections) to run at shutdown, even if the JVM terminates abruptly.

Sun’s JVM catches signals to implement shutdown hooks for abnormal JVM termination. The JVM uses SIGHUP, SIGINT, and SIGTERM to initiate the running of shutdown hooks.

The JVM uses a similar mechanism to implement the pre-1.2 feature of dumping thread stacks for debugging purposes. Sun’s JVM uses SIGQUIT to perform thread dumps.

Applications that embed the JVM frequently need to trap signals like SIGINT or SIGTERM, which can lead to interference with the JVM’s own signal handlers. The -Xrs command line option is available to address this issue. When -Xrs is used on Sun’s JVM, the signal masks for SIGINT, SIGTERM, SIGHUP, and SIGQUIT are not changed by the JVM, and signal handlers for these signals are not installed.

Источник

How to Run Java from Command-line in Linux

Java is the world’s popular software development platform that James Gosling develops. It is designed to support multiple platforms like Linux, macOS and Windows. Mobile and Desktop applications can also be developed using Java language.

Java language is one of the most popular high-level object-oriented programming languages. It comes with a simple syntax and easily understandable for beginners, as it is very secure and economical to use. Java is the platform-independent software, and it also provides an auto garbage collection facility.

How to Run Java through Command-line

To run the java program in Linux, we need to verify if Java Development Kit (JDK) is available in the system and its version.

To confirm it, type the following command:

(Javac command-line tool is used for the compilation of java programs)

The Javac command tool is not available in my system. We have multiple commands to download it, as mentioned in the above image.

Let’s go with the default-jdk command to get it:

To verify the installation of javac, type:

Now, write a Java program in the text file and save it with .java extension.

Suppose I created a file named “testing.java” and write a simple program in it:

(Keep in mind that your class name should be the same as the file name)

Compile the testing.java file on the terminal using the javac command:

Now, execute the Java program by calling its class name in the terminal:

Conclusion

Java is the high-level language of the modern era supported by the Java Development Kit (JDK). JDK is a package that helps to run java and is used for the development of software packages.

Java language comes with a simple syntax that is easy to get for beginners, and it is one of the most usable object-oriented programming languages.

We have seen in this article that how to install and run Java applications on the terminal.

About the author

Syeda Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.

Источник

Читайте также:  Linux таблица открытых файлов
Оцените статью
Adblock
detector