Thursday, December 1, 2016

Find first non repeated character in a string


public class FirstNonRepeatedChar {

public static void main(String[] args) {
String input = "InputTextYOUWant";
char[] c = input.toCharArray();
int count = 0;
for (int i = 0; i < c.length; i++) {
for (int j = i + 1; j < c.length; j++) {
if (String.valueOf(c[i]).toLowerCase().equals(String.valueOf(c[j]).toLowerCase())) {
count++;
break;
}

}

if (count == 0) {

System.out.println("Non Repeated Charatcher is:"+c[i]);
//if you want all non repeated values just comment below break
break;
} else {
count = 0;
}

}

}
}

Find Continious SubArray With Maximum Sum Problem

public class MaxSumSubArray {

public static void main(String[] args) {
// sample input elements
int[] intArr = { 0, -1, 2, -1, 3, -1, 2, 0, 0, 0 };
findMaxSubArray(intArr);
}

public static void findMaxSubArray(int[] inputArray) {

int maxStartIndex = 0;
int maxEndIndex = 0;
// intializing maxSum to least possible integer
int maxSum = Integer.MIN_VALUE;

int cumulativeSum = 0;
int maxStartIndexTilNow = 0;

for (int currentIndex = 0; currentIndex < inputArray.length; currentIndex++) {

int eachArrayItem = inputArray[currentIndex];

cumulativeSum += eachArrayItem;

if (cumulativeSum > maxSum) {
maxSum = cumulativeSum;
// startindex is the next index of last element till which
// cumulative sum < 0
maxStartIndex = maxStartIndexTilNow;
// assign end index with current index for every increase in
// cumulative sum
maxEndIndex = currentIndex;
} else if (cumulativeSum < 0) {
maxStartIndexTilNow = currentIndex + 1;
cumulativeSum = 0;
}
}

System.out.println("Maximum sum         : " + maxSum);
System.out.print("Continious array with Maximum Sum is : {");

for (int i = maxStartIndex; i <= maxEndIndex; i++) {
if (i != maxEndIndex)
System.out.print(inputArray[i] + ",");
else
System.out.print(inputArray[i]);

}
System.out.print("}");

}

}

Friday, November 11, 2016

How to get check Hash key used in specific Android Project

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "your App Package goes here",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
           // Toast.makeText(this, "" + Base64.encodeToString(md.digest(), Base64.DEFAULT), Toast.LENGTH_LONG).show();
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }
}

Tuesday, September 27, 2016

How to Use GSON in Android Studio

To add GSON to your project 

just add 

dependencies {compile 'com.google.code.gson:gson:2.3'}

then to add GSON plugin to your Android studion IDE
preset CTRL+ALT+S to open settings 
then go to plugins
then search for GSON(if you dont find it you need to download GSONFORMAT.jar)
once you install and restart Studio
Just create a empty class ALT+Insert  + ALT+S will open a window 
in which expected JSON you will paste
according to that JSON format your class will be created.

To use in code
Gson gson= new Gson();
Yourclass ref=gson.fromJson(json,YourClass.class);
String item=   ref.getName();

Sunday, October 11, 2015

What's new in Android 6.0 Marshmallow...??

This release introduces new power-saving optimizations for idle devices and apps. 
Doze:
If a user unplugs a device and leaves it stationary, with its screen off, for a period of time, the device goes intoDoze mode, where it attempts to keep the system in a sleep state. In this mode, devices periodically resume normal operations for brief periods of time so that app syncing can occur and the system can perform any pending operations.
App Standby:
App Standby allows the system to determine that an app is idle when the user is not actively using it. The system makes this determination when the user does not touch the app for a certain period of time. If the device is unplugged, the system disables network access and suspends syncs and jobs for the apps it deems idle.

This release removes support for the Apache HTTP client. Use the HttpURLConnectionclass instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption.

To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:
android {
useLibrary 'org.apache.http.legacy'
}

BoringSSL


Android is moving away from OpenSSL to the BoringSSL
If you’re using the Android NDK in your app, don't link against cryptographic libraries that are not a part of the NDK API, such as libcrypto.so and libssl.so. These libraries are not public APIs, and may change or break without notice across releases and devices. In addition, you may expose yourself to security vulnerabilities. Instead, modify your native code to call the Java cryptography APIs via JNI or to statically link against a cryptography library of your choice.

Access to Hardware Identifier


To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and theBluetoothAdapter.getAddress() methods now return a constant value of 02:00:00:00:00:00.

Notifications


This release removes the Notification.setLatestEventInfo() method. Use the Notification.Builder class instead to construct notifications. To update a notification repeatedly, reuse the Notification.Builder instance. Call thebuild() method to get updated Notification instances.


source:developer.android.com


Thursday, September 24, 2015

Android Studio Shortcuts

Navigation Shortcuts

Shortcut DescriptionAndroid Studio Shortcut
Go to classCtrl + N
Go to fileCtrl + Shift + N
Navigate open tabsALT + Left-Arrow; ALT + Right-Arrow
Lookup recent filesCTRL + E
Go to lineCTRL + G
Navigate to last edit locationCTRL + SHIFT + BACKSPACE
Go to declarationCTRL + B
Go to implementationCTRL + ALT + B
Go to sourceF4
Go to super ClassCTRL + U
Show Call hierarchyCtrl + Alt + H
Search in path/projectCTRL + SHIFT + F

Programming Shortcuts

Shortcut DescriptionAndroid Studio Shortcut
Reformat codeCTRL + ALT + L
Optimize importsCTRL + ALT + O
Code CompletionCTRL + SPACE
Issue quick fixALT + ENTER
Surround code blockCTRL + ALT + T
Rename and refactorShift + F6
Line Comment or UncommentCTRL + /
Block Comment or UncommentCTRL + SHIFT + /
Go to previous/next methodALT + UP/DOWN
Show parameters for methodCTRL + P
Quick documentation lookupCTRL + Q

General Shortcuts

Shortcut DescriptionAndroid Studio Shortcut
Delete lineCTRL + Y
Safe DeleteAlt + DELETE
Close Active TabCTRL + F4
Build and runSHIFT + F10
BuildCTRL + F9
All purpose (Meta)ShortcutCTRL + SHIFT + A

Thursday, March 19, 2015

How to see Classes of Jar File In Eclipse

Install  JadClipse Plugin

Step1: Go to Eclipse Help
Step2: Click on Eclipse market Place              
Step3: Type JadClipse and Go
Step4: click Install it will ask to restart Eclipse and it's done