Create,extract and see the contents of the JAR in Commnad Prompt

1)Create the jar file:

go the specific directory in which  .class files are there and the below command

jar cvf myproject.jar .

2) Extract the contents of the jar file

jar xvf myproject.jar 

3) To see the  contents of the jar file

jar tvf myproject.jar 

4) To know more about the jar options enter the below commnad

jar -help

5) To install the executable jar file

jar -jar sample.jar


Difference between AccessSpecifiers and AccessModifiers

  • Java has only AccessModifiers
  • Threre are no AccessSpecifiers in java

There are 12 AccessModifiers in java

public static native
private final transient
protected abstract volatile
<default> synchronized strictfp


Just create the Basic Example Lets say:

private class Test{
public static void main(String[] args){
} error: modifier private not allowed here
private class Test{
1 error


So From the above example we can clearly say that, Java has no AccessSpecifiers



Inheritance and Constructors behaviour

Inheritance with Constructors:

public class A{

public A(){

 System.out.println("A Constructor") ;





public class B extends A{

public B(){

System.out.println("B Constructor") ;



public class Test{

public static void main(String[] args){

A a=new A();
A a1=new B();
B b=new B();



A Constructor
A Constructor
B Constructor
A Constructor
B Constructor


How to Compile Java file with Package in command prompt


package com.sparity;

public class Test {

public static void main(String[] args){

System.out.println("Compile and run the java program with pakage in command Prompt");




  javac -d .

Note: -d and . should be seperated with space

After Compile the above program successfully,    .class    file will be generated in the com/sparity folders.


java com.sparity.Test






Difference between Intialization block and constructors


public class InitBlockandCons {

// Difference between Init block,static Block and Constructors

//static block will be called only one time after class loaded.

 /**initialization block will be called before each Object creation by Default constructor as well as
 Parameterized constructor.
 And one more advantage is initblock cab be used in AnonymousInner classes
 But Constructors can't be used.
 public InitBlockandCons() {
 System.out.println("This is Default Constructor");

 public InitBlockandCons(int i) {
 System.out.println("This is Parameterized Constructor---- "+i);

// init block
 System.out.println("This is Init Block");

// static Block

static {
 System.out.println("This is Static Blcok");


public static void main(String[] args) {

InitBlockandCons ini = new InitBlockandCons(1);
 InitBlockandCons ini1 = new InitBlockandCons(){

 System.out.println("In Anonymous Inner class");