Sunday, December 8, 2013

Junit Testing Introdcution

Testing:
Testing is the process of checking the functionality of the application as per requirements.

JunitTesting:
-JUnit is a unit testing framework for the Java Programming Language
-It is a process of checking the functionality of the application at the developer level .
-Main use of junit testing is programmer productivity and stability of program code that reduces programmer stress and the time spent on debugging.

Features :
*JUnit is an open source framework used for writing & running tests.
*Provides Annotation to identify the test methods.
*Provides Assertions for testing expected results.
*Provides Test runners for running tests.
*JUnit tests allow you to write code faster which increasing quality
*JUnit is elegantly simple. It is less complex & takes less time.
*JUnit tests can be run automatically and they check their own results and provide
immediate feedback. There's no need to manually comb through a report of test results.
*JUnit tests can be organized into test suites containing test cases and even other test
suites.

UnitTest case:
*A Unit Test Case is a part of code which ensures that the another part of code (method) works as
expected.
*JUnit is perfect unit test framework for java programming language.






Saturday, November 23, 2013

Facebook Android integration java.lang.NullPointerException: Argument 'applicationId' cannot be null

You may face the following error when integrating facebook sdk with Android :

                java.lang.NullPointerException: Argument 'applicationId' cannot be null.

If you are getting the above error even though you specified the facebook applicationId in manifest file as follows: 

          <meta-data android:name="com.facebook.sdk.ApplicationId"   android:value="123456785678" />


Reason:
Reason for the above error is due to the ApplicationId is mentioned as Integer , as we specified directly in manifest . But facebook SDK needs ApplicationId value as String. So if we pass ApplicationId as above, inside facebook SDK 'ClassCastException' occurs and considers  ApplicationId value as null. 

Solution:
Declare APP_ID value in strings.xml as follows:
 <string name="APP_ID">123456785678</string>

And then refer this APP_ID as ApplicationId value in manifest file:

<meta-data  android:name="com.facebook.sdk.ApplicationId" android:value="@string/APP_ID" />

Please share your comments on this , if it is helped ...




Thursday, May 23, 2013

Android Inc History and Development

Brief History - Android :

  • Android Inc  was founded at Palo Alto in oct-2003 by Andy Rubin, Rich Miner , Nick Sears and Chris White to develop Operating System for Digital Cameras.
  • Later they diverted their efforts towards produce a smart phone operating system due to less market for digital cameras.
  • Google acquired 'Android Inc' on August-2005 .
  • On 2007 Google established a 'Open Handset Alliance (OHA)' , is a association of hardware , software, telecommunication companies to develop open standards for mobile operating system.
  • First commercially available phone to run on Android was 'HTC Dream' on 2008.

=========================================================

Environment - Android:

  • Android SDK 
  • Eclipse IDE 
  • Java SDK 

Android SDK setup : 

 

Sunday, May 19, 2013

Android Operating System Introduction and Architecture

Android Operating System:

  1. Android is a software stack for mobile devices which includes operating system , middle-ware and key applications.
  2. Android applications are written in Java Language.
  3. Android SDK has build in tools and libraries which necessary for Android development.
  4. Android operating system is Multi User Linux system. By default Linux assigns unique user id for each application. So one application data can't be shared to other application directly(i.e Isolated).
  5. Each application runs on his own process.

Android System Architecture:

Architecture consists of four layers .
  • Linux Kernel
  • Libraries - Android Runtime
  • Application Framework
  • Applications 
Now I am going to explain each and every layer in details :
Linux Kernel
  • Android architecture is based on Linux kernel 2.6.
  • Linux kernel provides Memory management, power management , process management , security model , networking etc...
Libraries and Android Runtime
  • Libraries are written in C and C++.
  • Surface Manager is responsible for composing different drawing surfaces on to the screen.
  • OpenGL/ES is a 3D graphics library.
  • SGL is for 2D graphics. Most of the application drawing is based on this library only.
  • Media Framework contains the entire codex that make up the core media experiences.
  • Free Type is to render fonts .This is a free , high-quality , portable font engine.
  • SQLite is for core data storage.
  • WebKit is a open source browser engine.(Same as safari on Apple)
  • Android Runtime includes core libraries that provides the most of the functionality available in the core libraries of Java.
  • Dalvik Virtual Machine is extremely low memory based virtual machine, designed for Android tow work well in low power situations.
  • Core Libraries contains all the collection classes, utilities , tools .
