Posts

Showing posts from August, 2012

TabHost without extending TabActivity...Example

TabDemo.java package com.hcl.tab; import android.app.Activity; import android.app.ActivityGroup; import android.content.Intent; import android.os.Bundle; import android.os.Bundle; import android.util.Log; import android.widget.TabHost; public class TabDemo extends ActivityGroup {    TabHost host;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState)    {       Log.i(this.toString(), "OnCreate");       super.onCreate(savedInstanceState);       setContentView(R.layout.main);       Log.i(this.toString(), "get tab host");               this.host = (TabHost) findViewById(R.id.tabhost);       this.host.setup(getLocalActivityManager());       host.setup();       Log.i(this.toString(), "add tabs");       host.addTab(host.newTabSpec("one")                       .setIndicator("First Results")                       .setContent(new Intent(this, FirstResul

Why StAx Parser?

Check the link for stAx parser and webservices http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.6/tutorial/doc/SJSXP2.html http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.6/tutorial/doc/JavaWSTutorial.pdf

XML Parsing in Java

Parsing XML If you are a beginner to XML using Java then this is the perfect sample to parse a XML file create Java Objects and manipulate them. The idea here is to parse the employees.xml file with content as below <?xml version="1.0" encoding="UTF-8"?> <Personnel>   <Employee type="permanent">         <Name>Seagull</Name>         <Id>3674</Id>         <Age>34</Age>    </Employee>   <Employee type="contract">         <Name>Robin</Name>         <Id>3675</Id>         <Age>25</Age>     </Employee>   <Employee type="permanent">         <Name>Crow</Name>         <Id>3676</Id>         <Age>28</Age>     </Employee> </Personnel> From the parsed content create a list of Employee objects and print it to the console. The output would be something like Employee De

Simplest way to read data from an XML file into a Java program....Using DOM parser

This is the simplest way to read data from an XML file into a Java program. I have also included some basic error checking, so you can directly cut-paste this code with a few changes ofcourse. All you have to do is change the XML tags within the program to match those that are present in your XML file. XML File <book> <person> <first>Kiran</first> <last>Pai</last> <age>22</age> </person> <person> <first>Bill</first> <last>Gates</last> <age>46</age> </person> <person> <first>Steve</first> <last>Jobs</last> <age>40</age> </person> </book> Program Output Root element of the doc is book Total no of people : 3 First Name : Kiran Last Name : Pai Age : 22 First Name : Bill Last Name : Gates Age : 46 First Name : Steve Last Name : Jobs Age : 40 Program Listing The Java program to read the above XML file is sho

Inter process communication(IPC)

Image
What is IPC? Inter-Process Communication (IPC) is a set of techniques for the exchange of data among multiple threads in one or more processes. Processes may be running on one or more computers connected by a network. IPC techniques are divided into methods for message passing, synchronization, shared memory, and remote procedure calls (RPC). The method of IPC used may vary based on the bandwidth and latency of communication between the threads, and the type of data being communicated. A Socket-based IPC Tutorial http://people.cis.ksu.edu/~singh/CIS725/Fall99/programs/sock_ipc_tut.html JIPC - Java Interprocess Communication Server http://www.garret.ru/jipc/jipc.html Inter-Process Communication Module Index http://www.cs.gmu.edu/cne/modules/ipc/term-index.html

Thread

Image
process: A process consists of the memory space allocated by the operating system that can contain one or more threads. A thread cannot exist on its own; it must be a part of a process. A process remains running until all of the non-daemon threads are done executing. Multithreading enables you to write very efficient programs that make maximum use of the CPU, because idle time can be kept to a minimum. Life Cycle of a Thread: A thread goes through various stages in its life cycle. For example, a thread is born, started, runs, and then dies. Following diagram shows complete life cycle of a thread. Above mentioned stages are explained here: New: A new thread begins its life cycle in the new state. It remains in this state until the program starts the thread. It is also referred to as a born thread. Runnable: After a newly born thread is started, the thread becomes runnable. A thread in this state is considered to be executing its task. Waiting: Sometimes a thread transitions t

Implementation differences in GET and POST:

Differences in GET and POST: they have different encoding schemes. multipart/form-data is for POST only the result of POST may not result in an actual page. url limit necessitates use of POST If you are using HIDDEN inputs in form then submitting a GET request reveals those inputs  GET is for data retrieval only. You can refine what you are getting but it is a read only setup and yes, as you mentioned anything used for refinement are part of the URL. POST is meant for sending data, but is generally a way to 'break' the simple workings of HTML because you are neither guaranteed of anything that is happening, it can just fetch data, send data or delete data.

AsyncTask in Android Expample

Image
AsyncTask is an abstract class that provides several methods managing the interaction between the UI thread and the background thread. it’s implementation is by creating a sub class that extends AsyncTask and implementing the different protected methods it provides. Let’s demonstrate how to user AsyncTask by creating a simple activity that has two buttons and a progress bar: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=" http://schemas.android.com/apk/res/android "  android:layout_width="fill_parent" android:layout_height="fill_parent"  android:orientation="vertical">  <ProgressBar android:id="@+id/progressBar"   style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent"   android:layout_height="wrap_content" android:indeterminate="false"   android:max="10" android:padding="10dip">

MNC: Android and Java interview questions

Java Questions: 1)       What is the difference between Java IPC and Android IPC? 2)       What is the main specific difference between GET and POST? 3)       Factory design pattern 4)       What are all the design patterns you know? 5)       What is throw, throws and Throwable? 6)       Explain, How synchronization concepts   works internally in java ?(not   technically) 7)       Explain synchronization through operating system concepts? 8)       What will happen if                 Object obj=null;                   Synchronized(obj){                   } 9)       Rules to use synchronization? 10)    About Synchronization concept of static and non- static method using Class level lock ?             a)    If more than one threads are running then how threads they can operate on same static synchronized method simultaneously?              b) Class level lock, can have more than 1 threads are able to execute in non-static synchronized method 11) Difference of Hashtable , Hashset and   Ha