Data Types in Java

Photo : Lee Campbell via
Want create site? With Free visual composer you can do it easy.

Today let’s see what the data types in Java are. Generally, we consider two types of data types: Primitive Data Types and Reference Data Types.

Since Java is a statically-typed language, variables must be declared before use. Declaring means you have to give the data type and name of the variable.

ex: int num ;

Initializing the variable...

Since the data type of the above variable is int ,the value it contains should be an int.
ex: int num = 10 ;

There are 8 Primitive Data Types in Java.
  1. byte
  2. short
  3. int
  4. long
  5. float
  6. double
  7. boolean
  8. char
In addition to these primitive data types Java also supports String type which contains character strings. Strings are represented with in double quotation marks ( ” ” ).
ex: String s = "string example";
When we declare a String, then an object will be created for it automatically in String Constant Pool of Heap. Once created the value of a String object will not be changed. (immutable)
String s1 = "ABC";

String s2 = "xyz";

s1 = s1 + "DE";
Data Types in Java - String
Dinuka Jayaweera
Dinuka is a Contributor at Nerdynaut Staff from Sri Lanka.
Did you find apk for android? You can find new Free Android Games and apps.
  • Fascinated
  • Happy
  • Sad
  • Angry
  • Bored
  • Afraid
Data Types in Java


  1. Porter

    May 1, 2017 at 1:11 am

    As a Newbie, I am continuously searching online for articles that can benefit me. Thank you

  2. Tamiko

    May 1, 2017 at 12:40 pm

    An fascinating dialogue is price comment. I think that it is best to write more on this matter, it might not be a taboo subject however generally people are not enough to speak on such topics. To the next. Cheers

  3. Ellsworth

    May 5, 2017 at 1:08 pm

    whoah this blog is magnificent i love reading your articles. Keep up the great work! You know, lots of people are looking around for this info, you could aid them greatly.

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular

​Disclaimer : Nerdynaut is a tech company which consists of professionals in respective academic fields in its functional team facing challenging roles to quench the thirst of knowledge in cyberspace. Every article and majority of artworks in this website are copyright of Nerdynaut 2017. After a written permission from the publisher, the original content can be reused or referred for promotional work of education without any modification. Expressions of mass media with intentional harm on Nerdynaut brand may be liable to criminal prosecution and civil claims for the damages caused.
Protected by Copyscape
* = required field

Copyright©2014-2017.The Nerdynaut. All Rights Reserved. A game-changing subordinate of Naut's Capital.
Made in Sri Lanka.

To Top