• Facebook
  • Twitter
  • Google+
  • Youtube
  • Instagram

About me

Let me introduce myself

A bit about me

Hello friends, I am Dhananjaya Naidu and I’m just like you; a java lover. I feel proud to say that I am a Java Developer and currently located in Bangalore, India.

I enjoy coding in full Java/J2ee stack (Spring, JSF, Hibernate, Struts, Servlets, JSP) and Web Technologies (HTML, CSS, JavaScript, JQuery).

I love to play Cricket, Kabaddi, Valley Ball and any Outdoor Sports. I love the nature and like to travel new places.


Dhananjaya Naidu

Personal info

Dhananjaya Naidu Reddi

Be good, Do good !!!

Birthday: 19 Jun 1988
Website: www.rdnaidu.com
E-mail: hello@rdnaidu.com

Skills & Things

Java & J2ee


My latest writings

Thursday, 21 December 2017

What is Kafka.? What is ZooKeeper.? Kafka Basic Commands...!!!

If you are new to Kafka this notes is a good starter.

What is Apache Kafka?

  • a publisher-based messaging system in the Hadoop ecosystem
  • each node is called a "broker"
  • written in scala and Java 1.6
  • queues are known as "topics"
  • Topics can be partitioned, generally based on the number of consumers of the topic.  
  • Each message in a partition has a unique sequence number associated with it called an offset.  
  • ZooKeeper serves as the coordination interface between the kafka broker and its consumers.  
  • Elects one broker as the leader of a partition, and all the writes and reads must go to the leader partition.
  • Kafka does not have any concept of a master node and treats all the brokers as peers.  

ZooKeeper Basics

  • ZooKeeper is a configuration and coordination manager used in many Hadoop products. 
  • znodes:  shared, hierarchical namespace of data registers much like a filesystem
  • runs, generally, on port 2181
  • config/server.properties
    • lists zookeeper connection info
    • lists the broker.id for the node/namespace
    • lists the logs dir
  • zoo.cfg

Kafka Topics

  • by default a topic (queue) has one partition and a replication factor of 1.  
  • kafka-list-topic.sh actually queries zookeeper for its replication factor, partitions, and leader info.  
  • Leader:  a randomly-selected node for a specific portion of the partitions and is responsible for all reads and writes for the partition.  
  • isr:  in-sync replicas:  replicas that are currently alive and in sync with the leader.  Basically, the non-leader nodes
  • When a new leader needs to be elected this causes significant read-write load in zookeeper and should be avoided.  
  • Kafka tries to ensure that lead replicas for topics are equally distributed among nodes but that breaks down when a node is taken offline. 

Partitioning and Replication

  • The producer determines how the messages are partitioned.  The broker stores the messages in the same order as they arrive.  The number of partitions can be configured for each topic within the broker.  
  • Replication was introduced in Kafka 0.8.
  • ensures better durability of messages and high availability of the cluster.  
  • guarantees that the message will be published and consumed even in case of broker failure 

Useful Kafka Commands

# create a topic

/bin/kafka-create-topic.sh --zookeeper localhost:2181 --replica 1 --partition 1 --topic 

# create a topic with 4 partitions and a replication factor of 2

/bin/kafka-create-topic.sh --zookeeper localhost:2181 --replication-factor 2 --partition 4 --topic 

# have a producer send some messages

/bin/kafka-console-producer.sh --broker-list localhose:9092 --topic 

# starting a consumer

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic  --from-beginning

#list all topics with leader, replication, and partition information
./kafka-list-topic.sh --zookeeper localhost:2181
#see information for only one topic
./kafka-list-topic.sh --zookeeper localhost:2181 --topic 
#show a topic's "lag"
/opt/kafka/bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group  --zkconnect :2181
#show just the topic's "lag"
/opt/kafka/bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group  --zkconnect :2181 | awk '{print $6}' | tail -n 3
#start Kafka on one node, with its correct configuration (supervisord is the right way to do this)
./kafka-server-start.sh ../config/server.properties
#stop Kafka on one node (supervisord is the right way to do this)
#look at Kafka/ZooKeeper supervisord configuration entries
cat /etc/supervisord.conf

tail -f /var/log/supervisor/supervisord.log 

Since Kafka depends on ZooKeeper it's best, IMHO, to ensure each service is managed with something like supervisord.  Having said that, we'll look at the native commands:  

#shutdown a node

