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

Java Data Types

Uploaded by

mangatangat
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)
7 views1 page

Java Data Types

Uploaded by

mangatangat
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
You are on page 1/ 1

 Menu   Log in

L  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 (who


float myFloatNum = 5.99f; // Floating poi
char myLetter = 'D'; // Character
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 ›

W3schools Pathfinder
Track your progress - it's free!

Sign Up Log in

ADVERTISEMENT

COLOR PICKER



ADVERTISEMENT


PLUS

SPACES

GET CERTIFIED

FOR TEACHERS

FOR BUSINESS

CONTACT US

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS 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
W3.CSS 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 ACADEMY

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-2024 by Refsnes Data. All


Rights Reserved. W3Schools is Powered by
W3.CSS.

You might also like