Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's This compile error?

 
Gary Farms
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I compile the following Gary.java program, I get an error stating: Incompatible type for declaration. Can't convert java.lang.String to string. Why??? Here's my simple Gary.java program:

public class Gary
{
static public void main(String args[])
{
string tmp = "boy";
}
}
Also, what class(if any) are the primitives such as integer in?
Insn't everything a subclass of class Object?
 
Bill Graf
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String needs a capital S.
Originally posted by Gary Farms:
When I compile the following Gary.java program, I get an error stating: Incompatible type for declaration. Can't convert java.lang.String to string. Why??? Here's my simple Gary.java program:

public class Gary
{
static public void main(String args[])
{
string tmp = "boy";
}
}
Also, what class(if any) are the primitives such as integer in?
Insn't everything a subclass of class Object?

 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Capitalize the word String. Java is case sensitive.
Primitives are called primitives because they are not objects. So you will not find them in any class.
Java is ALMOST a pure OO language, except for the primitives which were allowed for efficiency, and for the String Literal behavior which is a shortcut and adds efficiency, and arrays which have some specific non-OO behavior other than that it is completely OO.
Notice that C++ is not a pure OO language, VB is not even CLOSE, etc.
There ARE a few pure OO languages out there though.
 
Christine Alfano
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to declare a String the 'S' must be capitalized. Make the change and your compilation error will disappear.
Originally posted by Gary Farms:
When I compile the following Gary.java program, I get an error stating: Incompatible type for declaration. Can't convert java.lang.String to string. Why??? Here's my simple Gary.java program:

public class Gary
{
static public void main(String args[])
{
string tmp = "boy";
}
}
Also, what class(if any) are the primitives such as integer in?
Insn't everything a subclass of class Object?

 
Steve Lemay
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to deal with primatives like objects then use the wrapper classes, you can find these in the java.lang package, there called the same as primative's but with capitilization (ie Integer).
And yes all classes are ultimatley subclasses of object
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic