Friday, 4 July 2014

How do I compare strings in Java

Use equals () to compare

two string 



package com.vipul;

public class StringComporation {

      /**
      * How do I compare strings in Java
      * @param args
      */
      public static void main(String[] args) {
            String fooString1 = new String("foo");
            String fooString2 = new String("foo");
            // Evaluates to true
            if(fooString1.equals(fooString2));
            {
                  System.out.println(fooString1);
            }
           

      }

}
==========================================================================
Maven + eclipse related 
An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4 fixed

==================================================================================

How to convert StringBuilder to String

package com.vipul;

public class StringBuildertoString {

      /**
      * How to convert StringBuilder to String
      * @param args
      */
      public static void main(String[] args) {
            StringBuilder sb = new StringBuilder();
                sb.append("test");

                System.out.println(sb.toString());

      }

}

==========================================================================
Maven + eclipse related 
An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4 fixed

==================================================================================

How to concatenate or combine two Strings

How to combine two Strings


package com.vipul;

public class Stingconcatenate {

      /**
      * How to combine two Strings
      * @param args
      */
      public static void main(String[] args) {
            String firstName = "Vipul";
            String lastName  = "Gulhane";
            String fullName  = firstName + lastName;
            System.out.println("Stingconcatenate is "+fullName);
      }

}

==========================================================================
Maven + eclipse related 
An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4 fixed

==================================================================================

How to remove the last character in StringBuilder

How to remove the last character in StringBuilder


package com.vipul;

public class StringBufferDelete {

      /**
      * How to remove the last character in StringBuilder
      * @param args
      */
      public static void main(String[] args) {
            String text2 = "Test";         
              StringBuffer text=new StringBuffer(text2);
           // ...
           final int length = text.length();
           if ( length > 0 ) {
                // We have remove the last character.
                text.deleteCharAt( length - 1 );
           }
           System.out.println(text);
      }

}

==========================================================================
Maven + eclipse related 
An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4 fixed

==================================================================================

Getting the Current Working Directory in Java

package com.vipul;

public class CurrruntPath {

      /**
      * Getting the Current Working Directory in Java
      * @param args
      */
      public static void main(String[] args) {
            System.out.println("Working Directory = " +
                    System.getProperty("user.dir"));
       

      }

}

convert string to ascii value

this is example of StringToAscii convertion in java.

string get character java ascii to value

package com.vipul;

public class StringToAscii {
      public static void main(String[] args) {

            char character = 'a';
            int ascii = (int) character;
            System.out.println("ascii is"+ascii);
      }
}


Output is ::
================================
ascii is:97
================================

one to many relationship example in hibernate annotations


This was one to many relationship example in hibernate annotations.how to achive one to many mapping in hibernate java integration with mysql.

this was the the database design.

===========================================================
1)pom.xml
===========================================================