Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Uses for Special Characters in Java Code

DZone's Guide to

Uses for Special Characters in Java Code

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

Ever wondered how you can write code like this in Java?
    if( ⁀ ‿ ⁀ == ⁀ ⁔ ⁀ || ¢ + ¢== ₡)

Background

Underscores has long been using in C like language such as Java to distinguish fields and method names.

It is common to see a leading underscore like _field or an underscore in a constant like UPPER_CASE. In Java the $ is also used in class names and accessor method names.

The SCJP has notes which state

Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!
This leads to the question; what other connecting characters are there?

What are connecting characters?

A connecting character joins two words together. This page lists ten connecting characters

U+005F LOW LINE _ view
U+203F UNDERTIE view
U+2040 CHARACTER TIE view
U+2054 INVERTED UNDERTIE view
U+FE33 PRESENTATION FORM FOR VERTICAL LOW LINE view
U+FE34 PRESENTATION FORM FOR VERTICAL WAVY LOW LINE view
U+FE4D DASHED LOW LINE view
U+FE4E CENTRELINE LOW LINE view
U+FE4F WAVY LOW LINE view
U+FF3F FULLWIDTH LOW LINE _ view

And if you try the following you may find it compiles.

     int _, ‿, ⁀, ⁔, ︳, ︴, ﹍, ﹎, ﹏, _;

While this is interesting, does it have a use?  Recently I found one.
I have an object which represents a column, and this column has a value for that row. The names are basically the same but I want a notation to distinguish them. So I have something like
    Column<Double>︴tp︴ = table.getColumn("tp", double.class);
    double tp = row.getDouble(︴tp︴);

This way I can see with is tp the column, and which is the value.

Interestingly the currency characters are valid as well.
 for (int i = Character.MIN_CODE_POINT; i <= Character.MAX_CODE_POINT; i++)
        if (Character.isJavaIdentifierStart(i) && !Character.isAlphabetic(i))
            System.out.println(i + " : " + (char) i);

prints

36 : $
95 : _
162 : ¢
163 : £
164 : ¤
165 : ¥
1547 : ؋
2546 : ৲
2547 : ৳
2555 : ৻
2801 : ૱
3065 : ௹
3647 : ฿
6107 : ៛
8255 : ‿
8256 : ⁀
8276 : ⁔
8352 : ₠
8353 : ₡
8354 : ₢
8355 : ₣
8356 : ₤
8357 : ₥
8358 : ₦
8359 : ₧
8360 : ₨
8361 : ₩
8362 : ₪
8363 : ₫
8364 : €
8365 : ₭
8366 : ₮
8367 : ₯
8368 : ₰
8369 : ₱
8370 : ₲
8371 : ₳
8372 : ₴
8373 : ₵
8374 : ₶
8375 : ₷
8376 : ₸
8377 : ₹
43064 : ꠸
65020 : ﷼
65075 : ︳
65076 : ︴
65101 : ﹍
65102 : ﹎
65103 : ﹏
65129 : ﹩
65284 : $
65343 : _
65504 : ¢
65505 : £
65509 : ¥
65510 : ₩

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Published at DZone with permission of Peter Lawrey, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}