• Java
    • JAXB Tutorial
      • What is JAXB
      • JAXB Marshalling Example
      • JAXB UnMarshalling Example
  • Spring Tutorial
    • Spring Core Tutorial
    • Spring MVC Tutorial
      • Quick Start
        • Flow Diagram
        • Hello World Example
        • Form Handling Example
      • Handler Mapping
        • BeanNameUrlHandlerMapping
        • ControllerClassNameHandlerMapping
        • SimpleUrlHandlerMapping
      • Validation & Exception Handling
        • Validation+Annotations
        • Validation+ResourceBundle
        • @ExceptionHandler
        • @ControllerAdvice
        • Custom Exception Handling
      • Form Tag Library
        • Textbox Example
        • TextArea Example
        • Password Example
        • Dropdown Box Example
        • Checkboxes Example
        • Radiobuttons Example
        • HiddenValue Example
      • Misc
        • Change Config file name
    • Spring Boot Tutorial
  • Hibernate Tutorial
  • REST Tutorial
    • JAX-RS REST @PathParam Example
    • JAX-RS REST @QueryParam Example
    • JAX-RS REST @DefaultValue Example
    • JAX-RS REST @Context Example
    • JAX-RS REST @MatrixParam Example
    • JAX-RS REST @FormParam Example
    • JAX-RS REST @Produces Example
    • JAX-RS REST @Consumes Example
    • JAX-RS REST @Produces both XML and JSON Example
    • JAX-RS REST @Consumes both XML and JSON Example
  • Miscellaneous
    • JSON Parser
      • Read a JSON file
      • Write JSON object to File
      • Read / Write JSON using GSON
      • Java Object to JSON using JAXB
    • CSV Parser
      • Read / Write CSV file
      • Read/Parse/Write CSV File – OpenCSV
      • Export data into a CSV File
      • CsvToBean and BeanToCsv – OpenCSV

JavaInterviewPoint

Java Development Tutorials

Components of Java Development Kit (JDK)

February 5, 2016 by javainterviewpoint Leave a Comment

Java Developer Kit contains tools which a Java developer needed to develop the Java programs, and JRE to run the program. In simple terms we can say that JDK is equal to JRE and Development Tools. The tools include Java Archive (jar), Java Compiler (javac), Java Disassembler (Javap), Java Debugger (jdb) , Java HeaderFile Generator (javah), Documentation (javadoc) and many others. We will look into some of the most used tool in this article.

Components of Java Development Kit

Java Archive (jar) :

Java Archive (jar) tool combines multiple Java files/ applets into a single archive .jar (Java Archive). jar is a archival and compression tool based on ZIP and ZLIB compression formats. Mainly jar is designed to package applets or multiple files into a single archive. Components of an applet or an application containing files,images, media elements etc once combined into a singe archive then the Java agent can download them in a single transaction rather than going for multiple transaction to get individual files. In addition the compression functionality reduces the download times.

Creating a Jar File

The syntax for creating a jar is

jar cf <<jar filename>> <<input file(s)>>

The options and arguments used in the above command are

  • ‘c’ – This indicates that we want to create a jar file.
  • ‘f’ – This indicates that we need the output to goto a file rather than sdout.
  • jar filename – The name of the jar which needs to be created, the filenames are given with the extension of ‘.jar’ as a convention though it is not a mandatory.
  • input files – List of the files which you want to put inside the jar file, multiple files can be added each separated by a space

Lets take the below two files Sample.java and Demo.java and put it in a single archive “Test.jar”

Sample.java

package com.javainterviewpoint;

public class Sample
{
    //Instance variable
    String name;
    //Parameterized Constructor
    public Sample(String name) 
    {
        this.name = name;
    }
    public void show()
    {
        System.out.println("Hello "+name+"!!");
    }
    public static void main(String args[])
    {
        //Create object for Sample class
        Sample sample1 = new Sample("World");
        //Call the show method
        sample1.show();
    }
}

Demo.java

package com.javainterviewpoint;

public class Demo 
{
    public void disp()
    {
        System.out.println("Welcome to JavaInterviewPoint!!!");
    }
    public static void main(String args[])
    {
        Demo d1 = new Demo();
        d1.disp();
    }
}

Upon executing the below command

jar cf Test.jar Sample.java Demo.java

we will have the “Test.jar” created.

Viewing the Contents of a JAR File

The syntax for viewing a jar is

