Thursday, June 26, 2014

Java Regular Expressions common matching symbols

Regular Expression                              Description                                      Example

. Matches any single character          (“..”, “a%”) – true(“..”, “.a”) – true
                                                                                                (“..”, “a”) – false

^xxx     Matches xxx regex at the beginning of the line        (“^a.c.”, “abcd”) – true
                                                                                         (“^a”, “ac”) – false

xxx$   Matches regex xxx at the end of the line   (“..cd$”, “abcd”) – true(“a$”, “a”) – true
                                                                               (“a$”, “aca”) – false

[abc] Can match any of the letter a, b or c. [] are known as character classes.
                                                        (“^[abc]d.”, “ad9″) – true(“[ab].d$”, “bad”) – true
                                                        (“[ab]x”, “cx”) – false

[abc][12] Can match a, b or c followed by 1 or 2  
                                              (“[ab][12].”, “a2#”) – true(“[ab]..[12]“, “acd2″) – true
                                               (“[ab][12]“, “c2″) – false

[^abc] When ^ is the first character in [], it negates the pattern,
                                                                             matches anything except a, b or c
                                          (“[^ab][^12].”, “c3#”) – true(“[^ab]..[^12]“, “xcd3″) – true
                                          (“[^ab][^12]“, “c2″) – false

[a-e1-8] Matches ranges between a to e or 1 to 8
                                                           (“[a-e1-3].”, “d#”) – true(“[a-e1-3]“, “2″) – true
                                                           (“[a-e1-3]“, “f2″) – false

xx|yy  Matches regex xx or yy (“x.|y”, “xa”) – true(“x.|y”, “y”) – true
                                                      (“x.|y”, “yz”) – false


Wednesday, June 25, 2014

Java Interface OOP Concept

package java_mysql;

/**
 *
 * @author sakib
 */
public interface MySQL_Interface {
 
 
  public  String Insert_Store_Procedure(String Table_Fields,String Table_Name,String DB_Name);
 
  public  String Update_Store_Procedure(String Table_Fields,String Table_Name,String DB_Name);
 
  public  String Delete_Store_Procedure(int Table_Field,String Table_Name,String DB_Name);
 
  public  String Select_Store_Procedure(String Table_Fields,String Table_Name);
 
  public  String Create_Table(String Table_Fields,String Table_Name);
 
  public  String Insert_Trigger(String DB_Table_Fields,String Table_Name );
 
  public  String Update_Trigger(String DB_Table_Fields,String Trigger_Name );
 
  public  String Delete_Trigger(String DB_Table_Fields,String Trigger_Name );
 
   
}

Tuesday, June 10, 2014

Junit test for testing methods of Java

package junit_test;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Sakib
 */
public class UtilsTest {
 
    public UtilsTest() {
    }
 
    @BeforeClass
    public static void setUpClass() {
    }
 
    @AfterClass
    public static void tearDownClass() {
    }
 
    @Before
    public void setUp() {
    }
 
    @After
    public void tearDown() {
    }

        /**
     * Test of percentage calculate, of class Utils.
     */
    @Test
    public void testgetPercent() {
     
        double rate = 10;
        double amount = 500;
        double expResult = 50;
        double result = Utils.percentage(rate,amount);
        assertEquals(expResult, result,2);
          }
 
}
Result :Test Passed