Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Simon Jensen
484 PointsAm i right or wrong when I say this about String and Variable
Am i right or wrong when I say:
Is a string a Datatype? Yes, a datatype can be: Numbers, Text, Bits, Boolean (true or false)
So a string is a form of variable there uses text.
Another way of saying it:
A string is a datatype from variables.
2 Answers
Samuel Ferree
31,723 PointsJava differentiates between Classes, and primitive datatypes.
Abstractly, both are datatypes in that they define the type of data referenced by a variable. However, in the context of JAVA, when talking about "datatypes" people are most often referring to primitive datatypes, which doesn't include Classes.
So you might be technically correct, but depending on which domain you're speaking in. you could be causing confusion. In the Java world. Strings are classes that inherit from Object. This sets them apart from primitive datatypes like int, char, or boolean.
Note that there are classes like Integer, and Boolean. These function like int and boolean, but are classes and as such inherit from and are Objects. It's confusing... I know. sadly, decisions were made, and Java must stick with them for the sake of backwards compatibility.
Pedro Cabral
Full Stack JavaScript Techdegree Student 23,916 PointsThe JDK provides the String class which in turn makes heavy use of the primitive type char to store data as an array of characters.
Simon Jensen
484 Pointswhat is JDK?