Thursday, April 9, 2015

Java 8 without Lambdas to print elements using short hand

Goal
Print all elements in List with Java 8 without Lambdas and a short hand input.

Setup
In following code lets fill in the blanks to print all elements of given list.

@Test
    public void SimpleCollection() {
        List values = Arrays.asList(1, 2, 3, 4, 5, 6);

        values.forEach(/* fill the code here */);

    }

Solution
As the solution is small and trivial the output looks as follows.


@Test
    public void SimpleCollection() {
        List values = Arrays.asList(1, 2, 3, 4, 5, 6);

        values.forEach(System.out::println);

    }

Java 8 with lambda expression to print elements on screen

Goal
Using Java 8 and its new feature Lambdas lets print each element of List to screen.

Setup
We will start with following code and fill in to a piece of logic to push elements on console.

@Test
    public void SimpleCollection() {
        List values = Arrays.asList(1, 2, 3, 4, 5, 6);

        values.forEach(/* fill with lambda expression */);

    }

Goal
We will a lambda expression e -> {/** code block **/} to manage the output logic. Something like this
value -> {
            System.out.println(value);
        }

The complete solution looks like following

@Test
    public void SimpleCollection() {
        List values = Arrays.asList(1, 2, 3, 4, 5, 6);

        values.forEach(value -> {
            System.out.println(value);
        });

    }

Java 8 For Each with Consumer example

Goal
Java 8 comes with new features which adds forEach and Consumer to its list. Lets write a simple piece of code that uses forEach and Consumer<> to print the elements on screen.

Setup
Following code is given to us and need to fill in the blank to print the elements.

@Test
    public void SimpleCollection() {
        List values = Arrays.asList(1, 2, 3, 4, 5, 6);

        values.forEach(/** fill with Consumer and print to screen.**/
);

    }

Solution
We can use follwing code to fill in the blank. This code uses Consumer and implements the method accept(). In accept() we can write any piece of logic. Here we will simply print elements on screen.

new Consumer() {
            public void accept(Integer value) {
                System.out.println(value);
            }

The complete program looks like as following :

@Test
    public void SimpleCollection() {
        List values = Arrays.asList(1, 2, 3, 4, 5, 6);

        values.forEach(new Consumer() {
            public void accept(Integer value) {
                System.out.println(value);
            }
        });

    }

Sort Collection using sort function and Java 8

Goal
Sorting is widely used in daily routine to modify data arrangement. In this blog the input is a list of alphabets. Using Java 8 and new sort method. This blog introduces List.sort() as a small example.

Setup
Lets start with following code. As shown it prints unsorted array elements.

         @Test
    public void testCollectionSorted() {
        List list = Arrays.asList("b", "f", "e", "a");
        
        // print each elements of list object
        list.forEach(input -> System.out.println(input));
    }

Solution
Now we will use List.sort() and pass a lambda expression which will sort the list

list.sort((e1e2) -> {
            return e1.compareTo(e2);
        });

Thats it. Here is the full method which can be used to sort and print array contains alphabets.

         @Test
    public void testCollectionSorted() {
        
        List list = Arrays.asList("b", "f", "e", "a");
        list.sort((e1, e2) -> {
            return e1.compareTo(e2);
        });

        list.forEach(input -> System.out.println(input));
}

Tuesday, April 7, 2015

Hello World in Java

In this blogpost I will show you how to write SIMPLE hello world program in Java using command line.

On Windows :
> Type cmd in start
> in cmd type notepad press enter
> In notepad type following



> Save the notepad to cmd's present working directory
> execute javac "filename.java"
> execute java -classpath . filename.class
> Output should be "Hello World!"

Have fun .. this is just a sample blog......

Saturday, January 11, 2014

Handling screen resolution problem after installing ubuntu

>> Changing Screen resolution :

Somtime ubuntu does not recognize correct resolution for the screen. But we can always make it up. Execute following steps in order to change screen resolution are you are interested in :

1) Screen resolutions that my screen can adjust to are :
   - 1280x1024
   - 1680x1050

2) Adding a new resolution starts with getting the right configurations for that resolution.
  - (todo: write cvt command here )

3) Execute : xrandr --newmode "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync

This will create a resolution entry in the file

4) Now add the resolution to GUI for changing resolution :

xrandr --addmode VGA-0 1680x1050_60.00

