Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

Extract metadata using ImageIO in java

Hello guys We are creating a file which have some information about file i.e create date, modify date, tags and description etc. called metadata of the file. Now, We are extract the Imagedata using javax.imageIO package requires Imag...

How to compare strings in Java

There are two ways of comparison in Java. In you just want to match value of the string Object.equals() will be used. It simply compares the string values. While if you use == to compare, it will check the object reference. So new S...

Prevent site from showing up in search results on Google, Bing and other search engines

Sometimes we need to prevent our testing.dev site from showing up in search results on Google, Bing and other search engines until we are ready to launch. We can do this by addting "X-Robots-Tag" paramet to header of the response. Create filte...

How to implement select event of Autocomplete feature in jsp?

Sometimes we need do functionality when we select any item from the suggestions that display by autocomplte feature. Example: In the below example I'm using autocomplete() function to get suggestions with the provided keyword. As below by impl...

How to implement autocomplete feature with AJAX in jsp?

Sometimes wee need to call an API or action to get matching list with the provide keyword in Search box, for this we usually implemente autocomplete feature to input field for searching purpose by doing AJAX call. Example: In the below example...

How to check a particular date is within past 24 hours or not?

Sometimes we need to check whether a date is within past 24 hours or not. Generally we implement this kind of functionality when we create an AuthToken or a code that we want to to be valid for some time duration. Example: In the below example...

Find Number of days between two given dates

Here, I am writing simple method to find out the number of days between two dates. In many situations, we need to calculate it. So just pass two dates as parameters of the method and get the number of days in long data type. publ...

Adding Component Dynamically In Swings

