81

I just began to learn Java.

My friend who is helping me study just sent me this and said 'figure this out'.

Unfortunately I am unable to read this. It looks like Perl to me.

class _{_ _;_(){_=this;}}

What does it mean?

Tim Post
  • 33,371
  • 15
  • 110
  • 174
another ordinary
  • 899
  • 7
  • 10
  • 17
    This question is being discussed [on meta](http://meta.stackexchange.com/questions/173714/can-we-nuke-this-too-localized-question). Let's take arguments for or against closing/deleting it there. – Adam Lear Mar 26 '13 at 22:32
  • 64
    @anotherordinary You should probably ditch your friend as a programming teacher if he/she thought telling you to figure this out would be a good way to learn this language. Remembering irreverent trivia isn't useful at all. Much less when you are starting to learn a language. – Enno Shioji Mar 27 '13 at 00:44
  • 2
    @EnnoShioji Great point. "Irrelevant". Sorry. – Asad Saeeduddin Mar 27 '13 at 02:31
  • 1
    is someone trying to create the "IOJCC" ? (google "IOCCC") – Olivier Dulac Mar 27 '13 at 09:23
  • 1
    @EnnoShioji How is this "irrelevant trivia" that needs remembering? Anyone that calls himself a Java programmer should be able to understand this easily. – phant0m Jun 11 '13 at 13:21
  • 1
    @phant0m: The "trivia" here I think is the fact that Java allows a single underscore as an identifier, which I don't think is useful knowledge. – Enno Shioji Jun 11 '13 at 13:56

3 Answers3

155

_ is the class name. It's a very confusing one, but it works!

With the class renamed:

class Something {Something something;Something(){something=this;}}

And cleaned up:

class Something {
    Something something;
    Something() {
        something=this;
    }
}

And you can go crazy with this odd naming :)

class _{_ __;_ ____;_(){__=this;____=__;}_(_ ___){__=___;}}

In fact, Unicode is even supported, so this is valid:

class 合法類別名稱{合法類別名稱(){}}
tckmn
  • 57,719
  • 27
  • 114
  • 156
  • 29
    I personally love the @Alvin's edit :) – Bartek Banachewicz Jun 25 '13 at 09:40
  • 4
    There are few mistakes in your `get crazy` example. (1) you forgot to add semicolon after `____=__` (two times), (2) if you are trying to overload `_` method then you need to also pass type so `_(___)` should be `_(_ ___)`. Here is how it can look `class _{_ __;_ ____;_(){__=this;____=__;}_(_ ___){__ = ___;}}`. Wait a minute. Did I just debugged underscores? It is time for a brake. – Pshemo Oct 18 '13 at 22:25
  • @Pshemo Lol, I never really meant to be serious about that code :P fixed – tckmn Oct 20 '13 at 19:37
  • Get a +1 for the comment on my answer. Could not think of another way of rewarding you. – Ed Heal Nov 11 '13 at 02:50
71

_ is the class name, underscore is a valid Java variable name, you just need to indent your code to deobfuscate it:

class _{
    _ _;
    _(){
     _=this;
   }
}

Like:

class A{
    A A;
    A(){
     A=this;
   }
}

Edit: thanks to @Daniel Fischer

Type names and variable names have different namespaces. and for example code class FOO { FOO FOO; } is valid in Java.

Summary

  • _ is a class name e.g at class _{
  • _ is a class member name e.g at _ _; and _=this
  • _ is a constructor name e.g. at _()

Remember: Java uses six different namespaces:

  • Package names,
  • type names,
  • field (variable) names,
  • method names,
  • local variable names (including parameters), and
  • labels.

In addition, each declared enum has its own namespace. Identical names of different types do not conflict; for example, a method may be named the same as a local variable.

phant0m
  • 16,595
  • 5
  • 50
  • 82
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
  • 3
    There is no mistake. It compiles just fine as I typed. I just didn't understand it till now. – another ordinary Mar 26 '13 at 22:21
  • 2
    @GrijeshChauhan type names and variable names have different namespaces. `class FOO { FOO FOO; }` works. – Daniel Fischer Mar 26 '13 at 22:39
  • @DanielFischer Thanks..This is in Java only **?** ..any other language do this? – Grijesh Chauhan Mar 26 '13 at 22:40
  • 1
    In Haskell, for example, types and values also have different namespaces. A difference there is that case has meaning, a type name must begin with an upper case letter, so you can't name any old value like a type, but only constructors, but `data Foo = Foo | Bar Int` works. It can only work, of course, in languages where you can figure out the category of an identifier from where it appears. – Daniel Fischer Mar 26 '13 at 22:45
  • @DanielFischer thanks a lot Deniel Fischer... I found it very interesting. – Grijesh Chauhan Mar 26 '13 at 22:51
  • 2
    @anotherordinary read my updated answer I added a link also – Grijesh Chauhan Mar 26 '13 at 23:01
  • @DanielFischer I have a cross question: In c++ also contractors and class name, function name is overloading and overriding are same. Its dues to namespace or c++ compiler internally represent every function with different name **?** Sorry for bothering you again. – Grijesh Chauhan Mar 26 '13 at 23:14
  • 1
    Uh, C++ isn't really my domain. But unless things changed since I last looked, overloading is resolved via name-mangling, with parameter types included in the "real" name in some way. I think type names and function/constructor names are in the same namespace in C++, but I'm not sure, and too lazy to look it up now. – Daniel Fischer Mar 26 '13 at 23:27
  • 1
    Aren't field names and local variables in the same namespace? Otherwise you wouldn't be able to shadow the variables, as is commonly done in setter methods: `void setValue(String value) { this.value = value;}` – Jörn Horstmann Mar 27 '13 at 14:38
  • @JörnHorstmann No I mean yes both are in same *namespace*. – Grijesh Chauhan Mar 27 '13 at 14:42
  • @anotherordinary Hi Did you read this question and its answer [Obfuscated C Code Contest 2006.](http://stackoverflow.com/questions/15393441/obfuscated-c-code-contest-2006-please-explain-sykes2-c/15395030#15395030) – Grijesh Chauhan Mar 28 '13 at 14:08
  • @GrijeshChauhan: In the comment you wrote that they're in the same namespace, but this contradicts your answer listing 6 different namespaces. I'd say "field vs local variable vs enum member" is all just scoping. – maaartinus Nov 14 '13 at 03:49
  • @maaartinus Yes I notice. But I think because we use `this` so both are in same name space. I didn't understand what do you mean by `'this is just scoping'` ..please add some info/link I am myself confused. – Grijesh Chauhan Dec 04 '13 at 12:00
12

well that’s good example . Java allows unicode to be identifiers so you can write something like:

class ⲥlass {
ⲥlass claѕѕ;
}

here class name's c is 'ⲥ' (U+2CA5 COPTIC SMALL LETTER SIMA) and

object name's 'ѕ' (U+0455 CYRILLIC SMALL LETTER DZE).

ashgkwd
  • 195
  • 11
  • You can't have a variable named `class`, it's a keyword. – nickb Mar 27 '13 at 16:36
  • 14
    @nickb : it is not Java keyword `'class'`. as I have mentioned that object name `'claѕѕ'` has `'ss'` which are non ascii characters. so actually object's name is `claѕѕ` is `cla\u0455\u0455'` I think this clears misunderstanding. :) – ashgkwd Mar 27 '13 at 17:31