Application Framework:
  • Application framework written in java .
  • It is like a toolkit that all applications can use.
  • It has several components like Activity manager, Package Manager , Window manager , Telephony Manager , Content Provider , Location Manager, View System , Notification System.
Applications:
  • At the top of the architecture we have all the applications which are used by final user.
  • Apps developed by us also sits on this layer.



Monday, June 4, 2012

Why Sencha Touch 2

INTRODUCTION:


1. As a Android developer we need to implement UI in a generic way as much as possible ,even though
project is targeting to particular device. Because android support multiple screen sizes.
Eg: 7 inch, 10 inch tablets , phone devices with different sizes.


2. If we are working on Iphone, we need to develop UI for both Ipad and Iphone. Same case in other technologies also.


  Here the question is can we develop UI to work in all the devices irrespective of the size ???
  Here one more question is can we develop UI to work in most of the popular devices irrespective of                                platform like   Android/Iphone/BlackBerry/Windows ???              

Answer to the above questions is "Sencha Touch 2"

What is  Sencha Touch 2 ???
-Framework that enables developers to build fast and impressive apps that works on iOS, Android, BlackBerry, Kindle Fire etc and produce a native-apps.
-It's a high-performance HTML5 mobile application framework .
-Portability across multiple platforms. (cross-platform).
- Ease of Development.
- One developer can implement UI for all the devices irrespective of Device or platform.
- It makes specific use of HTML5 to deliver components like audio and video, as well as a     localStorage proxy for saving data offline .
- Makes extensive use of CSS3 to provide a robust styling layer.

Advantages of Native apps?
-Native look and feel.
-Access to Device features like File system, GPS etc.
-Navigation speed is more.



What’s so Special about Sencha Touch?

There are some obvious advantages of using Sencha Touch. The specialty of this framework is its features, and they make it one of the most preferable platform to develop hybrid applications. Sencha has gained its popularity because of its following advantages :
  • Highly compatible with HTML5, CSS3 and Javascript and is built with web standards
  • Provides highest level of flexibility and optimization to the apps
  • High compatibility with the most advanced operating systems like iOS and Android
  • Provides pixel-perfect, cross-browser fidelity
  • Access to building blocks like Grids, carousels, nested lists, trees, toolbars for consumers, and enterprise applications
  • Customized enhanced touch events like tap, double tap, swipe, pinch and rotate
  • Allows the developers to use special themes for different devices



Friday, April 27, 2012

Telugu Movie Story in English ,for Personality Development Session.






Today I would like to talk about a movie, which i feel is not only a very good movie but also  message oriented. This movie is all about the corruption.Coming to the story , a college professor whos aim is to eliminate corruption from the society forms a group/coalition called ACF.
He  is the hero in our story. He starts one coalition by the former students. This coalition plan is to kidnap 15 most corrupt officers from any one department and kill the most corrupt of them all.This spreads panic and fear among others. There after officer are afraid to take the bribe . They start killing one corrupted person from every department. From that time no body takes bribe from anyone. So common people starts praising about this coalition. This way he eliminates the corruptoin from the society. the most interesting point here is how this group gets the corruption details of every officer. For this atleast one employe in every govt office belongs to this team. This way this group fights against the corruption. This group name is ACF (Anti Corruption Force) and the hero name is Tagore.

In flashback  Tagore loses his wife and kid in an accident that was caused due to illegal constructions, which happened because of corruption.Finllay Police found one clue and
arrests all ex-students of that college and gives them a redroom treatment. But, police people fails to know their chief's name.
Unable to see the torture on his students, Hero decides to surrender himself on a condition that all those who were arrested will get back their jobs unconditionally.


Tagore is arrested and is presented in a special court, where he refuses to plead guilty.
Cheif minister requests him to appeal for kshamabiksha. But, tagore rejects.

In the end, tagore is sentenced to 5 years imprisonment and is released thereafter.










Sunday, June 5, 2011

Java And Android Interview Questions asked in Harman.com

1. Tell me the OOP'S concepts in Java ?
2. Can abstract class contain constructor or not ?
3. Difference between Interface and Abstract class ?
4. Can Interface have Inner class ?
5. How to throw "IllegalArgumentException"?
6. What is JDK and JRE , explain about these.
7.  Threads read and write problem ? (Write the code).
8. Tell me about Serialization in Java ?
9. Inheritance concepts and Object creation possibilities in Inheritance ?
10. What is Collection and Vector ?
11. Write the Code for Singleton's class ?
12. Tell me about Android Framework ?
13. What is a Service in Android ?































