> For the complete documentation index, see [llms.txt](https://hanfak.gitbook.io/workspace/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hanfak.gitbook.io/workspace/languages/java/tools.md).

# Java Tools

* The jvm comes with a lot of tooling apart from compling (javac, javac -jar) and running the class/jar (java ...)

## In the JDK /bin

* jps
  * To find running JVM, use jps
    * lists the process ID and the application’s main class name, making it far easier to figure out which process is which.
  * Can use `ps aux | grep java`
  * `jps -l` will list the fully qualified main class name
  * `jps -l <remote>` will list jvm on remote server
  * `jps -m`will show the arguments passed to the main method
  * `jps -v` will show all the arguments passed to the JVM
* javap
  * Java class file disassembler
  * Run `javap <class file>` to see that class file’s fields and methods,
    * which can often be very enlightening for understanding what code written in JVM-based languages such as Scala, Clojure, or Groovy
  * `javap -c <class file>` to see the complete bytecode of those methods.
* jmap
  * `jmap -heap <process id>` will print a summary of the JVM process’s memory space, such as
    * how much memory is being used in each of the JVM’s memory generations,
    * the heap configuration
    * type of GC being used
  * `jmap -histo <process id>` will print a histogram
    * of each class in the heap
    * how many instances there are of that class
    * how many bytes of memory are consumed
  * `jmap -dump:format=b,file=<filename> <process id>` will dump a snapshot of the entire heap to a file
* jhat
  * `jhat <heap dump file>` will take the file generated by jmap and run a local web server.
  * You can connect to this server in a browser to explore the heap space interactively, grouped by package name.
  * The “Show instance counts for all classes (excluding platform)” link shows only instances of classes outside of Java itself.
  * You can also run “OQL” queries, allowing you to query the heap space via SQL-esque syntax.
* jinfo
  * `jinfo <process id>` to see all system properties the JVM loaded with and JVM command-line flags
* jstack
  * `jstack <process id>` will print stack traces for all current Java threads running in a JVM
* jconsole and jvisualvm
  * These are graphical tools that allow connecting to JVMs and interactively monitoring running JVMs.
  * They offer visual graphs and histograms of various aspects of a running process and are a mouse-friendly alternative to many of the tools listed above.
  * These can be process/memory heavy for your local setup
* Jshell
  * command line repl
