Data Types in Java with example

Every variable in Java has a data type. Java Data Types specify the size and type of values that can be stored. There are a variety of data types available in Java. There are mainly two types of Java Data Types.

  • Primitive Data Types or Built-in data types.
  • Non-Primitive Data Types or Reference data types
  • Primitive Data Types are classified into two category :

  • Numeric
  • Non-Numeric
  • Numeric Data Types are two types

  • Integer Data Type
  • Floating-Point Data Type
  • Non-Numeric Data Types are also two types

  • Character Data Type
  • Boolean Data Type
  • Java Data Types

  • Integer Data Type : Integer data types can hold whole numbers such as 25, -40, 2456. The size of the values that can be stored depends on your choose’s integer data types. Java supports four types of integer data type and they are byte, short, int and long. Java does not support unsigned integer data types. So, all java values are signed that means those values can be positive or negative.
  • Floating-Point Data Type : Floating-Point Data Type can also hold whole numbers containing fractional parts such as 25.6675. There are two types of Floating-Point Data Types are given as follows :
    float

  • Float : The float type values are single precision numbers such as 3.142857. A single precision number using 6 decimal digits.
  • Double : Double types values are represent double precision number such as 3.142857142857.
    A double-precision number using 12 decimal digits.

  • Character Data Type : Java provides a character data type that is called char. The char type assumes a size of 2 bytes, but it can hold only a single character.
  • Boolean Data Type : Boolean Data Type is used when we want to test a particular condition during the execution of the program. There are only two values in Boolean Data Types such as true or false.Boolean data type is denoted by the keyword boolean and it uses only one bit of storage.

    Recommended Posts:

    Java
        1. Features of Java
        2. Java Program Structure
        3. Command Line Arguments in Java
        4. Difference between java and c++
        5. Data Types in Java with example
        6. Scope of Variables in Java
        7. Operators in Java
        8. Looping Statement in Java
        9. Objects and Classes in Java
        10. Constructors in Java with example
        11. Method Overloading in Java with example
        12. Method Overriding in Java with example
        13. Static Members in Java with Program
        14. Abstract Class in Java with Program
        15. final, finally and finalize in Java
        16. Dynamic Method Dispatch in Java | Runtime Polymorphism
        17. Nesting of Methods in java
        18. Inheritance in Java with example
        19. Java Access Modifiers – Public, Private, Protected, Friendly
        20. Array in Java
        21. Strings in Java | String Methods
        22. StringBuffer class in Java with Program
        23. Vector in Java | Vector Methods
        24. Wrapper Classes in Java With Program
        25. Autoboxing and Unboxing in Java With Program
        26. enum in Java with Program
        27. Java Annotation
        28. Interface in Java with Program
        29. Difference between Class and Interface in Java
        30. Implementing Interfaces in Java
        31. Java Program to implement Multiple Inheritance using Interface
        32. Difference Between Multithreading and Multitasking in Java
        33. Life Cycle of Thread in Java with Diagram
        34. Synchronization of threads in Java
        35. Java Thread Priority
        36. Java Program to Implement Multithreading using Runnable Interface
        37. Inter-thread Communication in Java
        38. Suspend, Resume and Stop Thread in Java
        39. Types of Error in Java
        40. Exceptions in Java
        41. Exception Handling in Java with examples
        42. Java Package
        43. Static import in Java
        44. Design a package to contain class Student and package contain interface Sports