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

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

Creating a struts action in Liferay

We can create custom Struts action in Liferay by using Hooks, these type of Hook is called as Liferay Struts Action Hook. Follow the below steps to create a Struts Action: Create Liferay Plugin Project of type Hook. Write the below cod...

Auto completion not working in eclipse

Eclipse has a behavior to suggest the list of methods that can be used with the class name or the instance variable of any class. This behavior works fine for few of the Java classes but for some other classes like DesiredCapabilities,etc., eclip...

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

Email validation using regex

Email validation using regex The Email Id such as adam.sandler@findnerd.com is made up of local-part, an @ symbol and then a domain part. Hence, Email Id is of the form : local_part@domain *TLD = Top Level Domain Some Valid Emails ...

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

Install Oracle JDK with apt-get

The official JDK is provided by Oracle but is not provided as default installation by ubuntu You can install Oracle JDK using apt-get by adding the repositories and then using apt-get command. To add the repository issue the following comm...

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

How to take Backup of MYSQL Database file and upload it on Dropbox Account?

Hello, I am sharing here how we can take backup of our Project mysql database file and upload it in our Dropbox Account. Advantage using this feature is we can store our database backup in our Dropbox account daily. We can set our script as a...

Web applications with AnnotationConfigWebApplicationContext

Web applications with AnnotationConfigWebApplicationContext: In Spring we can use the WebApplicationInitializer in place of web.xml to initialize DispatcherServlet and use @EnableWebMvc annotation to support Spring MVC.The below example code can ...

Using context:component-scan to pick up @Configuration Classes

In Spring 3.0 using the tag context:component-scan in xml file, the entry of the class(or bean) defined under the scan tag is automatically created. The example to show use of context:component-scan tag is as below: Example:- JavaConfig.jav...

Instantiating the Spring container using AnnotationConfigApplicationContext

In Spring 3 we can also create a bean using java file instead of XML.It is alternate way to create the bean, you can also use xml based configuration. HelloWorld.java package com.babita; public class HelloWorld { public void p...

How to achieve Document Version Contorl in Liferay?

Liferay provides very rich environment to create versions for the Uploaded documents. You can achieve Document Version Control very easily in Liferay by using the below code. Create the object of ServiceContext as below: ServiceContext serv...

How to create XML File in Java using DOM parser?

To create XML file in Java,here we are using DOM parser. By using the below code you can easily create XML file. Write the below Java class to create a XML file: CreateXMLFile.java package com.babita; import java.io.File; import jav...

How to create CSV file in java?

Sometime we need to generate CSV from data as per requirement. You can easily create CSV file by following the below steps: Write the following Maven configuration in pom.xml file in your project: <dependency> <groupid>net....

How to read data from CSV file in Java?

Sometimes we need to read data from a CSV file as per requirement. You can easily read the data from CSV file by following the below steps: Write the following Maven configuration in pom.xml file in your project: <dependency> ...

Creating Custom Scope in Spring

Using Custom Scopes, we can define new scope as well as modify the existing scope. Custom Scope is useful for following scenarios- creating a bean scope where beans can be shared between servlet contexts creating a bean scope where bean...
1 5
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: