Javascript for loop vs jQuery for each Web developers often come across looping through data at client side. People generally use native Javascript coding for loop, or jQuery for each. Javascript For Loop. Example var names= ["jkoder", "kumar", "temp"]; var i; var text=""; for (i = 0; i < cars.length; i++) { text += names[i] + ","; } document.write(text); Result-> ... Read More »
Detecting key press for input text and Detecting Enter key
Detecting keypress for input text and Detecting Enter key The order of events related to the keyup event: 1. keydown – The key is on its way down2. keypress – The key is pressed down3. keyup – The key is released The keyup event occurs when a keyboard key is released. The keyup() method triggers the keyup event, or attaches ... Read More »
Potential security hole- Final field containing a reference to a mutable object
Potential security hole- Final field containing a reference to a mutable object As a thumb rule, instance fields should never be public. If an instance field is non-final, or is a final reference to a mutable object, then by making the field public, we give up the ability to limit the values that can be stored in the field. So ... Read More »
Some useful JSP Expression Language hacks in JSP
Some useful JSP Expression Language hacks in JSP If you have JSTL in your classpath(by including JSTL.jar and standard.jar in your classpath), then you need to write below taglib directive so that you can use JSTL tags. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%/> 1. Redirecting to other resource in application where, hello.html is another resource. 2. Looping model data in JSP and ... Read More »
Some useful Regular Expression examples
Some useful Regular Expression examples Regular expression is a special sequence of characters that helps you match/find strings or sets of strings. Basically it defines a search pattern for strings. They can be used to search, edit, or manipulate text and data. The abbreviation for regular expression is regex Below are some useful regex patterns that can be used in ... Read More »
Consider implementating compareTo and equals method
Consider implementating compareTo and equals method Unlike the other methods the compareTo method is not declared in Object. Rather, it is the sole method in the Comparable interface. It is similar in character to Object’s equals method, except that it permits order comparisons in addition to simple equality comparisons, and it is generic. By implementing Comparable, a class indicates that ... Read More »
What is Quick sort and usage of Quick sort in JAVA Arrays.sort method
What is Quick sort and usage of Quick sort in JAVA Arrays.sort method As per JDK-8 Arrays.sort method uses Quick sort algorithm for sorting of data in ascending/descending order. So this post is for persons who wants to know, how does Quick sort works. In JAVA world quick sorting is used to sort an array. In our example we will ... Read More »
What is Merge sort and usage of Merge sort in JAVA Collections.sort method
What is Merge sort and usage of Merge sort in JAVA Collections.sort method Manipulating data in a faster and efficient way has always been the fantasy of every language and JAVA is no untouchable in this case. As per JDK-8 Collections.sort method uses Merge sort algorithm for sorting of data in ascending/descending order. So, what is Merge sort? Well, if ... Read More »
Which is better option: Java clone or Copy constructors or Copy static factory?
Which is better option: Java clone or Copy constructors or Copy static factory? The Cloneable interface was intended for objects to advertise that they permit cloning. Unfortunately it fails to serve this purpose. It’s primary flaw is that it lacks a clone method, and Object’s clone method is protected. So what does Cloneable do, given that it contains no methods? ... Read More »
Prevent Safari/any browser loading from cache when back button is clicked
Prevent Safari/any browser loading from cache when back button is clicked This problem is caused by back-forward cache. It saves complete state of page when user navigates away. When user navigates back with back button, page is loaded from cache very quickly. This is different from normal cache which only caches HTML code. This kind of situation arises mainly with ... Read More »
Jkoder.com Tutorials, Tips and interview questions for Java, J2EE, Android, Spring, Hibernate, Javascript and other languages for software developers