Quantcast
Channel: Java – StackTips
Browsing latest articles
Browse All 50 View Live

How to Trust All Certificates for HttpURLConnection in Android

The following code snippet will help you to disables the SSL certificate checking for new instances of HttpsURLConnection in Android. Note: You can use this code for testing purpose only and remove...

View Article


How to Calculate Image Dimensions in Java

The following code snippet shows how to calculate image dimension in java by reading the file from specified path. public static Dimension getImageDimension(final File path) { if (path == null) return...

View Article


How to Generate Unique File Name When Saving a File in Java

The following code snippet shows how to get unique file name when saving file in java. It first checks if already a file exist with the specified name, then it appends a number to end. public static...

View Article

How to Generate Gravtar Image Url from Email in Java

The following code snippet shows how to generate Gravatar URLs from email address. This utility method alows you to pass the size of your email. public String getGravatarUrl(String email, int size) {...

View Article

How to Add Click Listener to Android Switch

A Switch is a two-state toggle switch widget that can select between two options. Add Switch control to your Activity or Fragment layout as follows. <Switch android:id="@+id/wifi_switch"...

View Article


How to Programmatically Turn on and off Wifi on Android Device

Use the following code snippets to turn on and off wifi on Android devices. Switch toggle = (Switch) findViewById(R.id.wifi_switch); toggle.setOnCheckedChangeListener(new...

View Article

Sort Array ascending or descending using comparator in Java

Quick Java code snippet to sort Array ascending or descending using comparator in Java.

View Article

Linear / Sequential Search Example in Java

Quick Java code snippet to show Linear / Sequential Search.

View Article


Insertion sort example in Java

Code snippet to sort array using insertion sort algorithm in java.

View Article


String Concatenation Test in Java

Sample Java program to concatenate two strings using plus (+) concatenation operator. public class StringConcatination { public static void main(String args[]) { String str1 = "Hello"; String str2 =...

View Article

Reverse Java string using recursive method

Quick Java code snippet to reverse a string using recursive method.

View Article

How to change upper case string to lower case in Java

Quick Java code snippet to change case of a String in Java. It uses toUpperCase() and toLowerCase() methods present in java.lang.String class to convert the case.

View Article

How to Compare Two Strings in Java

Sample program that accept values form user and compare two strings. import java.util.Scanner; class CompareStrings { public static void main(String args[]) { String str1, str2; Scanner in = new...

View Article


String length and trim string in java

Code snippet explains the usage of String class length and trim() method. The length() method returns the length of this string. The trim() method returns a copy of the string, with leading and...

View Article

How to Test String Equality in Java ?

Sample program to test String Equality in Java using equals to (==) operator and String.equals() method. public class StringEqualsTest { public static void main(String[] args) { String str1 = "hello";...

View Article

Browsing latest articles
Browse All 50 View Live