How to For Each in Hash Map in Java 8 using Lambda Expressions

Lambda Expression Java 8

In Java 1.8 (Java 8) this has become lot easier by using forEach method from Aggregate operations(Stream operations) that looks similar to iterators from Iterable Interface.

Just copy paste below statement to your code and rename the HashMap variable from hm to your HashMap variable to print out key-value pair.

HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();
/*
 *     Logic to put the Key,Value pair in your HashMap hm
 */

// Print the key value pair in one line.
hm.forEach((k,v) -> System.out.println("key: "+k+" value:"+v));

Below is the sample code that i tried using Lambda Expression. This stuff is so cool. Must try.

HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();

    Random rand = new Random(47);

    int i=0;
    while(i<100)
    {
        i++;
        int key = rand.nextInt(20);
        int value = rand.nextInt(50);
        System.out.println("Inserting key: "+key+" Value: "+value);
        Integer imap =hm.put(key,value);
        if( imap == null)
        {
            System.out.println("Inserted");
        }           
        else
        {
            System.out.println("Replaced with "+imap);
        }               
    }

    hm.forEach((k,v) -> System.out.println("key: "+k+" value:"+v));

Also one can use Spliterator for the same.

Spliterator sit = hm.entrySet().spliterator();

UPDATE


Including documentation links to Oracle Docs. For more on Lambda go to this link and must read Aggregate Operations and for Spliterator go to this link.

Design Patterns

Cover of "Design Patterns: Elements of Re...

Cover via Amazon

Hello guys,

Last week I got a chance to attend a training on Design Patterns. I would like to share my views on that this is the best way to really learn object-oriented design. After recognizing these Patterns it will improve your coding skills to par and further in future it will make you a good developer.

Prior knowledge of any computer language is required but it will be advantage to those people who have worked upon languages related to OOPs concept. It will be easy for them to co relate their problems and easy design solution to their problems.

1. Design Patterns are solution to common design problems that developers face during designing simple/complex applications and GOF(Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides) Gang Of Four identified those problems and make a series of those solutions as Design Patterns. I would recommend you all to read this book at least.

2. We can divide these 23 Design Patterns into three categories:

3. Structural Patterns are those patterns which are related to composing the classes and objects in order to form larger Structures. One can relate these patterns to common life examples like Bridge, Adapter etc. Let me write down those patterns:

  • Bridge
  • Adapter
  • Decorator
  • Composite
  • Proxy
  • Flyweight
  • Facade

4. Creational Patterns are related with Instantiating the objects, creating the good design concept while coding in order to make their use easy while developing applications, these are:

5. Behavioral Patterns  are related to Behavior of the objects, their communication with the other objects and their methods. Basically algorithmically design of the classes and their methods. These are:

  • Chain of Responsibility
  • Command
  • Interpreter
  • Iterator
  • Mediator
  • Memento
  • Observer
  • State
  • Strategy
  • Template Method
  • Visitor

So guys improve your programming skills as I am doing so right now. Please share your comments and suggestions to improve others.

Books you can read to improve your Design Patterns concept

1.  Design Patterns: Elements of Reusable Object-Oriented Software

2. Head First Design Patterns

Nokia Lumia 920 in Newyork from the verge

Image representing Nokia as depicted in CrunchBase

Image via CrunchBase

So people are shouting Switch to Lumia. Well lets see what do you have Mr. Nokia Lumia 920.

– Wireless Charging : That is something Apple does not have.

– Nokia SmartShoot lets your remove unwanted objects in photos.  That is smart.

– Pure View, Nokia Maps/Drive/Transport, Nokia City Lens

– In Slate grey, Red, and Yellow colors

– 2000mAh battery

– Carl Zeiss rear camera

– Offline Maps is the feature

– Nokia Drive for free voice navigation

– Best Viewing experience with Nokia PureMotion HD+

– 4.5 inches curved glass display

– ClearBlack displays using smart Polarizers

– Automatic brightness control in light and no light

– Qualcomm Snapdragon S4 processor

– IE10 and HTML5

– Auto upload to SkyDrive in Windows Phone 8 (WP8) not only phone photos even from third party apps photos too, totally smart

– fastest LCD display on smartphone, WXGA, higher than 720p resolution

– Super sensitivity touch allows you to touch the display with gloves good in winters

– JBL Power UP speaker for Nokia

– Integrated NFC

– Smart Shoot, it analyzes and finds the objects that are moving that is really really smart feature, very useful

– Cinemagraph is the lens to make GIF

– Whole camera assembly has springs around it that makes 50 percent better picture quality

– 100,000+ apps

Most of the stuffs from : The Verge Live Coverage  from New York. It looks Yellow and Blue is the color theme.

Reserve Bank of India

Hello Friends,

Today I am going to discuss about Reserve Bank of India (RBI). This is central bank of India.

It was established in 1934 as a private bank, government owned and it was not a commercial bank but its sole purpose was to provide basic services of Central Bank to India.

It is an agency or an institution to do traditional work of a central bank. Where Deposit, Credit can be done. Normal bank that we know are the bank which act as intermediaries between Depositors and Creditors.  Difference between Central bank and commercial bank is that Central Bank is bank of Commercial bank and Commercial banks are bank to Citizen.

Central bank works on government behalf,  like it can give pension, take income tax. It works for both government and commercial bank.

