Data Types in Java

Java has a variety of data types that you can use to store different kinds of information in your programs. The following are the types of data types in Java:

  • Primitive
  • Non-Primitive

Primitive Data Types

  • byte: 8-bit integer (values from -128 to 127)
  • short: 16-bit integer (values from -32,768 to 32,767)
  • int: 32-bit integer (values from -2^31 to 2^31-1)
  • long: 64-bit integer (values from -2^63 to 2^63-1)
  • float: 32-bit floating point
  • double: 64-bit floating point
  • char: Single 16-bit Unicode character (e.g., ‘a’, ‘*’, etc.)
  • boolean: Represents true or false

Non-Primitive Data Types

  • String: A sequence of characters, e.g., “Amit Diwan”
  • Array: A collection of elements of the same type.
  • Class: Templates for creating objects and defining object data types and methods.
  • Interface: An abstract type used to specify a behavior that classes must implement.
  • Object: The root class of the Java class hierarchy. All classes inherit from Object.

Let us now see an example and work with some data types:

Here is the output:


If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

Java Tutorial | Learn Java Programming
Scope of Variables in Java
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading