How can we compare String creation performance?

In this article we will discuss performance wise what is the best way to create String object. There are two ways to create String object: By string literal String str = “10Article”; When we create string literal then JVM checks Heap string constant pool first. If the string already exists in the pool, a reference

How to reverse each word of string?

How to reverse each word of string. Problem Statement: I have a string with multiple words. I want to reverse each word of this string. Reverse each word of string. Source Code: package com; public class Test { public static void main(String args) { String str1 = "Java and J2EE Technology Servlet"; String str2 =

How to count the occurrences of a Sub String in another String?

How to count the occurrences of a Sub String in the given String > String search Problem Statements: I have a long String, I want to find out the occurrence of sub string in this. How to find out a duplicate sub string in a long String. I want to print multiple occurrence count of

How to get the nth index of the given token occurring in the given string > String search

How to get the nth index of the given token occurring in the given string > String search Problem Statements: I have a long String with multiple lines, I want to print last 2 lines from this String. I want to print second last line from my String. I want to show only three lines

JAX-WS Tutorial

JAX-WS Tutorial: As we know there is two types of web services. SOAP Restful   Here I am talking about SOAP based web services. Java provides a set of APIs to develop web services in XML format is called JAX-WS. JAX-WS provides many annotation to simplify the development and deployment for both web service clients

Java Singleton Design pattern Question & Answer

Java Singleton Design pattern Question & Answer. Q1. What is the Significance of Classloader in Singleton Pattern? Ans1. If singleton class is loaded by two classloaders, two instance of singleton class will be created, one for each classloader. Q2. What is the significance of Serialization in Singleton Pattern? Ans2.  If a singleton class is serializable,

Factory Design Pattern

Factory Design Pattern: This is most used design pattern in Java. Factory pattern also called as Factory method design pattern. Factory design pattern comes under creational pattern. This pattern provides one of the best ways to create an object. By this pattern we create object without exposing creation logic of these objects to the users.

Singleton design pattern

Singleton design pattern: This is the simplest and most useful design pattern in java. Singleton design comes under creational pattern as this pattern provides one of the best ways to create an object. This pattern involves a single class which is responsible to create an object while making sure that only single object gets created.

Behavior Design Patterns

Behavior Design Patterns: Behavioral pattern explain interaction between the objects. Means objects look like they are talking with each other without hard coding .Objects are loosely coupled. Behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. Behavioral patterns increase flexibility in carrying out this communication. As we

Structural Design Patterns

Structural Design Patterns: These types of patterns describe how objects and classes can be combined and create big structure. Than question arise what is the difference between these class patterns and object patterns? Class patterns explain abstraction with the help of inheritance and how it can be used to provide more useful program interface. Object