Difference Between Two String

The following JAVA PROGRAM calculates the difference between two strings provided the initial contents in both the strings remain the same.

 

The logic behind this program is to consider the lengths of the two strings.

If the first string is having larger length, then it is divided to get the difference and same goes for the second string.

 

Here is the sample code snippet.

package samples;

public class DifferenceBetweenTwoStrings {

public static void main(String[] args) {

String one = “this is first string”;

String two = “this is first string with some extra content”;

if (one.length() > two.length()) {

System.out.println(one.substring(two.length() – 1));

} else if (two.length() > one.length()) {

System.out.println(two.substring(one.length() – 1));

} else {

System.out.println(“something went wrong”);

}

}
}

Log Structured Merge Trees

Log Structured Merge Trees

The LSM-tree is a data structure with an attractive performance characteristic.

The two structures which are used here are C0 and C1 and there is a special synchronization between the two structures.

The logic of this LSM tress is used in the designing of the NoSQL Databases like HBase, SQLite4 and Cassandra. The LSM trees are a hybrid data structure.
It contains two tree-like structures mainly known as C0 and C1. Among these two, C0 is smaller and resides completely onto memory while C1 is larger in size and it resides on disk.

The new records get inserted onto C0 first and as soon as this component exceeds a certain size threshold, those records are flushed to C1 making space for new entries in C0.

 

CALCULATE DIFFERENCE BETWEEN TWO DATES

CALCULATE DIFFERENCE BETWEEN TWO DATES

This program calculates the difference between two dates. This difference which is basically in milliseconds is then converted into the number of days, hours, minutes and seconds.

package samples;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DifferenceBetweenTwoDates{
public static void main(String[] args) {
String dateStart = “01/14/2012 09:29:58”;
String dateStop = “01/15/2012 10:31:48”;

// HH converts hour in 24 hours format (0-23), day calculation
SimpleDateFormat format = new SimpleDateFormat(“MM/dd/yyyy HH:mm:ss”);

Date d1 = null;
Date d2 = null;

try {
d1 = format.parse(dateStart);
d2 = format.parse(dateStop);

// in milliseconds
long diff = d2.getTime() – d1.getTime();

long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000);
System.out.println(“realdifference : ” + diff);
System.out.print(diffDays + ” days, “);
System.out.print(diffHours + ” hours, “);
System.out.print(diffMinutes + ” minutes, “);
System.out.print(diffSeconds + ” seconds.”);

} catch (Exception e) {
e.printStackTrace();
}

}
}

Designing my first android app

ANDROID APPLICATION DEVELOPMENT FOR BEGINNERS

1) INSTALLING ANDROID SDK

You will need the text editor for designing your android application. ECLIPSE IDE is recommended as I am working with it. Trust me guys, it’s very easy to use the eclipse in order to design your android apps.

You can download the eclipse IDE from the below link

https://dl.google.com/android/adt/adt-bundle-windows-x86-20131030.zip

It is totally safe to download the bundle from the above link, don’t use any other link, it might be malicious.

2) INSTALLING ADT PLUGIN for Eclipse

This plugin is required to integrate your eclipse IDE with the android SDK. With the help of this plugin, you can make your eclipse to design apps for android platform.

This ADT Plugin is installed into the eclipse IDE.

This should be done once you extract the above ADT bundle and start the eclipse from the same.

This plugin can be installed in simple steps as follows.

1) Start eclipse

2) Go to help in toolbar

3) Click on install new software

4) Click on add on top right corner

5) A new screen will appear, put ADT Plugin as the Name and the Location should be

http://dl-ssl.google.com/android/eclipse/

The process of installing the ADT Plugin will start; wait till this process gets over. At the end you will have to restart the eclipse.

install new softwarehttp

5 items selected accept

3) ADD ANDROID VIRTUAL DEVICE

This can be done in the following way

1)      Open eclipse IDE

2)      Go to Windows in Eclipse Toolbar and click on Android Virtual Device Manager

3)      New window will pop up.

4)      Click on new

5)      Enter the name of the Virtual Device in AVD Name, select the proper device which you want to create virtually

AVD

 

4) CREATE ANDROID PROJECT

 

Now it is the time to create your first android app. To do so, you need to create the project in eclipse.

 

Follow the simple steps to do this

1. Click on File in Eclipse Toolbar and select Android Application Project

2. Enter the name of the project in proper manner as shown below

 

3. The newly created android project will be shown in the left pane.

 

One thing to note over here is that plenty of repository folders and contents get created automatically. These all are created in order to enable you to create android apps in smooth manner and every repository folder is related to each other, so DON’T EVER DELETE ANY ONE OF THE REPOSITORY FOLDERS.

 

 avd successactivity selection   create anroid project create project 

5) PROGRAMMING

package com.example.second;

import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;

public class MainActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

TextView textView = new TextView(this);

textView.setText(“Hello World This is my first android app”);

setContentView(textView);

}

}

default screen

6)      EXECUTION SCREENSHOTS

execution1

execution