Saturday, October 2, 2010

Disabling Context Menu for EditText in Android

Generally most of the applications use EditText in Every UI screen.
Android provides default keyboard for EditText. This Keyboard pops-up whenever we are keeping the cursor in EditText box.

Also Android provides default ContextMenu options for EditText. If you enter any text in EditText box and then long press on the entered text , then context menu options will pop-up. These options like cut,copy ,paste ...etc. These are like right click options for the MSWord.


But For some requirements these context menu options not required and also some situations we have to disable this context menu options also. To do this we have to add one tag in XML for that edit text box.

Eg.  Add the following tag to ur EditText properties....

                      android:longClickable="false"

Tuesday, September 28, 2010

To Find the file extension using JAVA

String extension;


int dotPos = filenameExtension.lastIndexOf(".");

extension = filenameExtension.substring(dotPos);

Wednesday, September 22, 2010

Combining both view with xml layout.

package com.android.murthy;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;

public class Dynamic extends Activity {
    /** Called when the activity is first created. */
    Inner inner;
    EditText preview_val;
    Button show_prev;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        inner = new Inner(this);
      //  setContentView(inner);
        LayoutParams params = new LayoutParams(150,105);
        addContentView(inner, params);
        preview_val = (EditText) findViewById(R.id.prev_value);
        show_prev = (Button) findViewById(R.id.previewBtn);
        show_prev.setOnClickListener(new OnClickListener() {
          
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String value = preview_val.getText().toString();
                Log.i("edit_txt value",value);
            }
        });
      
      
      
      
    }
    private class Inner extends View{

        public Inner(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }
        @Override
        protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            super.onDraw(canvas);
            Rect rect = new Rect(10, 40, 60, 80);
            Paint paint = new Paint();
            paint.setStyle(Paint.Style.FILL);
            paint.setColor(Color.RED);
           // canvas.drawColor(Color.GREEN);
            canvas.drawRect(rect, paint);
        }
    }
}
 main.xml

    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
   
    >


                android:layout_height="fill_parent" >

          android:layout_marginLeft="200dp"
          android:text="ZOOM (%)"
          android:id="@+id/zoom_txt"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textColor="#000000"/>                 

          android:id="@+id/prev_value"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:layout_marginLeft="200dp"
          android:maxLines="1"/>
         


Monday, July 12, 2010

About Android SDK and It's contents

Android:

Android is a Stack for mobile devices, that includes an Operating system, middle ware, and key applications.

Android SDK:

The android SDK provides tools and libraries that are necessary to begin developing application that run on android devices..

SDK contains the following folders:

 1)add-ons:
    -Add-ons is an extension to the Android SDK development environment that  lets your to develop applications for devices .
  -Eg. we can develop an android application that uses google maps.This google maps API is available in this add-on folder.

2)docs:

- This folder contains full set of documentation in HTML format.
-This documentation includes development guide and API reference.
-This documentation is very useful for the developers, who is not having any net connection(broadband) .

3)platforms:

- This folder contains a set of Android platform versions. So that you can develop applications in different versions.

4)samples:

-This folder contains Sample code and applications that are specific to platform versions.

5)tools:
-This folder contains set of development and profiling tools available to us, such as emulator,android tool, adb, ddms etc.

6) SDK Readme.text:
-This file explains how to perform initial setup of android SDK.
-This also explains how to launch the Android SDK and AVD Manager tool on all platforms.

7)SDK setup.exe:
-This is shortcut that launches the Android SDK and AVD Manager tool.

8) usb_driver:

-This is folder is not in the android sdk if you are downloaded for Linux Operating System.
-We get this folder whenever we downloaded the SDK for Windows.
-This folder contains the driver files that we can install on our windows computer.So that we can run and debug our applications on actual device.

Screens:

Monday, July 5, 2010

Basic Flow of Lucene , Apache Solr. (Internal Flow /Process involved in Apache Lucene)

Read The following Article to Become Master in Lucene Scoring.
You can't get this information from anywhere.

Internal Flow in Apache Solr:

Whenver we enter something to search in Solr admin console,it will be received by QueryComponent.java. Means this is the starting point for the search process. QueryComponent.java is present in Solr.

Functionalities of QueryComponent.java


-Receives Query string.

-splits the query string based on some characters.