5) There must be an option to change to this resolution in the GUI. Go check and change to that GUI if interested ...

>> Installing JAVA
 
$ sudo apt-get install openjdk-6-jdk

>> Installing BUILD ESSENTIALS

$ sudo apt-get install build-essential

>> Installing Apache

$sudo apt-get install apache2

Few useful commands :
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop

Go to http://localhost in your browser and should get "It Works" message from Apache.

>> Installing PHP

sudo apt-get install php5 libapache2-mod-php5

Restart apache
sudo /etc/init.d/apache2 restart

Check if PHP is installed correctly 
sudo gedit /var/www/testphp.php
Write "" and save the file.

Go to following location in browser :
http://localhost/testphp.php

This will display PHP information on the webpage.

>> Installing MySQL 

sudo apt-get install mysql-server

Remember the passsword for mysql-server as root.

Now install php tool to edit MySQL .

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin


Configuration file is at /etc/mysql/my.cnf

Friday, June 29, 2012

Useful Softwares

SuperPutty : http://code.google.com/p/superputty/
JvmStat
JD : Java Decompiler

Sunday, May 13, 2012

Hadoop - Forrester Report


AWS is feature rich ?? Need to check it out.
 Forrester claiming AWS is feature rich. I dont know how.

hadoop modelling : MR, Pig, Mahout
Storage and Data MGMT : HDFS, HBase, Cassandra
Data warehousing,summarization, query : Hive, Sqoop
Data Collection / Aggregation / analysis : Chukwa, Flume
metadata/table/schema : HCatalog
Cluster mgmt/job sched/workflow : zookeeper, oozie, Ambari
Hadoop Data Serialization : Avro


Good News : Hadoop is full of immature products

Hadoop productions  :
MapR = Strong OEM, feature rich ( why feature rich )
HortonWorks : Efficient echo system, everything
Penhaho : BI tool for big data, works on thrid party hadoop clusters
DataMeer : Hadoop modelling tool ( a modelling tool for nonrelational database .. LOL )

Companies involving hadoop :
Composite Software, Concurrent, Dell, Endeca, Hadapt, HP/Vertica,Informatica, NetApp, Microsoft, Oracle, Pervasive, Platfora, Quest Software, RainStor, SAP/Sybase, SGI,and StackIQ. Karmasphere and Teradata/Aster Data,
Forrester : HStreaming, Outerthought, Zettaset, Platform Computing, Pentaho, Datameer, DataStax, HortonWOrks, Cloudera, MapR, GreenPlum, EMC, IBM, AWS

Friday, April 20, 2012

Compare Apache Wicket vs Vaadin

Here is the stackoverflow blog that I found which compare wicket and Vaadin.

If you are not interested in reading the whole forum then understand that Wicket has more advantages than Vaadin. Vaadin has advantages of beautiful themes but wicket can integrate with GWT.

Vaadin is better if  you just want to stick with java and not interested in CSS or javascript. But if you put in your resume that you are a web developer but not good at CSS or JavaScript then it automatically turns against you. So Vaadin wont be advantageous here. While using Wicket comes with some skills required to imagine the GUI. For developers designing GUI is also useful virtue. Does not need to be flashy but certainly useful GUI rocks.

If desktop look and feel is needed then Vaadin is good as I already suggested, but wicket is no less. You can use GWT to create such look and feels.



Thursday, March 8, 2012

datasets

This site links to various dataset across the federal government.

www.Data.gov -- repository for data and geodata from across the federal government, searchable by agency, data type, keyword, among others. Many, but not all Commerce data sets reside here.

http://www.data.gov/metric

Data.gov Commerce Data and tools can be found at

Data
http://www.data.gov/list/agency/1/0/catalog/raw/page/1/count/50

Tools
http://www.data.gov/list/agency/1/0/catalog/tools/page/1/count/50

Census Data – Population, household, housing, demographics. Economic census and monthly indicators, foreign trade, employment statistics, maps, geographic data and more. http://www.census.gov/
http://www.census.gov/main/www/access.html

List of Open Data Sites Around the World: http://www.data.gov/opendatasites
Amazon Listing of Public Data Sets: http://aws.amazon.com/datasets
Washington DC: http://data.octo.dc.gov
New York: http://nyc.gov/data
San Francisco: http://datasf.org/
U.K.: http://data.gov.uk/

http://www.cs.cmu.edu/~awm/10701/project/data.html