bin/kafka-run-class.sh kafka.admin.ShutdownBroker --zookeeper  --broker 

#startup a node

bin/kafka-server-start.sh config/server.properties 

Various Logs

#view supervisord configs
cat /etc/supervisord.conf
#supervisord logs
cat /var/log/supervisor/supervisord.log
#if only zk is not running, check its logs
tail -f /var/home/user/log/zookeeper.out
#if kafka process is not running, check these logs
less /var/home/user/kafka/logs/supervisor-kafka.log
less /var/home/user/log/kafka.out
less /var/home/user/logs/server.log
less /var/home/user/state-change.log

Friday, 15 December 2017

Apache Kafka : Installing and Running on Windows

This notes will provide a step by step guide to run Apache Kafka on a windows OS. This guide will also provide instructions to setup Java & zookeeper. Apache kafka is a fast & scalable messaging queue, capable of handling real heavy loads in context of read & write. You can find more about kafka on kafka. Apache kafka requires a zookeeper instance running which is used for reliable distributed coordination. Please find more about Zookeeper on zookeeper.

Downloading the Required Files


1. Install & Setup Java Runtime Environment (JRE)

2. Installing & Running Zookeeper

Kafka uses ZooKeeper so you need to first start a ZooKeeper server if you don't already have one. Otherwise Install ZooKeeper by following below steps.
  • Goto your zookeeper config directory. For me its C:\zookeeper-<version>\conf
  • Rename file “zoo_sample.cfg” to “zoo.cfg”
  • Open zoo.cfg in any text editor like notepad but I’ll prefer notepad++.
  • Find & edit dataDir=/tmp/zookeeper to dataDir=C:\zookeeper-<version>\data
  • Add entry in System Environment Variables as we did for java
  • Add in System Variables ZOOKEEPER_HOME = C:\zookeeper-<version>
  • Edit System Variable named “Path” add ;%ZOOKEEPER_HOME%\bin;
  • You can change the default zookeeper port in zoo.cfg file (Default port 2181).
  • Run zookeeper by opening a new cmd & type zkserver.
We can start zookeeper server from here or we can start from Kafka installation folder by using C:\kafka_2.11-\config\zookeeper.properties.

3. Setting Up Kafka

  • Go to your Kafka config directory. For me its C:\kafka_2.11-\config
  • Edit file “server.properties”
  • Find & edit line “log.dirs=/tmp/kafka-logs” to “log.dir= C:\kafka_2.11-\kafka-logs”.
  • If your zookeeper is running on some other machine or cluster you can edit “zookeeper.connect=localhost:2181” to your custom IP & port. For this demo we are using same machine so no need to change. Also Kafka port & broker.id are configurable in this file. Leave other settings as it is.
  • Your Kafka will run on default port 9092 & connect to zookeeper’s default port which is 2181. 

4. Running Kafka Server

Please ensure that your zookeeper is up & running before starting Kafka server.
  • Go to your kafka installation directory C:\kafka_2.11-\
  • Open command line in your Kafka installation folder
  • Launch Zookeeper with .\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
  • Open a second command line in your Kafka installation folder
  • Launch single Kafka broker: .\bin\windows\kafka-server-start.bat .\config\server.properties
Now your Kafka is up & running, so now you can create topics & produce or consume data from java/scala code & command prompt also.

5. Creating Kafka Topic

  • Now create a topic with name “test” & replication factor 1 as we have only one Kafka server running. If you have a cluster with more than 1 Kafka servers running, you can increase the replication-factor accordingly which will increase the data availability & act like a fault-tolerant system.
  • Open a new command prompt in the location C:\kafka_2.11-\bin\windows
  • Type following command and hit enter
  • kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

6. Creating a producer & consumer to test server

  • Open a new command prompt in the location C:\kafka_2.11-\bin\windows
  • To start a producer type command “kafka-console-producer.bat --broker-list localhost:9092 --topic test”.
  • Again open a new command prompt in the same location as C:\kafka_2.11-\bin\windows
  • Now start a consumer by typing command “kafka-console-consumer.bat --zookeeper localhost:2181 --topic test”.
Now you will have two command prompts like image below...

  • Now type anything in the producer command prompt & press enter and you should be able to see the message in the other consumer command prompt.
  • If you are able to push & see your messages in consumer side, your Kafka setup is ready.

Saturday, 14 October 2017

Immutable Java objects & Why String is immutable