jar tf <<jar filename>>

The options and arguments used in the above command are

  • ‘t’ – This indicates that you want to view the contents of the jar file
  • ‘f’ – This indicates that the JAR file whose contents are to be viewed is specified on the command line.
  • jar filename – The name of the jar whose contents needs to be viewed

Upon executing the below command

jar tf Test.jar

We will get the below content displayed

META-INF/
META-INF/MANIFEST.MF
Sample.java
Demo.java

Extracting the Contents of a JAR File

The syntax for Extracting a jar is

jar xf <<jar filename>>

The options and arguments used in the above command are

  • ‘x’ – This indicates that you want to extract the contents of the jar file
  • ‘f’ – This indicates that the JAR file whose contents has to be extracted is specified on the command line.
  • jar filename – The name of the jar whose contents needs to be extracted

Upon executing the below command

jar xf Test.jar

We will get the contents Sample.java and Demo.java extracted.

Updating a JAR File

The syntax for creating a jar is

jar uf <<jar filename>> <<input file(s)>>

The options and arguments used in the above command are

  • ‘c’ – This indicates that we want to update an existing jar file.
  • ‘f’ – This indicates that the JAR file whose contents has to be updated is specified on the command line.
  • jar filename – The name of the jar whose contents needs to be updated.
  • input files – List of the files which need to be added in addition

Upon executing the below command

jar uf Test.jar Sam.java

Now jar will be updated, Sam.java will be added along with Demo.java and Sample.java

Java Compiler (javac)

javac is the Compiler used in Java, javac tool it is location in the /bin folder of the JDK installation directory. Java Compiler reads all the class informations, interfaces and the other codes written in Java programming language and compiles them into byte code (.class file).

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

  • For a small number of source files, list the name of the java files separated by space
    • javac <<file1.java>> <<file2.java>>
  • For a large number of source files, create a file containing all the source file name separated by space or line breaks, to execute give the file name prefixed with @ symbol
    • javac @filelist

Java Disassembler (javap)

javap is also located in the /bin folder of the JDK installation directory. Java Disassembler disassembles one or more classes which is passed. The javap command prints the package, protected and public fields, and methods of the classes passed to it. The javap command prints its output to stdout.

Syntax

javap <<.class file1>> <<.class file2>>

Lets try to disassemble our Sample class

Output :

javap com.javainterviewpoint.Sample will give the below output

Compiled from "Sample.java"
public class Sample 
{
  java.lang.String name;
  public Sample(java.lang.String);
  public void show();
  public static void main(java.lang.String[]);
}

Java Debugger (jdb) :

Java Debugger (jdb) is a command-line debugger for Java classes it helps us in debugging our Java code. In order to start debugging we simply need to give the class name after jdb

jdb <<class name>>

Once jdb is initialized we can give any of the jdb basic commands such as run, cont, print etc… You can get the complete list of jdb commands <– here. On running jdb over the above Sample code we will get output like below

jdb com.javainterviewpoint.Sample

Output :

c:\JIP>jdb Sample
Initializing jdb ...
> run
run Sample
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Hello World!!

The application exited
}

Java Header File Generator (javah) : 

javah command generates C header and source files (.h file) which is needed to implement native methods. The generated header and source files can be used by C programs to reference an object’s instance variables from native source code. The package name is added in the header of the generated file, package name and Java Class name is seperated by underscore (_) delimiter.

Syntax

javah <<.class file1>> <<.class file2>>

Usually javah command creates a header file for each class listed on the command line and puts the files in the current directory.

When we run javah for our Sample class

javah com.javainterviewpoint.Sample

Sample.h file will be created in the current directory the content will look like below

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_javainterviewpoint_Sample */

#ifndef _Included_com_javainterviewpoint_Sample
#define _Included_com_javainterviewpoint_Sample
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

We can use the -o option to get the file in the different name and one more advantage is that if you are giving multiple class file all will be concatenated into this single file. Suppose we have another class called Demo.java

Running javah with -o option

javah -o Combined.h com.javainterviewpoint.Sample com.javainterviewpoint.Demo

will give output file name “Combined.h” and the contents like below like below

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_javainterviewpoint_Sample */

#ifndef _Included_com_javainterviewpoint_Sample
#define _Included_com_javainterviewpoint_Sample
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
/* Header for class com_javainterviewpoint_Demo */

