0% found this document useful (0 votes)
13 views1 page

Java Data Types Explained

The document explains Java data types, which are categorized into primitive and non-primitive types. It details the eight primitive data types, including byte, short, int, long, float, double, boolean, and char, along with their sizes and descriptions. Additionally, it provides examples of variable declarations and an exercise for practice.

Uploaded by

desmondavi0013
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Java Data Types Explained

The document explains Java data types, which are categorized into primitive and non-primitive types. It details the eight primitive data types, including byte, short, int, long, float, double, boolean, and char, along with their sizes and descriptions. Additionally, it provides examples of variable declarations and an exercise for practice.

Uploaded by

desmondavi0013
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

 Menu   Log in

CSS JAVASCRIPT SQL PYTHON JAVA PH

Java Data Types


‹ Previous Next ›

Java Data Types


As explained in the previous chapter, a
variable in Java must be a specified data type:

Example Get your own Java Server

int myNum = 5; // Integer


float myFloatNum = 5.99f; // Floating
char myLetter = 'D'; // Characte
boolean myBool = true; // Boolean
String myText = "Hello"; // String

Try it Yourself »

Data types are divided into two groups:

Primitive data types - includes byte ,


short , int , long , float , double ,
boolean and char
Non-primitive data types - such as
String , Arrays and Classes (you will
learn more about these in a later chapter)

Primitive Data Types


A primitive data type specifies the size and
type of variable values, and it has no additional
methods.

There are eight primitive data types in Java:

Data Size Description


Type

byte 1 Stores whole numbers from


byte -128 to 127

short 2 Stores whole numbers from


bytes -32,768 to 32,767

int 4 Stores whole numbers from


bytes -2,147,483,648 to
2,147,483,647

long 8 Stores whole numbers from


bytes -9,223,372,036,854,775,808
to
9,223,372,036,854,775,807

float 4 Stores fractional numbers.


bytes Sufficient for storing 6 to 7
decimal digits

double 8 Stores fractional numbers.


bytes Sufficient for storing 15
decimal digits

boolean 1 bit Stores true or false values

char 2 Stores a single


bytes character/letter or ASCII
values

Test Yourself With Exercises

Exercise:
Add the correct data type for the following
variables:

myNum = 9;
myFloatNum = 8.99f;
myLetter = 'A';
myBool = false;
myText = "Hello World";

Submit Answer »

Start the Exercise

‹ Previous Next ›

ADVERTISEMENT

COLOR PICKER



ADVERTISEMENT


SPACES

UPGRADE

NEWSLETTER

GET CERTIFIED

REPORT ERROR

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
[Link] Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
[Link] Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
[Link] Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples

Get Certified
HTML Certificate
CSS Certificate
JavaScript Certificate
Front End Certificate
SQL Certificate
Python Certificate
PHP Certificate
jQuery Certificate
Java Certificate
C++ Certificate
C# Certificate
XML Certificate

   
FORUM ABOUT
W3Schools is optimized for learning
and training. Examples might be
simplified to improve reading and
learning. Tutorials, references, and
examples are constantly reviewed to
avoid errors, but we cannot warrant
full correctness of all content. While
using W3Schools, you agree to have
read and accepted our terms of use,
cookie and privacy policy.

Copyright 1999-2023 by Refsnes


Data. All Rights Reserved. W3Schools
is Powered by [Link].

You might also like