Get absolute value of float, int, double and long using Math.abs in Java

by Chaitanya Singh August 1, 2014

Description In this tutorial we are gonna see a program to find out the absolute values of float, int, double and long variables in java. public static double abs(double a): Returns the absolute value of a double value. public static float abs(float a): Returns the absolute value of a float value. public static long abs(long a): Returns the absolute value […]

Read the full article →

Boolean.hashCode() Method in Java

by Chaitanya Singh August 1, 2014

Description Program to get hash code for Boolean object. We are using hashCode() method of Boolean class for this purpose, it returns integer 1231 if this object represents true; returns the integer 1237 if this object represents false. Example class BooleanHashCodeEx { public static void main(String[] args) { // Boolean objects Boolean bObj, bObj2; // Assigning values to both the […]

Read the full article →

Compare boolean values in java – compareTo() Method

by Chaitanya Singh July 31, 2014

Description Program to compare boolean values. Example In this example we are going to see how to compare two boolean values by using compareTo() method of Boolean class. class CompareBooleanValues { public static void main(String[] args) { // Creating Objects of Boolean class Boolean bObj = new Boolean("true"); // Case does not matter Boolean bObj2 = new Boolean("FaLsE"); Boolean bObj3 […]

Read the full article →

Cast Boolean Object to boolean in Java – booleanValue() Method

by Chaitanya Singh July 31, 2014

Description Program to convert Boolean object to boolean primitive in java Example class BooleanObjToBooleanPrim { public static void main(String[] args) { // Creating an object of Boolean Class Boolean bObj = new Boolean("true"); // Case does not matter Boolean bObj2 = new Boolean("FaLsE"); /* Boolean object to boolean conversion * using booleanValue() method */ boolean bvar = bObj.booleanValue(); System.out.println("boolean value […]

Read the full article →

Convert boolean Primitive to Boolean object in Java

by Chaitanya Singh July 31, 2014

Description Program to convert boolean primitive to Boolean object Example class BooleanPrimToBooleanObj { public static void main(String[] args) { boolean bvar = true; /* Method 1: By passing boolean value to * the constructor of Boolean class */ Boolean bObj = new Boolean(bvar); System.out.println(bObj); /* Method 2: By passing boolean value to the * valueOf() method of Boolean class. */ […]

Read the full article →

Convert String to boolean primitive in Java: parseBoolean() method

by Chaitanya Singh July 31, 2014

Description How to convert String object to boolean primitive in Java. Example: Complete conversion code In this example we are converting string to boolean using parseBoolean() method of Boolean class. class StringToboolean { public static void main(String[] args) { // String Objects String str = "false"; // Case does not matter for conversion String str2 = "TrUe"; // String to […]

Read the full article →

Convert String Object to Boolean Object in Java

by Chaitanya Singh July 31, 2014

Description How to convert String object to Boolean object. Example In this example we are gonna see two methods of String to Boolean object conversion. class StringObjToBooleanObj { public static void main(String[] args) { // String Objects String str = "false"; // Case does not matter for conversion String str2 = "TrUe"; /* Method 1: Using Constructor - * Passing […]

Read the full article →

@Deprecated annotation in java

by Chaitanya Singh July 30, 2014

@Deprecated annotation is used for informing compiler that the particular method, class or field is deprecated and it should generate a warning when someone try to use any of the them. What is the meaning of “Deprecated”? A deprecated class or method is like that. It is no longer important. It is so unimportant, in fact, that you should no […]

Read the full article →

@Override annotation in Java

by Chaitanya Singh July 30, 2014

@Override annotation is used when we override a method in sub class. Generally novice developers overlook this feature as it is not mandatory to use this annotation while overriding the method. Here we will discuss why we should use @Override annotation and why it is considered as a best practice in java coding. Lets take an example first to understand […]

Read the full article →

Sorting float array in Java example

by Chaitanya Singh July 24, 2014

In this tutorial we are gonna learn how to sort a float array. import java.util.Arrays; class SortingFloatArrayExample { public static void main(String[] args) { // Creating a Float Array float[] floatArray = new float[] { 21.1f, 9.9f, 9.8f, 7.5f, 2.1f }; // Displaying Array before Sorting System.out.println("**Float Array Before Sorting**"); for (float temp: floatArray){ System.out.println(temp); } // Sorting the Array […]

Read the full article →

Sorting double array in Java example

by Chaitanya Singh July 24, 2014

import java.util.Arrays; class SortingDoubleArray { public static void main(String[] args) { // Creating a Double Array double[] doubleArray = new double[] { 13.1, 2.5, 2.2, 41.1, 1.1 }; // Displaying Array before Sorting System.out.println("**Double Array Before Sorting**"); for (double d: doubleArray){ System.out.println(d); } // Sorting the Array Arrays.sort(doubleArray); System.out.println("**Double Array After Sorting**"); for (double d: doubleArray){ System.out.println(d); } // Another […]

Read the full article →

Our Friend's website link : FromDev.com