Java Puzzle 13 – Unicode

Merhaba Arkadaslar
Java , Unicode standardini destekler.

Ornek kodumuzu inceleyelim ;

Unicode.java

package _13.unicode;

public class Unicode{

	public static void main(String[] args) {	
		System.out.println("a\u0022.length() + \u0022b".length());
	}
}

2 tirnak arasinda 26 karakter yer almaktadir. Ornegi calistirdigimizda output ;

2

\u0022 degeri double quote(“)/cift tirnagin Unicode degeridir.
Compiler , Unicode karakterleri translate edecektir.

http://unicode-table.com/en/#0022
https://www.branah.com/unicode-converter

		System.out.println("a\u0022.length() + \u0022b".length());
		System.out.println("a".length() + "b".length());

Bir baska ornek olarak ;

		System.out.println("a\u0021.length() + \u0021b".length());
		System.out.println("a!.length() + !b".length());
		
                System.out.println("\u0024".equals("$"));

Unicode degerlerinin translate edildigini unutmayalim ve ozellikle ” karakteri konusunda dikkatli olalim.

Bir baska ornek olarak ;

LinePrinter.java

package _13.unicode;

public class LinePrinter {
	public static void main(String[] args) {
		// Note: \u000A is Unicode representation of linefeed (LF)
		char c = 0x000A;
		System.out.println(c);
	}
}

Kodumuz derleme hatasi verecektir , peki neden ?
\u000A , linefeed karakterinin unicode degeridir , yani bu kod aslinda soyledir ;

package _13.unicode;

public class LinePrinter {
	public static void main(String[] args) {

		// Note:
		is Unicode representation of linefeed (LF)
		
		char c = 0x000A;
		System.out.println(c);
	}
}

Bir baska ornek olarak ;

WeirdUnicode.java

\u0070\u0061\u0063\u006b\u0061\u0067\u0065 \u005f\u0031\u0033\u002e\u0075\u006e\u0069\u0063\u006f\u0064\u0065\u003b
\u0070\u0075\u0062\u006c\u0069\u0063 \u0063\u006c\u0061\u0073\u0073 
\u0057\u0065\u0069\u0072\u0064\u0055\u006e\u0069\u0063\u006f\u0064\u0065 \u007b
\u0070\u0075\u0062\u006c\u0069\u0063 \u0073\u0074\u0061\u0074\u0069\u0063 \u0076\u006f\u0069\u0064 
\u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d \u0061\u0072\u0067\u0073\u0029 \u007b
\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e
\u0028\u0022\u0048\u0065\u006c\u006c\u006f \u004a\u0061\u0076\u0061\u0021\u0022\u0029\u003b
\u007d\u007d

//https://www.branah.com/unicode-converter

Ornegimizi calistirdigimizda output/cikti olarak;

Hello world

Yazimi burada sonlandiriyorum.
Herkese bol Javali gunler dilerim.
Be an oracle man , import java.*;
Levent Erguder
OCP, Java SE 6 Programmer
OCE, Java EE 6 Web Component Developer

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *