Take the 2-minute tour ×

I'm really used to using "string" instead of "String" in C#. I was wondering what I can do to be able to do this in Java.

I'm using Eclipse's Java EE IDE if that matters.

share|improve this question

closed as not a real question by Oliver Charlesworth, Don Roby, duffymo, Pshemo, Graviton Jul 12 '12 at 2:36


this is a terrible idea. –  Hunter McMillen Jul 12 '12 at 0:29
This is not recommended. –  Zéychin Jul 12 '12 at 0:29
I would wager that it's not possible (short of hacking the IDE/compiler). And even it were, it's a really silly idea. –  Oliver Charlesworth Jul 12 '12 at 0:30
It guarantees that no one else will ever want to work on your code. Would you have written "String" in C#? If not, why change just for Java? Write in the idiom the language demands or go back to C#. –  duffymo Jul 12 '12 at 0:45
Just write String. Or you could write a pre-processor and run all your source code through that. Call it Java#. You could change more of the language. In fact, you could write a compiler and change the entire language, and call it Scala, or Clojure, or Groovy. If you want to target the JVM and you don't want to write Java, there are other languages that run on the JVM. But if you want to write in Java, then write in Java. –  David Conrad Jul 12 '12 at 1:09

5 Answers 5

Don't. Just use String. You'll get use to it.

share|improve this answer

Even if it were not a bad idea, I don't think this is possible. There are no typedefs in java, so you cannot alias a class. In addition String is a final class and thus cannot be extended -- meaning you can't extend String and call it string.

share|improve this answer

String is a wrapper proper first-class Class in Java, and there's no primitive data-type of string in java, unlike in C#.

Coding conventions in Java states that classes need to start with an uppercase letter. So, no you can't rename it.

share|improve this answer
This is incorrect. String is a proper first-class Class in Java: it is not a "wrapper" for anything. Indeed, in modern JVMs, the String class is implemented completely in Java ... no native code. –  Stephen C Jul 12 '12 at 0:36
Thanks for the save there. I almost forgot wrapper classes are made for primitive data-types like int -> Integer. –  Ruel Jul 12 '12 at 0:38
The string class isn't primitive in C#, either, but it's got a name that indicates that's it's a basic type, which is nice. Still, write C# when you're writing C#, and Java when you're writing Java. Horses for courses. –  David Conrad Jul 12 '12 at 1:06

This is not possible:

  • Java does not allow you to rename or alias types. Each (class) type has one and only one FQN (i.e. fully qualified name). Any type with a different FQN is a different type.

  • The String type is declared as final so you couldn't even create a convenience subclass. (And even if it did, it wouldn't help because you can't change the rest of the system libraries to use your class.)

  • Changing system libraries while theoretically possible is a REALLY, REALLY BAD IDEA, because it would break compatibility with everything under the sun, starting with your Java toolchain and IDE.

  • Changing the name of String would be particularly difficult because of the cross-dependencies between this class, generated code and the JVM internals. In particular, there are some really scary relationships between this class and the JVM bootstrap process.

  • And even if it was technically feasible to do this, it would STILL be a bad idea ... from the perspective of code maintainability. Think of the next guy who would have to read and modify your mongrel "Java looking like C#" codebase.


You just need to learn to use String ... like the millions of other C# programmers who have learned Java.

share|improve this answer

For lulz only

public final class string {
    private final String string;
    public string(String string){
        this.string = string;
    public String toString(){
        return string;

    public static void main(String args[]){
       string myString = new string("Hello World");
share|improve this answer
Maybe it would be a good idea to explain the joke ... i.e. why this class is (almost) no use to the OP. –  Stephen C Jul 12 '12 at 2:34
I think he gets the point with the 7 downvotes –  Shawn Jul 12 '12 at 14:39
I'm not talking about explaining for the OP. I'm talking about explaining for other people ... –  Stephen C Jul 12 '12 at 23:52