#ifndef _Included_com_javainterviewpoint_Demo
#define _Included_com_javainterviewpoint_Demo
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

Java Documentation (javadoc) : 

javadoc tool parses the declarations and documentation comments in the Java source files and produces a corresponding set of HTML pages. It describes public, default and protected classes, interfaces, constructors, methods, and fields except anonymous inner classes. The javadoc tool can be directly called on a single or multiple files, however using the below three ways you can run the javadoc tool without specifying the file name.

  1. Giving the package name itself
  2. Using -subpackage option of javadoc
  3. Using * wildcard character in front of source filename (*.java)

Syntax

javadoc <<source file1>> <<source file2>>

Other interesting articles which you may like …

  • Java Method Overloading Example
  • Java Constructor Overloading Example
  • Java this keyword | Core Java Tutorial
  • Java super keyword
  • Abstract Class in Java
  • Interface in Java and Uses of Interface in Java
  • What is Marker Interface
  • Serialization and Deserialization in Java
  • Generate SerialVersionUID in Java
  • Java Autoboxing and Unboxing Examples
  • Use of Java Transient Keyword – Serailization Example
  • Use of static Keyword in Java
  • What is Method Overriding in Java
  • Encapsulation in Java with Example
  • Constructor in Java and Types of Constructors in Java
  • Final Keyword in Java | Java Tutorial
  • Java Static Import
  • Java – How System.out.println() really work?
  • Java Ternary operator
  • Java newInstance() method
  • Java Constructor.newInstance() method Example
  • Parameterized Constructor in Java

Filed Under: Core Java, Java Tagged With: Components of JDK, jar, Java Development Kit, javac, javadoc, javah, javap, jdb

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Java Basics

  • JVM Architecture
  • Object in Java
  • Class in Java
  • How to Set Classpath for Java in Windows
  • Components of JDK
  • Decompiling a class file
  • Use of Class.forName in java
  • Use Class.forName in SQL JDBC

Oops Concepts

  • Inheritance in Java
  • Types of Inheritance in Java
  • Single Inheritance in Java
  • Multiple Inheritance in Java
  • Multilevel Inheritance in Java
  • Hierarchical Inheritance in Java
  • Hybrid Inheritance in Java
  • Polymorphism in Java – Method Overloading and Overriding
  • Types of Polymorphism in java
  • Method Overriding in Java
  • Can we Overload static methods in Java
  • Can we Override static methods in Java
  • Java Constructor Overloading
  • Java Method Overloading Example
  • Encapsulation in Java with Example
  • Constructor in Java
  • Constructor in an Interface?
  • Parameterized Constructor in Java
  • Constructor Chaining with example
  • What is the use of a Private Constructors in Java
  • Interface in Java
  • What is Marker Interface
  • Abstract Class in Java

Java Keywords

  • Java this keyword
  • Java super keyword
  • Final Keyword in Java
  • static Keyword in Java
  • Static Import
  • Transient Keyword

Miscellaneous

  • newInstance() method
  • How does Hashmap works internally in Java
  • Java Ternary operator
  • How System.out.println() really work?
  • Autoboxing and Unboxing Examples
  • Serialization and Deserialization in Java with Example
  • Generate SerialVersionUID in Java
  • How to make a class Immutable in Java
  • Differences betwen HashMap and Hashtable
  • Difference between Enumeration and Iterator ?
  • Difference between fail-fast and fail-safe Iterator
  • Difference Between Interface and Abstract Class in Java
  • Difference between equals() and ==
  • Sort Objects in a ArrayList using Java Comparable Interface
  • Sort Objects in a ArrayList using Java Comparator

Follow

  • Coding Utils

Useful Links

  • Spring 4.1.x Documentation
  • Spring 3.2.x Documentation
  • Spring 2.5.x Documentation
  • Java 6 API
  • Java 7 API
  • Java 8 API
  • Java EE 5 Tutorial
  • Java EE 6 Tutorial
  • Java EE 7 Tutorial
  • Maven Repository
  • Hibernate ORM

About JavaInterviewPoint

javainterviewpoint.com is a tech blog dedicated to all Java/J2EE developers and Web Developers. We publish useful tutorials on Java, J2EE and all latest frameworks.

All examples and tutorials posted here are very well tested in our development environment.

Connect with us on Facebook | Privacy Policy | Sitemap

Copyright ©2023 · Java Interview Point - All Rights Are Reserved ·