-3

Hi I am new to java have and wondering why is that String is a class and (int,double,etc.)are not.. is there a big different for me they are all the same string read letter int read integer.

user2242573
  • 81
  • 1
  • 2
  • 7

5 Answers5

2

int, double, etc. are primitive data types and there are equivalent classes for these data types in Java namely Integer, Double, etc. They are known as wrapper classes.

Please read up more on Java wrapper classes.

Vaibhav Desai
  • 2,618
  • 1
  • 16
  • 16
1

String is a class because it usually represents a character array in most langauges. And supports its own functions.

Primative types sunch as int, double, etc. have no support for functions and are stored in memory directly, with a size corresponding to it's limits.

Strings have no practical limits.

Consider String class methods, and instance methods, ints, doubles, etc dont have these.

j_mcnally
  • 6,928
  • 2
  • 31
  • 46
0

String is an object, it isn't a primitive type at all, just an array of chars.

Why is there no primitive type for String?

Community
  • 1
  • 1
Wilts C
  • 1,720
  • 1
  • 21
  • 28
0

int, double, char are primitive types, where as String is a Class. There isn't going to be any different for you.

viclim
  • 959
  • 8
  • 16
0

Yes, String is a class and that class contains methods which allow it to be manipulated in many ways. The primitives also have their own classes (called wrapper classes). Which as you know now, allow them too to be manipulated.

One thing to remember is, Java has naming conventions the one applying to your question is, you always name a class with a capital letter.

Joban
  • 1,318
  • 7
  • 19