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

Implement Producer Consumer Problem Using Threading in Java

ProducerConsumer problem is also known as the bounded-buffer problem.It is multi-process synchronization problem.There are two processes one is producer and another is consumer that can share a common and fixed-size buffer. The producer insert th...

Implement Generic Method in Java

Generic Methods:- The Below code will helps you to implement Generic Method using the Generic Programming in Java. The generic methods enable us to specify, with a single method declaration and use with different data types. we can write a single...

How to Construct your own ArrayList Using Generics

Here the Below Example will show you how you can construct your own Collection(ArrayList) in Java. The below example will show you that our Class Generics will behave like the ArrayList. I have use the Generic Programming to Implement the concept...

Static in Java

One of the most important topic that we encounter in java. We can use static with class name, methods name, variables name and block. Static keyword mainly used for memory management. Static variable Static variable takes memory o...

Spring MVC @RequestParam Usses

For Get request we need to pass parameters as request param along with the url to get the data. In Spring MVC framework, we can customize the URL in order to get data. To read the parameters passed with the URl we use @RequestParam in Spring fram...

Spring MVC @RequestParam vs @PathVariable

@PathVariable: 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. @PathVariabl...

How to match a word in Java?

Sometimes we need to match some words in a particular String. We can do this easily by matches() method of String class. Example: package com.demo; public class TestApps { /* *@param args */ public static void mai...

How to replace whole word with Word Boundaries in Java?

Sometimes we need to replace whole word with the word boundaries in a string. For this we use "\b" regular expression token which is called a word boundary. It usually matches at the start or the end of a word. Example: You just need to place ...

How to replace Case-Insensitive chars in a String in Java?

Sometimes we need to replace some characters with some other set of characters. To replace a Case-Insensitive chars from string you can use the below example: package com.demo; public class TestApps { /* *@param args */ ...

Use of JPA(Java Persistence API) to implement ORM

JPA:- Java Persistence API is a collection of classes and methods to persist or store data into the database Using the JAVA API. The Below code will show you how you can work with JPA. First we make the POJO. Employee.java package...

HashSet in Java

Here I am writing a way to implement Hashset. HashSet creates hashtable to store the data. As it implements Set interface so it doesnt contains duplicate elements. It also extends AbstractSet class. We can implement HashSet by using different...

Enumeration Interface in Java

Enumeration is used to retrieve or traverse all the elements of particular collection of objects. Its not considered for collections but we can use it for legacy like Vectors. To use it we need to import - Java.util.Enumeration Below is the ...

Iterator in Java

In collection, there would be many situations where we need to retrieve the collection elements. Example, we need to show each element. For these situations Iterator is the best solution. How it implements :- First iterator comes to start p...

Java Interview Coding problems for Freshers- Part II

In the previous tutorial of Java Interview Questions and Answers Part 1, I have explained some basic coding problems of Java.This part is in continuation with the previous Java Interview Questions and Answers tutorial. In this part of the tutoria...

Map Interface in Java

We use Map Interface for mapping unique keys and values. By using these keys, we can retrieve the mapping values at any time. Map Interface has so many methods. Some of them are given below :- clear() : It clears all pairs from the given map....

double colon(::) operator in Java 8

In Java 8 we can also use double colon(::) as the method reference. By using double colon(::) operator we can easily convert normal method into lambda expression. The below example will show you how you will convert normal method into lambda ...

Java 8 Iterable.forEach() vs foreach loop

foreach loop In Jdk 1.5 generics concept can be introduced and do some enhancement in for loop and the enhanced for-loop is introduced. The enhanced for-loop is reduce the overhead to print the values of the arrays and collections because it w...

Java Interview Coding problems for Freshers- Part I

Hi, For all the final year graduates and freshers, I have got a series of java coding interview questions and answers, which is good to prepare before appearing on any Java interviews. Java coding questions are based on programming, logical an...

Image Crop Using Java and Jquery Crop (Jcrop)

FrontEnd: Include jquery.Jcrop.css, jquery.Jcrop.js and jquery.Jcrop.min.js Open an image in a div with a form. Take 4 hidden input fields: <input type="hidden" id="x" name="x" /> // x coordinate of the image <input type="hidde...

How to create Concatenate string in java

With the help of java, I have created concat() string method. In the example given below, I have used '+' operator , StringBuilder and StringBuffer Class to join string in java. The string concat() method combines specified string at the end of t...

Spring Security:RESTful Authentication via Spring

AuthenticationTokenProcessingFilter First we need to make security context where we define our Authentication Entry point and a filter for processing the token. Configuration xml will look something like this: <security:http realm="Authe...

How to split a String

Below I have written a code to split a string. Suppose we have a string name imagePath and we are going to split by "/" by using split method in java. String delimiter = "/"; String[] img; if (imagePath.contains("/")) { img = i...

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...

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...

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...

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...

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/...

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...

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 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...

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...

Read and Write JSON data in MySQL

Store JSON in MYSQL:- Here below snippet will show you how we can store json data in mysql and read the json data from mysql and convert into a java object. Remember that the field where you can store the JSON data in mysql to set data type of t...

Spring Security - UserDetailsService vs. AuthenticationProvider

We can use Custome UserDetailsService and custom AuthenticationProvider for user authentication in Spring Security. Here I'm taking example of custom UserDetailsService. UserDetailsService is a Core interface which loads user-specific data. I...

How to invalidate a spring security session?

To invalidate spring security session you need to follow below steps: 1. Add Logout configuration in your applicationContext-security.xml file Set logout-success-url attribute to /login.jsp. After logout user will be redirected to this pag...

Spring security 3: database authentication with hibernate

For authenticating the user via spring security we need to make our own custom authentication-provider. We can make our custom UserDetailService easily, here is the sample custom code MyUserDetailsService.java package com.users.serv...

How to delete file in Java

Hello readers, To Delete a File in Java is not a big issue, you don't need to do any rocket science for this. So if you want to delete the file in java here below is the method. To delete the file, you just have to issue the File.delete(...

Java 8- Method and Constructor References

Method Referencing Method reference is feature related to lambda expressions. Method references are more readable form of Lambda expressions for already written methods. :: operator is used to define method reference. It provides a way to a ...

How to iterate Object List in JavaScript

Sometimes we need to send data from Controller to JSp. Here I'm going to explain how we can send and iterate Object List in JSP file. You can do this easily by following the below steps: 1- Define the below dependency in you pom.xml file for...

Lambda expressions - Java 8

Lambdas? A lambda is nothing but a anonymous function which accepts zero or more arguments and produces output. Lambda is basically composed with three components- argument section, an arrow and a body. (argument ...) -> { body } // ...
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: