Thursday, November 24, 2016

Numbers in Java - integer double byte float uses

Numbers in Java - integer double byte float uses

      numbers system in java

        Data Types Numbers in Java


For numbers we use primitive data types like: int, short, byte, long, double, float, decimal etc. when we come across development process then we should need to used object instead of primitive data types. So, java provide some wrapper classes which are the following.
 integer double byte float uses
o   Integer.
o   Float
o   Long
o   Double
o   Byte
o   Short
These all wrapper classes are subclasses of the abstract class Number. Converting primitive data types into object is called boxing and converting object into primitive data types id called unboxing.
  integer double byte float uses

Example:

Numbers in Java - integer double byte float uses
 integer double byte float uses

Class Methods Number in Java

Here is the list of number class methods

Method Name    Description

xxxValue()     Convert the current value into xxx data types
                       Integer x = 10;byte = x.byteValue();

compareTo()   Compare the current value this argument value.
                       Interger x = 15;
                       x.compareTo(10); // return -1 b/c argument value less
                      than the current value
                      x.compareTo(15); // return 0 b/c argument value equal to
                      the current value
                      x.compareTo(20); // return 1 b/c argument value greater than
                       the current value

equals()      equals method returns true if and only if argument value and data type
                   is  equal to current value
                  Interger x = 15;   Interger y = 15;x.equals(y); //return true;

toString()      This method converts the wrapper class object into string
                      Interger x = 15;
                     x.toString(); or Interger.toString(x) // both
                    return string object

parseXXX();   This method converts the String object into respected wrapper class
                         int a = Integer.parseInt(“5”);
                        double b = Double.parseDouble(“10”);

abs()         This method is used for absolute value of the argument and this
                  method use Math class: Integer x = -10;
                  System.out.println(Math.abs(x)); // 10

ceil()        This method returns the smallest value which is near to
                 the argument value
                System.out.print(Math.ceil(50.75)); // 50.0
                System.out.print(Math.ceil(40)); // 40.0

floor()       This method returns the largest value which is near to the argument value
              System.out.print(Math.floor(50.75)); // 51.0
              System.out.print(Math.floor (40)); // 40.0

rint()        This method returns the closet value that is in arguments but return in
                double
                System.out.print(Math.rint(50.75)); // 51.0
                System.out.print(Math.rint(40)); // 40.0

round()       This method work same like rint() method but it return integer
              System.out.print(Math.round(50.75)); // 51
              System.out.print(Math.round(40)); // 40

min(arg1, arg2)  Return Minimum value between two given arguments
                 Math.min(15.4, 15.0); // 15.0

max(arg1, arg2)  Return Maximum value between two given arguments
                 Math.max(15.4, 15.0); // 15.4

exp(arg0)     Return the base of natural logarithm, e, to the power of the argument
              Math.exp(11.635); // 112983.831

log(arg0)     Return the natural logarithm of the argument
              Math.log(11.635); //2.454

pow(arg0, arg1)  First argument is value and second argument is the power raised
                 Math.pow(2,3); // 8

sqrt(arg0)       This method returns the square root of argument value
                 Math.sqrt(4); // 2

random()       This method generates some random number
                      Math.random(); // 0.22374096634063045.
                       integer double byte float uses
         
         Characters
Same like numbers class for primitive char data type java provide wrapper class Character. This Character wrapper class is more useful at development process. integer double byte float uses

Example:
Character a = ‘s’;

Escape Sequence
Escape sequence are a special type of characters


Charater    Description
\t                Inserts a tab in the text at this point.
\b               Inserts a backspace in the text at this point.
\n              Inserts a newline in the text at this point.
\r               Inserts a carriage return in the text at this point.
\f               Inserts a form feed in the text at this point.
\'                Inserts a single quote character in the text at this point.
\"               Inserts a double quote character in the text at this point.
\\               Inserts a backslash character in the text at this point.
                                           integer double byte float uses

Character Methods In Java


Methods       Description


isLetter()    It returns true if character is any letter
                   System.out.println(Character.isLetter(‘c’));//true

isDigit()     It returns true if character is any number
                  System.out.println(Character.isDigit(‘5’));//true

isWhiteSpace() 
                           It returns true if character is any white space
                          System.out.println(Character.isWhiteSpace(‘ ’));//true

isUpperCase()  It returns true if character is in upper case
                          System.out.println(Character.isupperCase(‘A’));

isLowerCase()  It returns true if character is in lower case
                           System.out.println(Character.isLowerCase(‘a’));//true

toUpperCase()  It will convert the character into Upper case
                           System.out.println(Character.isupperCase(‘a’));//A

toLowerCase()  It will convert the character into Lower case

                           System.out.println(Character.isupperCase(‘A’));//a.
                                           integer double byte float uses

No comments:

Post a Comment