Hi All, If you are adding JButton ,JLabel or JComboBox etc dynamically or adding them during runtime For example public class Main { public JPanel buttonPanel ; public static void main(String[] args) { JFrame frame = new J...

Difference between HashSet and TreeSet

Hi, I am explaining the difference between HashSet and TreeSet in Java. First of all they both come from the same family. They implement the Set Interface. In HashSet, values store in random order. That means it is not sure that the ele...

How to add/remove class to an element on keyup event with jQuery?

We can add or remove a class to an element very easily by using addClass() and removeClass() methods. To do this on keyup event of a textbox we just need call these functions when we bind keyup event to textbox. Example: <input id="sear...

How to refresh a web page after a particular time?

Sometimes we need to refresh web page after a particular time interval to refresh the content present on that page. So we can do this easily by writing the meta tag in the page source code: <meta http-equiv="refresh" content="60"/> ...

How to resolve problems with Request parameters encoding?

When we type any Accented char(not all) in input field and try to submit it gets encoded to some other chars automatically. To resolve this we need to enable CharacterEncoding. Follow the below steps in order to resolve problems with Request ...

How to put if/else condition in JSTL?

Sometimes we need to show HTML based on some conditions, so for this we use JSTl in JSP file. Example: In the below code I'm changinf heading based on condition. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <h...

How to apply conditional operators in JSTL?

In JSP file sometimes we need to put conditional operators through JSTL. Example: In the below example I am applying && and || operators. <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <html> <head&g...

How to find the size of a file while uploading in JSP?

Sometimes we need to find the size of a file at the time of uploading to prevent the file that is greater than a particular size. We can achieve this by handling "change" event of a input-file. Examlpe: Suppose I want to upload a file less tha...

How to find the extension of a file to be uploaded in JSP?

Sometimes we need to find the extension (file-type) of a file at the time of uploading to apply some validation on it. We can do this by handling "change" event of input-file. Example: In the below example I want to upload the file having exte...

How to change the context root of dynamic web application in eclipse?

To change the default url of the dynamic web project, say, the default url of a project is http://localhost:8080/DemoApp through which we can access the project using brower but we need a url like http://localhost:8080/xyz, then there is need ...

Add any character to String on a particular location

Sometimes, we need to change some special character on String to fulfill our requirements. For example, we need to show phone number, i.e, 2001256443 as (200)-125-6443 Now we use the substring method of String to solve it. We just add Stri...

How to read properties from property file in jsp?

Create a property file in the package with extension '.properties' and use those properties defined in the file in jsp by importing the resource bundle package in the jsp. Example: config.properties name=tom email=tom@gmail.com phone...

if-else in jstl

In JSTL, the functionality if-else is provided by choose-when-otherwise statement . <c:choose> tag is an enclosing tag for <c:when> and <c:otherwise>. And it is also known as mutual exclusion as only a block of code withi...

Send data through ajax call and receive Json response from controller in Springs

Here is the sample code implementing ajax call to send the data of a form to the controller and receiving json response from controller. Student.java Create a java bean class and generate setter and getter. public class Student { ...

Spring Security 4: Auto login with annotation

Spring security gives us the feature to auto login into the system just after creating an account. Other way is to register then go to login page, and then login to the system. When we login login mechanism spring automatically creates the sess...

Remove some particular character from a String

Sometime, we need to remove or replace some particular character from a String. Below is the method by which we can accomplish this. I am using replaceAll() method of the String. replaceAll() have two parameter as an arguments. First one is t...

Sort alphanumeric string with awareness of number using Java comparator

The java by default sorting is based on either number or string. If we try to sort a alphaneumeric it will be treated as an string so the sorting will come something like: 1abc 11abc 2abc instead of 1abc 2abc 11abc So in such cases w...

How to reset ArrayList in Java - Clear vs RemoveAll

To reset ArrayList we have two options, one is to use clear() method and another is to use removeAll(). We dont need to worry if size of the ArrayList is small i.e. 10 to 100. But if ArrayList size becomes huge the difference in the performan...

Convert Map to List

Map and List are the two commonly used data structures Here I am writing way to convert Map to List. Basically Map holds two things are key and value on the other hand list holds only values. Both Map and List allow duplicate data. Below i...

Threads

Threads Threads are used to get the multiple activities in a single process. They are light weight programs. They share memory and files and process state. They have their own local variable and stack and program counter. Every jav...

Static Keyword

Static Keyword Static keyword can be applied on 1.Method 2.Variable 3.Class nested within another Class 4.Initialization Block Static keyword can not be applied to 1.Class (Not Nested) 2.Constructor 3.Interface 4.Met...

Convert String to Date in Java

Its very easy in java to convert String to Date. Java provides SimpleDateFormat to handle Date related functionality. Here we call parse() method of SimpleDateFormat. Example import java.text.SimpleDateFormat; import java.util.Date;...

Phone number Regex Java

Regex for mobile number validation with prefix of '+' ^[+][0-9]{12,13}$ Regex for mobile number validation with optional '+' ^[+]?[0-9]{10,13}$ Use in Code:- Pattern.matches("^[+][0-9]{12,13}$",mobilenumber); Ha...

Constructor in Java

Java Class Constructor It is special kind of function, but doesn't have a return type. It has the same name as class name. Constructor is used to initialized the variable of class. we can't call the constructor with the help of object. If...

Get Current Date in Java

Hello, We need current date in many situations. Here I am writing different ways to get current date in java. 1. Get current date using java.util.Date. Date currentDate = Date(); System.out.println(Current date : +currentDate); O/P: Curr...

Covariant Return Type

When return type of the method of super class is different than the return type of method of subclass and it is also a method overriding then it is known as covariant return type. And here the return type is non primitive. I am writing the si...

Access Denied in spring security 4 even after successful authentication

In spring security after successfull authentication I was getting the Access denied error to go to pages which had the authentication. What I did was. @Override protected void configure(HttpSecurity http) throws Exception { ht...

How to add multiple properties file in spring configuration

Here we have configured the spring mvc configuration. In @ComponentScan we can give the path where we have our components(like controller, model, dao etc). For adding the single properties file we use: @PropertySource("classpath:application.p...

How to disable csrf spring security 4

In spring security bydefault the csrf protect in on. As a result it asks for token during login and other requests. Although its not a good practise to disable the protection but we can do it. As we can see in the code below, http.csrf().disable...

How to authenticate MD5 password encyption in spring security 4

Whenever we deal with password in an application, we go for some encryption. In spring the password it authenticated within the configuration. Here is the sample code where we have already saved the password in encrypted form and now during lo...

Encapsulation

Encapsulation is a concept of wrapping up of data into a single unit and hiding implementation details from the user. If we use the private method then they can not be accessed in the other class. If we put a getter setter method to update ...

Final Keyword

Final is keyword that can be used before a class or method or a variable. Final Class They can not be subclassed and the method in it are by default final. public final class MyFinalClass {...} public class ThisIsWrong extends MyFinal...

Access Modifiers

Access modifiers in java are used to control the access of other classes to access the class or method. There are different type of access modifiers used 1.Public-It is the default access modifier it means that your class or method is visib...

Interface vs Abstract Class

Interface Interface can extend many interface. Interface can extend from a interface only. Interface have only abstract method by default. Interface can have public method only it it. Abstract Abstract can attend only on class at a time. ...

Abstract Class

Abstract class are simply the base class. They can not be instantiated but can be subclassed and have protected, private method unlike the interface. Abstract classes can be declared by simply using the keyword abstract. abstract class Graphi...

Interface

Interface is the way to get the multiple inheritance. This means that a class can inherit two or more class. As java, we can not extend more than one class but we can extend more than one interface. So Interface is used to have inheritance Bu...

Inheritance

Inheritance in java is concept by which one class can have the method of the other class. The class that is being inherited is called Base or Parent class and the one which derive is called the Derive or child class. Inheritance can be of the t...

Method Overriding

Method Overriding is a type of polymorphism. It is dynamic type of polymorphism. In this we have the method with the similar name in both parent class and child class. But the child class override the method of the parent class when we create ...

Method Overloading

Method Overloading is a type of polymorphism. Using this we can have two different method having the same name in a single class. Method have the same name but different argument through which they are recognize. Argument have 1.Different num...

HttpSessionAttributeListeners in Servlet

In Servlet we can also track the events using the Listeners, In below code script we have to track the events using the listeners. we have easily maintained the HttpSession events with the HttpSessionAttributeListener while we add, remove or repl...

Stack in java

In stack, we save elements in last-in, first-out manner. Stack extends the Vector class and have only one constructor that is default. By this default constructor, we can create an empty stack. Below is the example. public class Exampl...

SortedSet in Java

I am writing a way to implement SortedSet in java. SortedSet have the properties of Set interface plus feature of sorting in ascending order. It is by default provides elements in ascending order. It is very useful in such situation when we do...

LinkedList implementation in Java

Hi friends, Here I am writing a way to implement basic LinkedList. First of all LinkedList has the properties of List interface and AbstractSequentialList class because it implements List interface and extends AbstractSequentialList. ...
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: