Saturday, 20 April 2013

What is the solution of JAR Updates and its dependencies...?



 Answer is:  Apache Maven 
----------------------------------------------------------------------------------
 Introduction
Maven, a Yiddish word meaning accumulator of knowledge, was originally started as an attempt to simplify the build processes in the Jakarta Turbine project. There were several projects each with their own Ant build files that were all slightly different and JARs were checked into CVS. We wanted a standard way to build the projects, a clear definition of what the project consisted of, an easy way to publish project information and a way to share JARs across several projects.
The result is a tool that can now be used for building and managing any Java-based project. We hope that we have created something that will make the day-to-day work of Java developers easier and generally help with the comprehension of any Java-based project.
Maven's Objectives
Maven's primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal there are several areas of concern that Maven attempts to deal with:
  • Making the build process easy
  • Providing a uniform build system
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features
For more Details.. Go Through http://maven.apache.org/what-is-maven.html and any doubt about it send me mail ….

Zip Format Compress With JAVA Code

package com.jay.zip;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class MyZip
{
    List<String> fileList;
    private static final String OUTPUT_ZIP_FILE = "C:\\MyFile.zip";
    private static final String SOURCE_FOLDER = "C:\\testzip";

    MyZip(){
    fileList = new ArrayList<String>();
    }

    public static void main( String[] args )
    {
        MyZip MyZip = new MyZip();
        MyZip.generateFileList(new File(SOURCE_FOLDER));
        MyZip.zipIt(OUTPUT_ZIP_FILE);
    }

    /**
     * Zip it
     * @param zipFile output ZIP file location
     */
    public void zipIt(String zipFile){

     byte[] buffer = new byte[1024];

     try{

        FileOutputStream fos = new FileOutputStream(zipFile);
        ZipOutputStream zos = new ZipOutputStream(fos);

        System.out.println("Output to Zip : " + zipFile);

        for(String file : this.fileList){

            System.out.println("File Added : " + file);
            ZipEntry ze= new ZipEntry(file);
            zos.putNextEntry(ze);

            FileInputStream in =
                       new FileInputStream(SOURCE_FOLDER + File.separator + file);

            int len;
            while ((len = in.read(buffer)) > 0) {
                zos.write(buffer, 0, len);
            }

            in.close();
        }

        zos.closeEntry();
        //remember close it
        zos.close();

        System.out.println("Done");
    }catch(IOException ex){
       ex.printStackTrace();  
    }
   }

    /**
     * Traverse a directory and get all files,
     * and add the file into fileList 
     */
    public void generateFileList(File node){

        //add file only
    if(node.isFile()){
        fileList.add(generateZipEntry(node.getAbsoluteFile().toString()));
    }

    if(node.isDirectory()){
        String[] subNote = node.list();
        for(String filename : subNote){
            generateFileList(new File(node, filename));
        }
    }

    }

    /**
     * Format the file path for zip
     * @param file file path
     * @return Formatted file path
     */
    private String generateZipEntry(String file){
        return file.substring(SOURCE_FOLDER.length()+1, file.length());
    }
}

Saturday, 6 April 2013

Most favorite Question : Logic Behind "System.out.println()"



System.out.println prints the argument passed, into the System.out which is generally stdout.

  • System – is a final class and cannot be instantiated. Therefore all its memebers (fields and methods) will be static and we understand that it is an utility class. As per javadoc, “…Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array…”



  • out – is a static member field of System class and is of typePrintStream. Its access specifiers are public final. This gets instantiated during startup and gets mapped with standard output console of the host. This stream is open by itself immediately after its instantiation and ready to accept data. When running a program from windows command line, it is the standard console.



  • println – println prints the argument passed to the standard console and a newline. There are multiple println methods with different arguments (overloading). Every println makes a call toprint method and adds a newline. print calls write()and the story goes on like that.

Thursday, 4 April 2013

Android Holo Colors Generator

Change Tabhost Setting Programattically


tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String arg0) {

// Log.i("***Selected Tab", "Im currently in tab with index::" +
// tabHost.getCurrentTab());
selTabPos = tabHost.getCurrentTab();
for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) {
if (i == selTabPos) {
tabHost.getTabWidget()
.getChildAt(i)
.setBackgroundColor(Color.parseColor("#4a92ce"));
} else {
tabHost.getTabWidget()
.getChildAt(i)
.setBackgroundColor(Color.parseColor("#253040"));
}


}
}
});

for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) {
if (i == selTabPos) {
tabHost.getTabWidget().getChildAt(i)
.setBackgroundColor(Color.parseColor("#4a92ce"));
} else {
tabHost.getTabWidget().getChildAt(i)
.setBackgroundColor(Color.parseColor("#253040"));
}

tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = height / 15;
}

Wednesday, 3 April 2013

How to add tab layout without letting the activity to extend TabActivity? Part -2


How to add tab layout without letting the activity to extend TabActivity?

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TabHost tabHost = (TabHost) findViewById(R.id.mytabhost);
    tabHost.setup();

    TabSpec tab1 = tabHost.newTabSpec("TAB_1");
    tab1.setIndicator("Tab 1");
    tab1.setContent(R.id.tab1);
    tabHost.addTab(tab1);

    //tab 2 etc...
    TabSpec tab2 = tabHost.newTabSpec("TAB_2");
    tab2.setIndicator("Tab 2");
    tab2.setContent(R.id.tab2);
    tabHost.addTab(tab2);
}
-----------------------------------------------------------------------------------------------------------------------
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mytabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


    <LinearLayout android:id="@+id/LinearLayout01"
        android:orientation="vertical" android:layout_height="fill_parent"
        android:layout_width="fill_parent">

        <TabWidget android:id="@android:id/tabs"
            android:layout_height="wrap_content" android:layout_width="fill_parent"></TabWidget>

        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_height="fill_parent" android:layout_width="fill_parent">
            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:id="@+id/tab1">
                <!-- tab 1 content goes here -->
            </LinearLayout>
            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:id="@+id/tab2">
                <!-- tab 2 content goes here -->
            </LinearLayout>

        </FrameLayout>

    </LinearLayout>

</TabHost>