There are 27 PSU banks in India, 196 regional banks, various private banks and some international banks also like Bank of America and Citi. America has 4 central banks.

It make sure that savings are getting utilized, means savings should be in other forms of liquid cases like MFs, Share market, FDs etc.

It take care of Controlled Monitoring Expansion.

Some other institutional banks that got formed from RBI:

1964 – Industrial Development Bank of India from RBI

1982 – NABARD

1989 – National Housing Bank

RBI works as guide to these banks.

RBI works as custodian of foreign currency, controller of credit.

There is a question between RBI and government. Shall RBI works as free entity, no control from Government.

What is Deficit banking, you must be wondering: What happens When government needs money they order overdraft on their behalf to RBI and RBI release it. This is called Deficit Financing.

RBI gives guidance, advise, warning to break this deficit financing but govt ignores. So bank finds it is not good for future. Now an agreement happened between govt and RBI for limit of ordering Overdraft. So if government asks for more than the limit then RBI can decide what is good for future.

July 1991, Govt decontrol the government institution, and now almost every govt. institute is dismantling govt. control. So new economic system. no control, only market, capital power. So new situation is good but RBI should guide them.

Hope you liked my post. I will post more informative articles time to time.

The old RBI Building in Mumbai

Govt of India Mint, Behind the RBI HQ. Mumbai

Govt of India Mint, Behind the RBI HQ. Mumbai (Photo credit: Wikipedia)

The old RBI Building in Mumbai (Photo credit: Wikipedia)

How to remove extra characters in UNIX file using NotePad Plus Plus

Hi Guys,

Today i was facing some problem while viewing UNIX files on my system using NotePad ++. There were some unwanted characters in the file that were causing pain to read the file.

These are the steps how to remove those unwanted characters from the UNIX file in NPP++.

Step 1: Select the unwanted character by placing cursor right before the character and press shift+ right arrow key once.

Step 2: After selecting the character it will look like the above screen. Now you need to replace it with space ‘ ‘ character. Following screen will clear your understanding:

Step 3: Change the value in Replace with text field with ‘ ‘ single space character:

Step 4: Now just click the Replace All button and here you go smooth and clean text to read:

Thanks for reading it. I will paste some more easy to understand tricks on my site.

How to Save Battery

Hello friends,

Here are some suggestions from my side in order to save your battery. Information gathered from internet and from my experience.

1. First day of battery you should over charge it for half an hour more after your phone is showing Battery full.

2. Later days never charge it often, as Li ion battery comes with limits of number of recharge.

3. Always charge before it runs down.

4. Do not talk much on phone, so avoid long duration calls. Also good for health.

5. Use GPRS mode only when needed, so avoid those applications that syncs with the server more often. Increase the sync time if it needed be.

6. Switch off while you are travelling underground or there is no network, because battery consumption goes higher in order to increase the power of receiver to get the network signals.

7. Better suspend those applications which are in syncing mode while you are sleeping.

8. The best way of recharging battery is while phone is switched off.

9. Do not use UMTS network mode when there is no 3G network.

10. Protect it from direct sunlight.

 

Thanks guys for reading. Suggestions are welcome.

Nokia BL-5B lithium-ion battery

Image via Wikipedia

Yes, God is there!!!

Believers (film)

Image via Wikipedia

Yes, God is there…

Yet you never been to temple, you still care there is God.

Yet you never been to mountains, you still knows there is God.

Yet you never played any music, you still hear there is God.

Yet you never saw any miracles, you still see there is God.

Yet you never try to pray, you still gets because there is God.

Yet you never faced problems, you still say because there is God.

Yet you never lied and deceived someone, you still say because of God.

Yet you made a mistake, you still get it corrected and say there is God.

Yes my friends, its true there is God. There is an energy behind everything that moves around us, around others. From the ancient philosophers, scientist to the modern philosophers, scientist goes around and find only one thing in common and that is they say is God.

To God,

From

The Believers. Enjoy and keep smiling. :)

Dragon, Fly – Android v/s iOS

Hello Dear Friends,

I happened to get a chance to play new game called “Dragon, Fly” on one of my friends’ Samsung GS1. I will say it was total addiction. I would like to write some of my views:

Pros:
  • Graphics
  • Smooth
  • Easy to learn
  • Simple settings and good pictorial tutorial
  • Terrain changes on daily basis
  • Swoosh, Sky Fly and Hot Fire modes are quite good mode to encourage the player to earn more points
  • Sound is also good
  • Point system is clear and you can compete globally.
Cons:
  • Memory consuming
  • No Replay option
  • No Story line like we do have in Angry Birds.
Then again luckily i got a chance to play same type of game on iPod Touch and name is Angry Hill“. For that i would like to compare same game on different OS.
Pros:
  • Different types of Terrain i.e. Dark, Light and Bright.
  • Funny graphics for kids.
  • Best free game in iTunes
  • You get a buddy to compete with
  • Also arcade mode is same  version like we have in Android version.
Cons:
  • Needs improvement on Graphics area
  • Sound is not interesting
  • Scaling of screen while high jump is not smooth
  • No story line.
Some video review that i found on YouTube, thanks to these video uploads :
Dragon, Fly

 

Angry Hills

I would like to give rating to both of these games:

Dragon, Fly – 8/10

Angry Hills – 7.5/10

Thanks guys for reading this post and do let me know if you have any comments.