** Exploring Java.lang**
  • The classes and interface are defined by java.lang

  • Classes and interfaces are fundamental to virtually all of Java program.

=> Boolean,Enum, Process, String,
Byte, Float, ProcessBuilder, StringBuffer,
Character, InheritableThreadLocal, ProcessBuilder.Redirect, StringBuilder

=>Character.Subset,Integer,Runtime,System,
Character.UnicodeBlock,Long,RuntimePermission,Thread
,Class,Math,SecurityManager,ThreadGroup

  • java.lang defines the following interfaces:

=>Appendable,Cloneable,Readable
,AutoCloseable,Comparable,Runnable,CharSequence,IterableThread.UncaughtExceptionHandler

Primitive Type Wrappers:

  • Java uses primitive types, such as int and char, for performance reasons.
  • These data types are not part of the object hierarchy.
  • They are passed by value to methods and cannot be directly passed by reference
  • At time you will need to create an object representation for the one of the primitive types.

Number:

  • The abstract class number define superclass that implement the class that wrap the numeric types as byte,short,int,long,float and double.
  • These example has,

    byte byteValue( )

    double doubleValue( )

    float floatValue( )

  • The values returned by these methods might be rounded, truncated, or result in a “garbage”

  • value due to the effects of a narrowing conversion.

Double and Float:

  • Double and Float are wrappers for floating-point values of type double and float, respectively.
  • The constructors for Float are shown here:

    Float(double num)

    Float(float num)

Method Description

1.double doubleValue( ) Returns the value of the invoking object as a double.

2.boolean equals(Object FloatObj) Returns true if the invoking Float object is

equivalent to FloatObj. Otherwise, it returns false.

3.static int floatToIntBits(float num) Returns the IEEE-compatible, single-precision bit

pattern that corresponds to num.

4.static int floatToRawIntBits(float num) Returns the IEEE-compatible single-precision bit

pattern that corresponds to num. A NaN value is

preserved.

5.float floatValue( ) Returns the value of the invoking object as a float.

6.int hashCode( ) Returns the hash code for the invoking object.

7.static int hashCode(float num) Returns the hash code for num. (Added by JDK 8.)

8.static float intBitsToFloat(int num) Returns float equivalent of the IEEE-compatible,

single-precision bit pattern specified by num.

  • The method defined by double as,

Method Description

1.byte byteValue( ) Returns the value of the invoking object as a byte.

2.static int compare(double num1,double num2) Compares the values of num1 and num2.

Returns 0 if the values are equal.

Returns a negative value if num1 is less than num2.

Returns a positive value if num1 is greater than num2.

3.int compareTo(Double d ) Compares the numerical value of the invoking
object with that of d. Returns 0 if the values are equal.

Returns a negative value if the invoking object has a lower value.

Returns a positive value if the invoking object has a greater value.

4.static long doubleToLongBits(double num) Returns the IEEE-compatible, double-precision bit pattern that corresponds to num.

5.static long doubleToRawLongBits(double num) Returns the IEEE-compatible double-precision bit pattern that corresponds to num. A NaN value is preserved.

6.double doubleValue( ) Returns the value of the invoking object as a double.

7.boolean equals(Object DoubleObj) Returns true if the invoking Double object is equivalent to DoubleObj.

Otherwise, it returns false.

Byte, Short, Integer, and Long:

  • Variants of these methods allow you to specify the radix, or numeric base, for conversion.
  • Common radixes are 2 for binary, 8 for octal, 10 for decimal, and 16 for hexadecimal.

Converting numbers to and from Strings:

  • In this common programming are converting the string representation of a number into internal,binary format.
  • byte,short,integer and long classes provide the parsebyte,parseint and parseIong respectively.
  • The program use parseint().It uses to sums a list of integers entered by the user.
  • And it reads the integer by readline() & parseint() to convert the strings into int equivalents.

Example:

/* This program sums a list of numbers entered by the user.
It converts the string representation of each number into an int using parseInt().*/
import java.io.*;
class ParseDemo {
public static void main(String args[])
throws IOException
{
// create a BufferedReader using System.in
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));
String str;
int i;
int sum=0;
System.out.println("Enter numbers, 0 to quit.");
do {
str = br.readLine();
try {
i = Integer.parseInt(str);
} catch(NumberFormatException e) {
System.out.println("Invalid format");
i = 0;
}
sum += i;
System.out.println("Current sum is: " + sum);
} while(i != 0);
}
}

To convert the whole number into decimal string therefore string is used.byte,char are defined as stringbyte,stringchar.

Example:

/* Convert an integer into binary, hexadecimal,
and octal.
*/

class StringConversions {

public static void main(String args[]) {

int num = 19648;

System.out.println(num + " in binary: " +

Integer.toBinaryString(num));

System.out.println(num + " in octal: " +

Integer.toOctalString(num));

System.out.println(num + " in hexadecimal: " +

Integer.toHexString(num));

}

}

Character:

  • The character is wrapped around as char.

  • Its general form or constructor is

character (char ch)

By call charvalue()

char charValue() so it returns the character.

results matching ""

    No results matching ""