Immutable objects are simply objects whose state (the object's data) cannot change after construction.
Examples of immutable objects from the JDK include String and all Wrapper classes like Integer, Double...

Make a class immutable by following these guidelines:

  • Make all fields final.
    • When you define fields as final in Java, you must either initialize them at declaration time or in the constructor. Don't panic if your IDE complains that you don't initialize them at the declaration site. It'll realize that you've come back to your senses when you write the appropriate code in the constructor.
  • Make the class final so that it cannot be overridden.
    • If the class can be overridden, its methods' behaviors can be overridden as well, so your safest bet is to disallow subclassing. Notice that this is the strategy used by Java's String class.
  • Do not provide a no-argument constructor.
    • If you have an immutable object, you must set whatever state it will contain in the constructor. If you have no state to set, why do you have an object? Static methods on a stateless class would work just as well. Thus, you should never have a no-argument constructor for an immutable class. If you're using a framework that requires this for some reason, see if you can satisfy it by providing a private no-argument constructor (which is visible via reflection).
  • Notice that the lack of a no-argument constructor violates the JavaBeans standard, which insists on a default constructor. But JavaBeans cannot be immutable anyway, because of the way the setXXX methods work.
  • Provide at least one constructor.
    • If you haven't provided a no-argument one, this is your last chance to add some state to the object!
  • Do not provide any mutating methods other than the constructor.
    • Not only must you avoid typical JavaBeans-inspired setXXX methods, but you must also be careful not to return mutable object references. The fact that the object reference is final doesn't mean that you can't change what it points to. Thus, you need to make sure you defensively copy any object references you return from getXXX methods.
  • If the class has any mutable object fields, then they must be defensively copied when they pass between the class and its caller

Following example implementation demonstrates how to create an "immutable class" 

import java.util.Date;

* Planet is an immutable class, since there is no way to change
* its state after construction.
public final class Planet {

  public Planet (double aMass, String aName, Date aDateOfDiscovery) {
     fMass = aMass;
     fName = aName;
     //make a private copy of aDateOfDiscovery
     //this is the only way to keep the fDateOfDiscovery
     //field private, and shields this class from any changes that 
     //the caller may make to the original aDateOfDiscovery object
     fDateOfDiscovery = new Date(aDateOfDiscovery.getTime());

  * Returns a primitive value.
  * The caller can do whatever they want with the return value, without 
  * affecting the internals of this class. Why? Because this is a primitive 
  * value. The caller sees its "own" double that simply has the
  * same value as fMass.
  public double getMass() {
    return fMass;

  * Returns an immutable object.
  * The caller gets a direct reference to the internal field. But this is not 
  * dangerous, since String is immutable and cannot be changed.
  public String getName() {
    return fName;

//  /**
//  * Returns a mutable object - likely bad style.
//  *
//  * The caller gets a direct reference to the internal field. This is usually dangerous, 
//  * since the Date object state can be changed both by this class and its caller.
//  * That is, this class is no longer in complete control of fDate.
//  */
//  public Date getDateOfDiscovery() {
//    return fDateOfDiscovery;
//  }

  * Returns a mutable object - good style.
  * Returns a defensive copy of the field.
  * The caller of this method can do anything they want with the
  * returned Date object, without affecting the internals of this
  * class in any way. Why? Because they do not have a reference to 
  * fDate. Rather, they are playing with a second Date that initially has the 
  * same data as fDate.
  public Date getDateOfDiscovery() {
    return new Date(fDateOfDiscovery.getTime());


  * Final primitive data is always immutable.
  private final double fMass;

  * An immutable object field. (String objects never change state.)
  private final String fName;

  * A mutable object field. In this case, the state of this mutable field
  * is to be changed only by this class. (In other cases, it makes perfect
  * sense to allow the state of a field to be changed outside the native
  * class; this is the case when a field acts as a "pointer" to an object
  * created elsewhere.)
  private final Date fDateOfDiscovery;
“Classes should be immutable unless there's a very good reason to make them mutable....If a class cannot be made immutable, limit its mutability as much as possible.”

Benefits of immutability: 


  • are simple to construct, test, and use
  • are automatically thread-safe and have no synchronization issues
  • don't need a copy constructor
  • don't need an implementation of clone
  • allow hashCode to use lazy initialization, and to cache its return value
  • don't need to be copied defensively when used as a field
  • make good Map keys and Set elements (these objects must not change state while in the collection)
  • have their class invariant established once upon construction, and it never needs to be checked again
  • always have "failure atomicity" (a term used by Joshua Bloch): if an immutable object throws an exception, it's never left in an undesirable or indeterminate state
“The impact of object creation is often overestimated and can be offset by some of the efficiency associated with immutable objects. These include decreased overhead due to garbage collection, and the elimination of code needed to protect mutable objects from corruption.”

Why is String immutable in Java?

An immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. In some cases, an object is considered immutable even if some internally used attributes change but the object's state appears to be unchanging from an external point of view. Here, we look into the String immutability, why it is necessary, what's its use and what is string pool in Java.

Ways to create string:

There are two ways to create a String in java.
  • With new operator
  • Using string literal or constant
For example,
String str = new String("Hello Java World");
String str = "Hello Java World";       (literal)
String str1 = "Hello"+"Java"+"World";  (constant exp)

String Literal pool:

String allocation, like any other object creation proves costly in time and memory.The JVM do some trickery while instantiating the string literals to increase performance and decrease memory overhead. To decease the number of creation of String object in JVM, the String class keeps a pool of Strings. Each time you create a string literal, the JVM checks the string literal pool first. If a string is found in the pool, a reference to the pooled string is return.if the String is not exist in the pool, a new string object is instantiates, then placed in the pool.

String is immutable for several reasons, here is a summary:

  • Security: parameters are typically represented as String in network connections, database connection urls, usernames/passwords etc. If it were mutable, these parameters could be easily changed.
  • Synchronization and concurrency: making String immutable automatically makes them thread safe thereby solving the synchronization issues.
    • Since String is immutable it can be safely shared between multiple threads which is very important in multi threaded application and to avoid any synchronization issue. Also you no need to synchronize String operation externally.
  • Caching: when compiler optimizes your String objects, it sees that if two objects have same value (a="test", and b="test") and thus you need only one string object (for both a and b, these two will point to the same object).
    • String in immutable means, no one can change its contents once created and which guarantee the hashcode of string to be same in multiple invocation. So Java, cache the string hashcode and do not calculate every time we call its hashcode method of string, which make it very fast as hashmap key used in HashMap in java.
  • Class loading: String is used as arguments for class loading. If mutable, it could result in wrong class being loaded (because mutable objects change their state).
    • Had string been immutable, a request to load jdbc.driver could have been changed to "mysql.driver".
  • That being said, immutability of String only means you cannot change it using its public API. You can in fact bypass the normal API using reflection. See the answer here.
  • Imagine String pool facility without making string immutable.It is not possible at all because in case of string pool with one string object/literal
    e.g. "Java World" has reference by many reference variable, if one them change the value others will be automatically affected i.e. let say
    String A="Java World"
    String B="Java World"
    Now String B called "JAVA WORLD".toUpperCase() which change into JAVA WORLD, so A will also be changed which is not desirable .
This is the same reason for making String final.
Though final and immutable are 2 different things e.g. StringBuffer is a final class in java but still mutable. But certain feature of String class will not be possible until string is final.

equals()  vs  ==

equals() can be consider to perform a deep comparison of the value of a object. It compare the content of 2 objects rather then references. Whereas == perform a shallow comparison. == operator with reference type evaluate to true if the references are identical means point to the same location.
Example :
String s1="hello";
String s2="hello";
if(s1==s2) //return true
if(s1.equals(s2)) //return true

String s3=new String("hello");
String s4=new String("hello");
if(s3==s4) //return false
if(s3.equals(s4)) //return true

String s5="he"+"llo";
String s6="h"+"ello";
if(s5==s6) //return true
if(s5.equals(s6)) //return true

The creation of 2 string with the same sequence of letters without the use of new operator will create pointers to the same location in string literal pool. The literal pool is a way java conserves resources.


The Java String class has a method called intern(), used to create an internal pool of unique strings. Given a string str, saying:
str = str.intern();
adds the string to the internal pool if not already there, and returns a reference to the interned string. Interned strings can be compared with each other using ==, which is much cheaper than using equals() to do the comparison. String literals are always interned.

When you use
String str=new String("java world");
a string object is created out of the string literal pool , even if an equals string is already exists in the pool. Avoid new String unless you need it !

A JVM has string literal pool where it keep at most one object of the same type. String literal always refers to an object string literal pool. Since the object created with new String do not refer to objects in the String literal pool but you can made them with the help of String's intern() method.

java.lang.String.intern() return interned String i.e, one that has an entry in the global pool. If string is not already there, then it will be added.

Example of intern()
String s1 = "java world";
String s2 = new StringBuffer("java").append(" world").toString();
String s3 = s2.intern();

if(s1==s2) //return false
if(s1==s3) //return true

JVM is maintaining a table containing single reference to each unique string object in the global string pool ever created by an instance in order to optimize space. This means, there is always a reference to the String object in the string pool, therefore string object in the string pool is not eligible for garbage collection.


Thursday, 28 September 2017

Getting started with Spring Boot

What is Spring Boot

Spring Boot is a tool provided by Spring to help you starting a project quickly and easily. This is indeed true, but not the first time.

If you are using Spring Boot for the first time it will take you some time to get all the pieces of the long documentation to really understand how to use it. Spring Boot is simple but I think the documentation doesn’t really show it.

Don’t get confused…

If you want to work with Spring Boot you will inevitably go there http://projects.spring.io/spring-boot. This page is very confusing because you will understand that Spring Boot is a CLI, but also an online tool, and finally the page will suggest you to download a snippet of .xml.

From here you should start be lost and ask yourself questions like, why do I need to download a snippet of code if there is a CLI ? Is this Spring Boot thing a generator or not?

Then, to get more confused they add:
The recommended way to get started using spring-boot in your project is with a dependency management system
Ok, now you are talking about a dependency management system although I just wanted to generate a boilerplate Spring project to start with. This is where you will think that you need to go to the heavy documentation to understand Spring Boot. The good news is that you don’t need to.

So, what is it really?

Spring Boot regroup 2 things.
Spring Boot will help you to:

Generate a project
  • Using the online tool
  • Using the CLI
Run/maintain your project by managing Spring dependencies for you.

Generate a Spring project

Using the online tool Spring Initializer

If you don’t like the command line you can go online to http://start.spring.io and generate your Spring project.

Be careful, by default the tool doesn’t give you much choices, but on the bottom of the page you have a small link to access the full version of the tool.

The tool can take a lot of information as entries like the dependency management system that you want to use (Gradle or Maven), the Java version, or your Spring dependencies. After you have selected your desired options, the tool will send you a .zip file containing your Spring project and that’s it, you are done.

Using the CLI

The Spring Boot CLI provides a command which can generate a Spring project for you, like the Spring Initializr does. But if you prefer to use the CLI, you will have to install it first. It can be installed by several means but the easiest on Mac OS is surely Homebrew.

brew tap pivotal/tap
brew install springboot

Go here if you need instructions to install it on another system.

The command spring init will generate .zip file containing a very basic project structure but it is really helpful and powerful if you add some parameters to the command. Have a look at the documentation here

https://docs.spring.io/spring-boot/docs/current/reference/html/cli-using-the-cli.html#cli-init to get an overview of the possibilities or type spring init — list. If you use all of them you can get something as complete as the online version of the Spring Initializr.

This is an example of the command that you could use:

spring init --build=maven --java-version=1.8 --dependencies=web --packaging=war sample-app.zip

Run/manage your project with Spring Boot

The second use of Spring Boot is to run and maintain the dependencies of your project.

Run your project

To run your project you would need to build it and then run it. But because Spring Boot sets up your project with a Maven plugin, it will do all of that for you.

So, in order to run your project with the help of Maven and Spring Boot, simply run:

mvn spring-boot:run

You should now be able to visit http://localhost:8080 and see the first page of your project.
Don’t be surprised to read the message “Whitelabel Error Page” on the page. It doesn’t mean that your project is not working but instead that your project doesn’t have a page mapped to the url “/”. So all what you need to do here is to create your first controller and start building your web app.

Manage your Spring dependencies

Spring Boot is also very helpful to manage Spring dependencies in a project. Remember that when you generated your project you mentioned Spring dependencies. Those dependencies are indeed spring-boot dependencies which means that Spring Boot will manage them for you.

It will manage for example the versions to be sure that they are compatible but where it shines really is with configuration.

Spring Boot dependencies will allow your Spring project to be automatically configured whenever possible which is quite often actually. That means that your project almost doesn’t require that you manage its configuration yourself. This is a big advantage.

Finally, Spring Boot Actuator aimed at helping you to monitor and manage your application with a set of metrics gathered automatically for you. It adds several endpoints to your application each of them relative to different metrics. Learn more here.

Add other Spring dependencies

You are still able to add Spring dependencies after you generated your project. Go to your software management file and add the sping-boot dependencies that you want. This is an example with Maven.



A word on Gradle and Maven

Although the Maven plugin allows you to build and run your project as a single step, you can still of course use Gradle or Maven to only build your project in order to deploy it.

If you want to use those tool, here is a reminder of how to.

Install Maven:
brew install maven

Build your project with Maven:
mvn clean install

Once you have built your project you should get either a .jar or .war depending of what you chose when you generated your project. Then, you can run your project with:
java -jar target/sample-app-0.0.1-SNAPSHOT.jar

or (for a .war):
java -jar target/sample-app-0.0.1-SNAPSHOT.war

Finally, if you need to, you can also deploy your resulting .war file to a Tomcat server.


Friday, 23 June 2017

Iterate through a HashMap - Java

There are several ways of iterating over a Map in Java. Lets go over the most common methods and review their advantages and disadvantages. Since all maps in Java implement Map interface, following techniques will work for any map implementation (HashMap, TreeMap, LinkedHashMap, Hashtable, etc.)

Method #1: Iterating over entries using For-Each loop.

This is the most common method and is preferable in most cases. Should be used if you need both map keys and values in the loop.
Map<Integer, Integer> map = new HashMap<Integer, Integer>();

for (Map.Entry<Integer, Integer> entry : map.entrySet()) {

    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());


Note that For-Each loop was introduced in Java 5 so this method is working only in newer versions of the language. Also For-Each loop will throw NullPointerException if you try to iterate over a map that is null, so before iterating you should always check for null references.

Method #2: Iterating over keys or values using For-Each loop.

If you need only keys or values from the map, you can iterate over keySet or values instead of entrySet.
Map<Integer, Integer> map = new HashMap<Integer, Integer>();

//iterating over keys only

for (Integer key : map.keySet()) {

    System.out.println("Key = " + key);


//iterating over values only

for (Integer value : map.values()) {

    System.out.println("Value = " + value);


This method gives slight performance advantage over entrySet iteration (about 10% faster) and is more clean.

Method #3: Iterating using Iterator.

Using Generics:
Map<Integer, Integer> map = new HashMap<Integer, Integer>();

Iterator<Map.Entry<Integer, Integer>> entries = map.entrySet().iterator();

while (entries.hasNext()) {

    Map.Entry<Integer, Integer> entry = entries.next();

    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());


Without Generics:
Map map = new HashMap();

Iterator entries = map.entrySet().iterator();

while (entries.hasNext()) {

    Map.Entry entry = (Map.Entry) entries.next();

    Integer key = (Integer)entry.getKey();

    Integer value = (Integer)entry.getValue();

    System.out.println("Key = " + key + ", Value = " + value);


You can also use same technique to iterate over keySet or values.

This method might look redundant but it has its own advantages. First of all it is the only way to iterate over a map in older versions of Java. The other important feature is that it is the only method that allows you to remove entries from the map during iteration by calling iterator.remove(). If you try to do this during For-Each iteration you will get "unpredictable results" according to javadoc.

From performance point of view this method is equal to For-Each iteration.

Method #4: Iterating over keys and searching for values (inefficient).

Map<Integer, Integer> map = new HashMap<Integer, Integer>();

for (Integer key : map.keySet()) {

    Integer value = map.get(key);

    System.out.println("Key = " + key + ", Value = " + value);


This might look like a cleaner alternative for method #1 but in practice it is pretty slow and inefficient as getting values by a key might be time consuming (this method in different Map implementations is 20%-200% slower than method #1). If you have FindBugs installed, it will detect this and warn you about inefficient iteration. This method should be avoided.


If you need only keys or values from the map use method #2. If you are stuck with older version of Java (less than 5) or planning to remove entries during iteration you have to use method #3. Otherwise use method #1.

Source @www.sergiy.ca

Wednesday, 3 May 2017

Command to view stored procedure

You can use the following data dictionary views to display the body from stored procedures:




Here is an example of how to use the user_source view:

SELECT TEXT from user_source

where type='PROCEDURE'



Where TEXT lists the body of procedure "PROC1"


What can I do


Coming Soon...!!!

Web Design

Coming Soon...!!!


Coming Soon...!!!

Graphic Design

Coming Soon...!!!


Coming Soon...!!!

User Experience

Coming Soon...!!!


Get in touch with me


Bangalore, India