-collects the unique-id's from schema.xml.

-Find id's that are matched with query string.

-Send response to the user.

INTERNAL FLOW IN LUCENE:

The QueryParser is used to transform user submitted query strings into QueryObjects.

Lucene's Query API:


When a human-readable query is parsed by Lucene's QueryParser, it is converted to a single concrete subclass of the Query class. However, we need some understanding of the underlying concrete Query subclasses. The relevant subclasses, their purpose, and some example expressions for each are listed in the following table:



Query Implementation

Purpose

Sample expressions

TermQuery

Single term query, which effectively is a single word.

reynolds

PhraseQuery

A match of several terms in order, or in near vicinity to one another.

"light up ahead"

RangeQuery

Matches documents with terms between beginning and ending terms, including or excluding the end points.

[A TO Z]
{A TO Z}

WildcardQuery

Lightweight, regular-expression-like term-matching syntax.

j*v?
f??bar

PrefixQuery

Matches all terms that begin with a specified string.

cheese*

FuzzyQuery

Levenshtein algorithm for closeness matching.

tree~

BooleanQuery

Aggregates other Query instances into complex expressions allowing AND, OR, and NOT logic.

reynolds AND "light up ahead"
cheese* -cheesewhiz

QueryParser expression syntax:


The following items in this section describe the syntax QueryParser supports to create the various query types.


Single-term query:


A query string of only a single word is converted to an underlying TermQuery.


Phrase query:


To search for a group of words together in a field, surround the words with double-quotes. The query "hello world" corresponds to an exact phrase match, requiring "hello" and "world" to be successive terms for a match.

Lucene also supports sloppy phrase queries, where the terms between quotes do not necessarily have to be in the exact order. The slop factor measures against how many moves it takes to rearrange the terms into the exact order. If the number of moves is less than a specified slop factor, it is a match. QueryParser parses the expression "hello world"~2 as a PhraseQuery with a slop factor of 2, allowing matches on the phrases "world hello", "hello world", "hello * world", and "hello * * world", where the asterisks represent irrelevant words in the index. Note that "world * hello" does not match with a slop factor of 2. Why? Because the number of moves to get that back to "hello world" is 3. Hopping the word "world" to the asterisk position is one, to the "hello" position is two, and the third hop makes the exact match.


Range query:


Text or date range queries use bracketed syntax, with TO between the beginning term and ending term. The type of bracket determines whether the range is inclusive (square brackets) or exclusive (curly brackets).

NOTES: Non-date range queries use the start and end terms as the user entered them without modification. In the case of {Aardvark TO Zebra}, the terms are not lowercased. Start and end terms must not contain whitespace, or parsing fails; only single words are allowed. The analyzer is not run on the start and end terms.


Date range handling:


When a range query (such as [1/1/03 TO 12/31/03]) is encountered, the parser code first attempts to convert the start and end terms to dates. If the terms are valid dates, according to DateFormat.SHORT and lenient parsing, then the dates are converted to their internal textual representation (however, date field indexing is beyond the scope of this article). If either of the two terms fails to parse as a valid date, they both are used as is for a textual range.


Wildcard and prefix queries:


If a term contains an asterisk or question mark, it is considered a WildcardQuery, except when the term only contains a trailing asterisk and QueryParser optimizes it to a PrefixQuery instead. While the WildcardQuery API itself supports a leading wildcard character, the QueryParser does not allow it. An example wildcard query is w*ldc?rd, whereas the query prefix* is optimized as a PrefixQuery.


Fuzzy query:


Lucene's FuzzyQuery matches terms close to a specified term. The Levenshtein distance algorithm determines how close terms in the index are to a specified target term. "Edit distance" is another term for "Levenshtein distance," and is a measure of similarity between two strings, where distance is measured as the number of character deletions, insertions, or substitutions required to transform one string to the other string. For example, the edit distance between "three" and "tree" is one, as only one character deletion is needed. The number of moves is used in a threshold calculation, which is ratio of distance to string length.

QueryParser supports fuzzy-term queries using a trailing tilde on a term. For example, searching for wuzza~ will find documents that contain "fuzzy" and "wuzzy". Edit distance affects scoring, such that lower edit distances score higher.


Boolean query:


Constructing Boolean queries textually is done using the operators AND, OR, and NOT. Terms listed without an operator specified use an implicit operator, which by default is OR. A query of abc xyz will be interpreted as abc OR xyz. Placing a NOT in front of a term excludes documents containing the following term. Negating a term must be combined with at least one non-negated term to return documents. Each of the uppercase word operators has shortcut syntax shown in the following table.

Verbose syntax

Shortcut syntax

a AND b

+a +b

a OR b

a b

a AND NOT b

+a -b


Implementing Scoring:

The Scorer abstract class provides common scoring functionality for all Scorer implementations and is the heart of the Lucene scoring process. The Scorer defines the abstract methods which must be implemented in child classes.

The following methods are very important while we are implementing Score.


  1. DocIdSetIterator#nextDoc() — Advances to the next document that matches this Query, returning true if and only if there is another document that matches.

  2. DocIdSetIterator#docID() — Returns the id of the Document that contains the match. It is not valid until next() has been called at least once.


3.Scorer#score(Collector) — Scores and collects all matching documents using the given Collector.


4.Scorer#score() —Abstract method ,the child classes must implement.

--Returns the score of the current document matching the query.This value can be determined in any appropriate way for an application.

For instance, the TermScorer returns the tf * Weight.getValue() * fieldNorm.

NOTE:

Initially invalid, until DocIdSetIterator.next() or DocIdSetIterator.skipTo(int) is called the first time, or when called from within Collector.collect(int).

5. DocIdSetIterator#advance(int) — Skip ahead in the document matches to the document whose id is greater than or equal to the passed in value. In many instances, advance can be implemented more efficiently than simply looping through all the matching documents until the target document is identified.


CODING:

If anyone having interest to know more details about scoring implementaion just send a mail to the following mail-id:

murthy.mca53@gmail.com


Thanks&Regards

v.s.n murthy




Tuesday, May 4, 2010

Most Frquently Asked Questions in JAVA

Basic Questions from J2SE:

1) What is the difference between an interface and abstract?

2) What is the purpose of abstract class?

3) What is the use of volatile modifier?

4) Can we declare a class as private ? Explain ?

5) Tell me about native modifier ?

6) Explain public static void main(String args[])

7) What is the use of inheritance ?

8) Does java Supports Cyclic Inheritance ?

9) What is the size of char datatype in Java ?

10) What is the size of int data type in Java ?

11) How many keywords are there in Java?

12) Tell me about Access specifiers in Java?

JAVA JOBS FOR FRESHERS

Best Web site for Java Freshers

Wednesday, December 23, 2009

Spring Easy Example with Screen shots

Spring Tutorial By Murthy

Writing a Simple Spring Application :
I am explaining this application using MyEclipse IDE. Better to use MyEclipse because it has inbuilt support for Spring Framework. If you are using Eclipse ,you have to install plugins.


1) File->New->JavaProject


Then give project name as your wish. I gave project name as Project12 and click on Finish button.



2) Right click on the Project12 and follow as follows:

New-->Package-->give any name what you want.
For ex: com.companyname.projectname.iocmodule
Then click on Finish button.

3) In order to add Spring capabilities to our application we have to add Spring container. To do this follow the below steps:

Right click on the project and then Click on MyEclipse-->Add Spring Capabilities-->Select Spring 2.5 core libraries Checkbox.



4) Then one applicationContext.xml will be added in our project src folder. Just rename dat file to anyname.xml.

5) Then create a class under our package and provide that name as EmployeeContent.
Write the following code in this class as follows:

package com.companyname.projectname.iocmodule;

public class EmployeeContent {
private String empname;
private String city;
private String country;
public EmployeeContent(){
System.out.println("Employee Content created");
}
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}

6) Edit anyname.xml file and add the following code:





hyderabad


india


Murthy




7) Similarly we have to write another main method class in our package as follows:
Name this class as TestClient

package com.companyname.projectname.iocmodule;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

public class TestClient {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BeanFactory container=new XmlBeanFactory(new ClassPathResource("anyname.xml"));
System.out.println("container created");
Object o=container.getBean("empbean");
EmployeeContent ec=(EmployeeContent)o;
System.out.println(ec.getCity());
System.out.println(ec.getCountry());
System.out.println(ec.getEmpname());
}

}


8) All our coding part is over. Then just Run it ,you will get the output as follows:

Employee Content created
hyderabad
india
Murthy


If you have any doubts send reply to me. Plz send feedback, your feedback is very useful for me.

Thanks&Regards
Murthy
murthy.mca53@gmail.com

If anybody want more theory and programs just send a message.