Featured
-
How to split a String
Below I have written a code to split a string.
by shahbaz.ahmmod -
Send Push Notification with Custom Data to iPhone device from Java Server Side
This blog will help you to send Push Notifications
by babita.dhami -
Tomcat and Eclipse Integration Error : “Unknown version of Tomcat was specified”
If you are adding Server in Eclipse for Tomcat, an
by chandan.ahluwalia -
Spring MVC and MongoDB
Repository Class Using MongoDB : Spring has th
by sumit.vyas -
How to create DLL file from java?
Hello Guy's This Blog will guide how to create D
by bhagwan.khichar
Tags
Example of ServletContextListener Interface in Servlet
ServletContextListener Interface : In almost every web application there is a common scenario that application should need some pre-initialized data before starting the application. There are some actions which we need to perform before applicati...
How to implement validation for empty input field with jQuery?
Whenever we create a form, we always have a requirement to put validation for empty fields on some input fields. We usually implement this functionality by putting checks on "blur" and onFocus events of the input field.
Example: In the below e...
How to apply validation on checkbox with jQuery?
Sometimes we need to check whether a checkbox is checked or not. We can do this easily by using "checked" attribute of a checkbox.
Example: In the below I have created a function validateCheckBox() that checks whether a checkbox is checked or ...
Scripting Elements in JSP
Scripting Elements : In JSP every scripting element is written inside the <% %> tags. At the translation phase JSP engine reads the code inside the <% %> tags and processed it. In a JSP file outside this <% %> tag all code is t...
Example of HttpServletRequestWrapper class in Servlet
HttpServletRequestWrapper Class : In JavaEE everything is in the form of request and response. User sends the request and server do the response. Now the question is what if we want to change the request data or wanna override the default request...
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...
How to install open JDK on Ubuntu ?
You have to follow below Steps to install JDK (java developement kit) on Ubuntu
Step 1: Installation of JDK
sudo apt-get install openjdk-7-jdk
Step 2: After the installation, Use command.
apt-cache search jdk
Step 3: Settin...
How to implemente confirm password functionality with jQuery?
At the time of registration or change password we need to provide password, so for this we usually implement Confirm password functionality.
Example: In the below example I want to confirm password on form submit, so for this I have created a ...
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 ArrayList and Vector
Hi,
It is one of the important topics in java.
For dynamically resizable array we use ArrayList. ArrayList provides us fast access as compare to simple
array.
1. As we go to synchronization, Vector is synchronized means at a single time o...
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 select option of drop down with Jquery?
Sometimes we need select option of a drop-down dynamically by clicking on a button or on some other action. We can do this by using "selected" property.
Example- In the below example I have a drop-down for distance and I want to select option ...
How to appned li elements to ul dynamically with jQuery?
Sometimes we need to add li elements to ul dynamically based on some list. We can do this by using append() method.
Example- In the below example I have a list "users" and I want to display user names dynamically on page.
<html>
...
How to show div after some time period with jQuery?
Sometimes we need to display some alert or dive after some period on Web page.
We can do this by using setTimeout method as below:
<html>
<head>
<title>Demo to show div</title>
<script type="...
How to hide a message after some time interval with jQuery?
Whenever we submit a form or do some task, we usually display a success message, but sometimes it is required to hide this message automatically after some time period.
We can do this by two ways:
By using setTimeout method:
...
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 enable/disable a button with jQuery?
Sometimes we need to enable/disable a button based on some condition. We can do this easily by using "disable" attribute of a button.
Example:
<button type="button" id="voteButton">vote</button>
To disable a button write t...
How to refresh a function after a particular time in jsp?
To refresh a function after a particular time interval to refresh the values on the page.
We can do this by using setInterval() function on page load.
Write the below code where refresh() function will be the function that you want to refresh...
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 focus a text box on button click in jQuery?
Sometimes we need to focus a textbox on button click based on some condition. We can do this by using focus().
Example- Suppose I want to focus search-box on button click if the search-box is empty, then we can do this as below:
<input i...
How to Call Stored Procedure using Entity Manager in JPA
Call stored procedure in JPA : Here I am going to tell you that how you can call the stored procedure using JPA entity manager. Following is the example to call stored procedure using entity manger.
Suppose we have a stored procedure called 'g...
Send simple text mails using JavaMail API
You can build build mail and messaging applications with the help of JavaMail API, which gives you access to a platform-independent and protocol-independent framework. You can use the JavaMail API as an ...
how to identify location is enable or not on browser with jQuery?
To get the user's current location use the getCurrentPosition() method. This method contains two parameters, first parameter is success for providing locationd and second one is error to handle errors for ex: getCurrentPosition(success,error)
...
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 get browser current timezone with jQuery?
Sometimes we need to identify the clients timezone to make some calculation on time. For example - we want to save current time based on user's timezone into database, so in this case we need to get the user's current timezone.
To do this down...
How to detect if enter key is pressed with jQuery or not?
Sometimes we need to detect where ENTER key is pressed or not to do some action.
The "enter" key is represent by code 13 (ASCII value).
To detect whether ENTER key is pressed on Web-page or inside an input field, we can bind keypress() eve...
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 ...
Object Relational Mapping(ORM)
if we want to access and manipulate objects without considering much about its data resources, we use ORM. ORM allows programmers to maintain a consistent view of objects over time.Mapping details between a set of objects is managed by ORM.
OR...
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...
Exception Handling In Java
Exceptions are the abnormal conditions which generated at the time any runtime error occurred.
To handle these exception is known as exception handling. The exception handling is done to maintain the normal flow of the program. In java there are...
isNaN() And isInfinite() in Java
isNaN() and isInfinite() methods in Java are the member functions of the java.lang.Double and java.lang.Float classes. Both the functions here are static member functions of the classes.
NaN here stands for the Not-a-Number, it specifies wheth...
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...
Add image in panel using swings
Hi All,
To add image as background image in JPanel ,JLabel is used for example:-
setLayout(new BorderLayout());
try {
image = ImageIO.read(new File("D:\\New folder (2)\\fish.jpg"));
...
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
{
...
Java Interview Coding problems for Freshers- Part III
In the previous part, Java Interview Questions and Answers Part I and Java Interview Coding problems for Freshers- Part II, we have explained some basic questions of Java. This part is in continuation with the previous Java Interview Questions an...
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 sort alphanumeric string in JSONArray
Hello Guys
Here, I write blog for sort JSONArray using alphanumeric string.
Create JSONArray below :
JSONObject jsonObjupdate = JSONFactoryUtil.createJSONObject();
JSONArray jsonArrayupdate=JSONFactoryUtil.createJSO...
Java Development Environment Installation
Java Is a platform Independent Language, but the JDK Java Development Kit is used to developed wide range of applications. Java Development Kit includes some other like JRE and JVM for the complete development.
JRE Java Runtime Environment as a...
What is Enum type in Java
Enum type is a keyword which is used to represent similar kind of constants or fixed no of elements under one group only. The constants here may be static or final. In java the common use of the Enum keyword is to write Singleton. Enum as a type ...
Difference between java and c++
JAVA
1) Java is completely an object oriented language.
2) Java does not have template classes.
3) Java supports multiple inheritance by the use of interface.
4) Java does not support concept of pointers.
5) java does not have header files
...
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...