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
Why we Use Log4j in Java Projects?
Log4j in Java
Log4j is a logging tool made only for Java
Generally we Use System. Out console to print our Output, but they are all temporary messages and whenever new program run or when console is closed, our Output messages automatically...
Reading and injecting properties into spring from property file
We can read and inject the property from property file in spring. The below code will show you how you can read the property from property file and inject that properties to the List Object by using spring-config.xml file.
Customer.java
pac...
Injecting Property Object in Spring
Here the below code will show you how to inject the Properties in Spring using the spring.xml file. By using that we will inject the Properties Class object in spring.
Customer.java
package com.evon;
import java.util.Properties;
public...
Injecting Set in Spring
Here the below code will show you how to inject the Set in Spring using the spring.xml file. By using that we will inject the Set object in spring.
Person.java
package com.evon;
public class Person {
String name;
String addr...
Injecting Map in Spring
Here the below code will show you how to inject the Map in Spring using the spring.xml file. By using that we will inject the Map object in spring. -
Person.java
package com.evon;
public class Person {
String name;
String add...
Injecting List Bean in Spring
Here the below code will show you how to inject the List in Spring using the spring.xml file. By using that we will inject the list object in spring.
Person.java
package com.evon;
public class Person {
String name;
String ad...
Java Mail API : Sending Simple Mail
Java MAil API composed of classes and some Interfaces which is used to send(compose) , read(fetch) and delete e-mail messages
Sending Simple Text Mail:
To send a simple Text Mail you can follow the following steps:
1. Get a Session obje...
Difference between overloading and overriding in JAVA
Hi,
Difference between overloading and overriding in java is a repeatedly asked and very important interview question. So, you can find the details over here.
Method overloading in JAVA is used to increase readability of program while met...
Versioning of An Object in Hibernate
As we know that the Hibernate API provide us to save, retrieve, update and delete data features, but it's not just that it provides more than that. In traditional database programming what we do to check the data is being modified, answer is that...
Send Push Notification with Custom Data to iPhone device from Java Server Side
This blog will help you to send Push Notifications with Custom data to iPhone devices from server side where server side code is written in Java.
Follow the below code in order to send Push Notification:
Define the below dependency in your...
Difference between update() and merge() in Hibernate
Difference between update() and merge() method :
Hibernate has different methods to save, fetch, update and delete object. Commonly or the most popular methods to update the data are update() and merge(). The update() method is widely used to ...
JSP Life Cycle
JSP is a server side scripting language. JSP is used to develop web applications. We can do everything on JSP which we can do with Servlet. In JSP we can add the Java code inside the HTML tags.
There are three service methods provide...
Java connectivity JDBC driver
Hi Friends,
This article will help you to identify basic connectivity using JDBC driver in Java. There are only four categories of JDBC driver provided by SUN, Type 1, 2, 3, and 4, which is explained below
Type 1: JDBC-ODBC (Bridge Dri...
Difference between autowire byName and byType in Spring
Spring framework provides the way to inject the bean dependencies using the autowire functionality. By default autowire functionality is disabled in spring framework. A developer explicitly define the autowiring configuration in spring configurat...
Java Thread Join Example
join() method in Java Thread : The join() method of a Thread class allows the current thread to wait until the thread in which it is called will die. Sometime a question is asked in the interviews that How can we make sure main() is the last thre...
Difference between get() and load() methods in Hibernate
What is the difference between get() and load():
The most important question for the interview's perspectives that what is the difference between get and load methods in Hibernate? Developers use both the functions when coding but most of them u...
Java Thread Example
Thread: Thread is a lightweight process. Thread requires less memory space and resources to create and exists in the process, thread shares data and resources of the process.
Every Java application has at least one Thread (main thread). There ...
Thread States and Lifecycle in Java
Thread Lifecycle:
Want to start the multithreaded programming? Before starting you need to know what is Thread and what is the life cycle of the Thread. Thread having different states and life cycle methods. To know about the thread you can Visi...
Java with MongoDB
Java with MongoDB:- The MongoDB is the Document type Database. It is set of Collections and documents. it supports the NOSQL and to manage the collections inside the collection there are numbers of documents. The Below code will show you how to c...
Difference between user and daemon thread in Java
Difference between user thread and daemon thread:
When we talk about multi-threaded programming then we talked about threads. And when we talk about threads, then the question comes the types of threads. So guys we mostly work on user thre...
Spring OXM with XStream API
Spring with XStream : XStream is a simple library to serialize the Java object to the XML document and vice versa.We can use Spring OXM with XStream library for XML binding. The benefit of the XStream library over Castor is that XStream does not ...
Difference between save() and persist() methods
Difference between save() and persist() methods in hibernate: Using Hibernate framework to save object we mostly use two methods save() and persist(). Both methods fulfill the same purpose.
What is the difference between save() and persist() me...
Difference between Process and Thread in Java
Difference between Process and Thread : A process is an executing instance of an application, it can be seen as a program or application. It has it's own memory space and resources. A thread is a lightweight process, it can be seen as a part of a...
Pretty Print JSON Output in Jackson
**How to convert Java object to Pretty Print JSON :** Converting Java object to JSON is a little complex work in Java. We can use the third party api to make this easy.
Jackson is one of the most popular api for JAVA JSON processing. Jackson ap...
How to generate ppk file from pem file in Ubuntu?
To generate ppk file from pem file in Ubuntu you just need to write below command in the terminal:
puttygen pem-filel.pem -o ppkfilename.ppk -O private
For example:
puttygen /home/ubuntu/jeeyoh-site.pem -o jeeyoh.ppk -O private
Ho...
Sample application using JQuery, Spring MVC @RequestBody and JSON together
See the below steps to create sample application using JQuery, Spring MVC @RequestBody and JSON :
1- Define dependency for Spring, JSON in pom.xml as below:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/...
Converting JSON to Map Object
How to convert JSON to a Map object: Most of the time we have to communicate with other applications using the web services, and web services basically uses two ways to communicate with application one is using xml file and other is json.
So th...
Jackson Tree Model (Traversing json tree with Jackson)
How to traverse JSON object using Jackson api: Jackson api is used to read, write and update the Json object. We can traverse the JSON object using the Jackson api. Jackson provides the Tree model to traverse the JSON document, so we can traverse...
Converting Java Object to JSON
How to convert Java object to JSON : Converting Java object to JSON is a little complicated work in Java. We can use the third party api to make this easy.
Jackson is one of the most popular api for JAVA JSON processing. Jackson api is fast, co...
Spring MVC: Difference between context:annotation-config and context:component-scan
Difference between <context:annotation-config/> vs <context:component-scan/>:
<context:annotation-config/> : <context:annotation-config/> is used to activate all the annotations that are present in java beans and thos...
How to generate random number in Java?
Sometimes we need to generate random numbers to identify an entity uniquely.
We can generate random number very easily by the below code:
/**
*
* @return a random confirmation code.
*/
public int generateIntRandomNumber()
{
Ra...
Using @PreAuthorize on Spring controllers methods
Authenticate controller method using @PreAuthorize annotation : @PreAuthorize annotation is used to provide the method level security. We can secure our methods by using @PreAuthorize annotation. It is very easy to use and it is always preferred ...
Difference between @Secured and @PreAuthorize
@Secured vs @PreAuthorize : Spring Framework provides the different ways to secure the application. Spring Framework has lots of handy tools or methods to secure application. @Secured and @PreAuthorize are the two most popular annotations used to...
Spring MVC @PathVariable Uses
Sometimes we need to pass parameters along with the url to get the data. In Spring MVC framework, we can customize the URL in order to get data. For this purpose @PathVariable annotation is used in Spring framework.
For example you want to wr...
Spring with JSF integaration
JavaServer Faces (JSF):- JSF is an MVC web framework which focus on or we can say that it's objective is to built user interfaces for Java web application similar to the JSP(Java Server Pages). The JSF comes with 100+ ready UI tags to build the U...
Spring @Transactional Annotation
@Transactional Annotation in Spring:- A transaction is unit of work that have ACID (atomicity, consistency, isolation and durability) properties.
Atomicity:- this means that the changes will completely happens or not. for example If money is ...
Spring MVC 3 and handling static content - am I missing something?
We can handle static content for example: js,css,images in Spring MVC by using mvc:resources element. mvc:resources element is used to point to the location of static content with a specific public URL pattern.
For example define the bel...
Difference between WebApplicationContext and ApplicationContext in SpringsMVC
Well, when we start off with SpringMVC first of all we have Dependency Injection in mind and then comes ApplicationContext but when we dig deep we get stuck with a lot of issues one of which is Difference between ApplicationContext and WebApplica...
How to get date of past days in java?
To get the date of the past day you can use the below code. You can pass any number of day for which you want to get date instead of 7, I'm getting date of past 7 days in the below example:
/**
* Get date before past 7 days
*
* @return...
How to convert Model Object into JSON string and JSON string into Model Object in Java?
Sometimes we need to get JSON string direct from Model object and to read JSON values from Model object. We can do this functionality very easily by using Jackson Mapper.
Follow to steps in order to do conversion from Model Object to JSON stri...
How to get current date with start time and end time?
Sometimes we need to get current date but we need to get time with date that starts from 12 O'clock morning and sometimes ends with 12 O'clock night.
To achieve this use the below code:
1- Write the below code to set time fields to start
...
Spring MVC : How to perform validation?
Here I'm giving the example of validating form fields in a Spring Web MVC application using Bean Validation API. We'll develop a login form in Spring MVC in which we'll apply validation constraints on two fields email and password.
We use the ...
Variables in JAVA
Variable is a name. Variable name reserved an area which is allocated in memory.
In java each and every variable has some specific type, this specific type defines the size in variable's memory.
One should declare variables before used.
Eg. ...
Spring Security: Obtaining current username (i.e. SecurityContext) information in a bean?
Instead of calling static method inside the controller like below:
@RequestMapping(value="/welcome", method = RequestMethod.GET)
public String getUserDetails(ModelMap model) {
Authentication authentication = SecurityContextHolder.getCont...
Sprint Security: Getting Active user's UserDetails
We can easily get active user's UserDetails in Spring Security. Spring Security provides "org.springframework.security.core.Authentication" which provides the required API for retrieving the logged in user details. The methods of this class are g...
Spring MVC @PathVariable getting truncated
We generally face a problem when we hit server with path variable that contains special character like dot(.) it gets truncated.
For Example: If you have the mapping
@RequestMapping(value = "/findMe/{emailId}", method = RequestMethod.GET)
...
What's the difference between @Component, @Repository, @Controller & @Service annotations in Spring?
When we define the annotations @Component, @Service, @Controller, @Repository with the classes, Spring automatically scan and identifies those classes and register the Bean definition with the ApplicationContext.
Difference between @Component...
What is @ModelAttribute in Spring MVC?
@ModelAttribute implies to a property of the Model object in Spring MVC. This annotation workes only if your calss is Controller class i.e. declares with @Controller annotation.
It is also used to define the command object that we declared by ...
Spring 3 MVC accessing HttpRequest from controller
Spring 3 MVC accessing HttpRequest from controller
To access HttpRequest from controller you just need to define HttpServletRequest and HttpServletResponse as parameters in a function signature of your Controller. by doing this you allowing Sp...
How to rotate image in java?
Here I have illustrated how to rotate image using java code.
Impot imgscalr-lib-4.2.jar for Scalr class to rotated image on various angles.
Below code will rotated image on 90 degree angle.
File file= new File("file-path");
BufferedI...