Posts

Showing posts with the label java

Regular Expression Powerfull sample in java

We can use regular expression and to do large set of works as simple and single line code . In this example i will show you how the regular expression play a vital stage . I want to read a file and insert a new line (\n) at every 100 th character in that file content and write those changes in another file. Normally what i did first is written a code to read file line by line and written a sample piece of code to read position and insert the new line in that particular position then written in new file. Instead for write separate function i write an replaceAll with regular expression. The sample code given below, package com.shinnedhawks; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class REPower {     public static void main(String[] args) {         new REPower().replace();   ...

Mostly occured Performance Issue in JAVA

Top 10 causes of performance issues in Java Cause #1 : The JVM spends  more time performing garbage collection  due to improper Garbage Collection (GC) configuration. E.g. Young generation being too small. Heap size is too small (use -Xmx). The application footprint is larger than the allocated heap size. Wrong use of libraries. For example, XML based report generation using DOM parser as opposed to StAX for large reports generated concurrently by multiple users.  Incorrectly creating and discarding objects without astutely reusing them with a flyweight design pattern or proper caching strategy. Other OS activities like swap space or networking activity during GC can make GC pauses last longer.  Any explicit  System.gc( )  from your application or third party modules. Run your JVM with GC options such as  -verbose:gc (print the GC logs)  -Xloggc: (comprehensive GC logging)  -XX:+PrintGCDetails (for more detailed output)...

Role based Spring security

If you need Spring jsp page authorization means follow the below steps, Step 1: Need to activate web authorization in web security file use-expressions="true" in http tag  in security xml file ex:  <http .... use-expressions="true"> then you configure pom.xml for download spring <dependency> <groupId> org.springframework.security </groupId> <artifactId> spring-security-taglibs </artifactId> <version> 3.2.5.RELEASE </version> </dependency> Step2. Then add the tag lib in your need jsp page Ex: <%@ taglib prefix = "security" uri = "http://www.springframework.org/security/tags" %> Step3: Then check the hasRole in jsp page Ex: <security:authorize access = "hasRole('ROLE_USER')" > This text is only visible to a user <br/> </security:authorize> <security:authorize access = "hasRole('ROLE_ADM...