Wednesday, 19 April 2017

svn: E200030: There are unfinished transactions detected in project


When you try to commit some file to SVN, you may have encountered this error,
"svn: E200030: There are unfinished transactions detected in project".

Solution to this problem:

  • Right Click on Project-->Team--->CleanUP or
  • Open CommandLine,Goto Project Directory ,run svn cleanup command.
  • Restart the eclipse.

Happy Learning.

Tuesday, 4 April 2017

Java Program to remove duplicates character from String


Sample Program:
 import java.util.LinkedHashSet;  
 import java.util.Set;  
 public class RemoveStringsDuplicates {  
      public static void main(String[] args) {  
           String string = "abcdanbcd";  
           // Convert String into char array.  
           char[] chars = string.toCharArray();  
           // Set is used to remove duplicates.  
           Set<Character> charSet = new LinkedHashSet<Character>();  
           for (char c : chars) {  
             charSet.add(c);  
           }  
           StringBuilder result = new StringBuilder(charSet.size());  
           for (Character character : charSet) {  
                result.append(character);  
           }  
           System.out.println(result.toString());  
      }  
 }  

Output:
 abcdn  

Enjoy Learning.

Convert Date Object into String Object



Sometimes we have a requirement where we need to convert the date object received from input into String object.

Sample Program:


 import java.text.DateFormat;  
 import java.text.SimpleDateFormat;  
 import java.util.Date;  
 public class ConvertDateToStringExample {  
      public static void main(String[] args) {  
           Date date=new Date();  
           DateFormat dateFormatter=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
           String strDate=dateFormatter.format(date);  
           System.out.println("Converted Date:" +strDate);  
      }  
 }  

Output:


Converted Date:2017-04-04 08:57:44  


Enjoy Coding.

Program to check if String contains only digits


Sample Program:


 public class CheckDigitString {  
      public static void main(String[] args) {  
           String str1="abcd";  
           String str2="abc1d";  
           String str3="11234567";  
           //provide regex pattern for digits  
           System.out.println(" String str1 :"+str1.matches("[0-9]+"));  
           System.out.println(" String str2 :"+str2.matches("[0-9]+"));  
           System.out.println(" String str3 :"+str3.matches("[0-9]+"));  
      }  
 }  

Output:


  String str1 :false  
  String str2 :false  
  String str3 :true  

Enjoy Learning.

Friday, 31 March 2017

Wildfly 8.2 Heap Issue


In Wildfly 8.2, We face out of memory error due to Heap memory gets filled.

Following configuration needs to be added in order to avoid heap issue:

Java 8 does not support Perm gen settings.Instead we need to specify MaxMetaspaceSize.

In order to run MaxMetaspaceSize,Make sure JAVA_HOME is set to JDK 1.8.

JAVA_OPTS="$JAVA_OPTS -XX:MaxMetaspaceSize=256M"

Also The memory leak work around needs to be added.

# Memory Leak issues
JAVA_OPTS="$JAVA_OPTS -Djboss.remoting.pooled-buffers=false"


Happy Learning.

Tuesday, 21 March 2017

Find longest sequence of zeros in binary representation of an integer


 A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.

For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps.

Write a function:

int solution(int N);

that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.

For example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5.

Solution:


 public class Test {  
      private static long maxConsecutiveZeroes(int x) {  
           boolean flagOne = false;  
           long count = 0, max = 0;  
           //Loop until x becomes 0.  
           while (x != 0) {  
                if ((x & 1) == 1) {  
                     flagOne = true;  
                     if (count > max) {  
                          max = count;  
                     }  
                     count = 0;  
                } else if (flagOne) {  
                     count += 1;  
                } else {  
                     count += 1;  
                }  
                x = x >> 1;//Move ht binary digits to right side bit by bit.  
           }  
           return max;  
      }  
      public static void main(String strings[]) {  
           System.out.println(maxConsecutiveZeroes(16));  
           System.out.println(maxConsecutiveZeroes(9));  
           System.out.println(maxConsecutiveZeroes(14));  
           System.out.println(maxConsecutiveZeroes(222));  
           System.out.println(maxConsecutiveZeroes(3));  
           System.out.println(maxConsecutiveZeroes(4));  
           System.out.println(maxConsecutiveZeroes(1041));  
      }  
 }  

Output:


 4  
 2  
 1  
 1  
 0  
 2  
 5  

Enjoy Coding.

CheckMarx Secure Code Analyzer


  1. Login into CheckMarx using your Credentials.
  2. Go to Projects & Scans and select " Create New Project ".



  3. After select, you need to give project name, Select Preset in the field (General Tab). As shown below.
    Example :- Project Name : Universal Payment
                      Preset : APPSEC-Java-JS



  4. Click on Next. you can see Location tab, Click Source Control then click on Select button. new window will popup in there you need to select folder for Source Control i.e. SVN, GIT etc. 
  5. In Port number by default 8080 will show, we need to change 8080 to 443.
  6. Select " Required Authentication " , Enter your User Name and Password (Enterprise ID and Password). and Click on OK.



  7. After Clicking OK you can see another window where you need to select " Root " folder of Project and Click on OK.


  8. After Clicking OK, you can see Source Control got selected, Then click on Next.


  9. In next Scheduling tab select " None " and click on Next.


  10. Next in Advanced Actions tab Enter email to Example : your_email Id and select run post scan action (New_Eport_Script: PrepareAgregatedResult4Splunk.bat [XML_output]). and click on Next.


  11. In next Custom Fields Tab, select Next, and in Data Retention tab select Finish button. you can see Project got Added.


  12. Click on Full scan. it will take time to scan Project.


  13. After completed scan, click on View Project Scan.


  14. After Clicking view project scan, you can see below window. click on Create Report.


  15. After Clicking create report you can see popup window. in there form Report Format select format which is you wants to be created Example : PDF, CSV etc. and click on Generate Report Button.


  16. After Clicking Generate report it will take some time to get generate the report and will download in your local machine (Download folder).

Enjoy Learning.