Updates from July, 2014 Toggle Comment Threads | Keyboard Shortcuts

  • shashankgee 7:56 am on 1 Jul 2014 Permalink | Reply  

    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

    Advertisements
     
  • shashankgee 12:04 pm on 23 Jun 2014 Permalink | Reply  

    different syntaxes for array declerations in java 

    
    Integer[] in = new Integer[10];
    
    Integer[] in1 = { 1, 3, 4 };
    
    Integer[] in3={new Integer(1),new Integer(2),new Integer(4)};
    
    Integer[] in2 = new Integer[] { 1, 2 };
    
    Integer[] in4=new Integer[]{new Integer(2),new Integer(3)};
    
    Integer[] in5=new Integer[new Integer(2)];
    
    
     
  • shashankgee 4:32 pm on 14 May 2014 Permalink | Reply  

    Difference between Comparable and comparable 

    Comparator and Comparable
    Comparator and Comparable
     
  • shashankgee 6:02 pm on 12 May 2014 Permalink | Reply  

    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

    Proof:

    Just create the Basic Example Lets say:

    private class Test{
    public static void main(String[] args){
       System.out.println("Proof");
       }
    }
    


    Test.java:1: 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

     

     

     
  • shashankgee 5:25 pm on 11 May 2014 Permalink | Reply  

    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();
    }
    
    }
    

    output

    A Constructor
    A Constructor
    B Constructor
    A Constructor
    B Constructor
    
    
    	
     
  • shashankgee 6:34 am on 6 May 2014 Permalink | Reply  

    How to Compile Java file with Package in command prompt 

    Example:

    
    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");
    
    }
    
    }
    
    

    Comipile:

      javac -d . Test.java

    Note: -d and . should be seperated with space

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

    Run:

    java com.sparity.Test

     

     

     

     

     

     
  • shashankgee 4:07 pm on 23 Oct 2013 Permalink | Reply  

    Difference between Intialization block and constructors 

    
    package tutes.by.shashank.PractiseSCJP;
    
    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");
    
     }
    
     };
    
    }
    
    }
    
    
     
  • shashankgee 6:49 am on 31 Jul 2013 Permalink | Reply  

    program for List without duplicate elements 

    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    
    public class AvoidDuplicateList {
    
    /**
     * @param args
     *
     * Generally ,List allows the duplicate elements This example
     * shows you avoid adding of duplicate elements to List.
     *
     *
     */
    
    static List<String> list2;
    
    public static void main(String[] args) {
    
    list2 = new ArrayList<String>();
    
    ArrayList<String> list1 = new ArrayList<String>();
    
    list1.add("India");
     list1.add("Japan");
     list1.add("China");
     list1.add("China");
     System.out.println(list1);
     Iterator iterator = list1.iterator();
    
    while (iterator.hasNext()) {
     String cou = (String) iterator.next();
    
    if (!(list2.contains(cou))) {
    
    list2.add(cou);
     }
    
    }
     System.out.println(list2);
    
    }
    
    }
    
    &nbsp;
    
    
     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel