File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
src/main/java/com/howtodoinjava/core/basic Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .howtodoinjava .core .basic ;
2
+
3
+ import java .nio .charset .Charset ;
4
+
5
+ public class CharacterEncodingExample {
6
+
7
+ public static void main (String [] args ) {
8
+ String fileCoding = System .getProperty ("file.encoding" );
9
+ System .out .println (STR ."Default Character Encoding: \{fileCoding }" );
10
+
11
+ String filePathEncoding = System .getProperty ("sun.jnu.encoding" );
12
+ System .out .println (STR ."Default File Path Encoding: \{filePathEncoding }" );
13
+
14
+ String defaultCharset = Charset .defaultCharset ().displayName ();
15
+ System .out .println (STR ."Default Charset Name: \{defaultCharset }" );
16
+
17
+ /*System.setProperty("file.encoding", "UTF-16");
18
+ System.setProperty("sun.jnu.encoding", "UTF-16");*/
19
+
20
+ defaultCharset = System .out .charset ().displayName ();
21
+ System .out .println (STR ."Default Character Encoding: \{defaultCharset }" );
22
+
23
+ System .out .println ("The façade pattern is a software-design pattern." );
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ package com .howtodoinjava .core .basic ;
2
+
3
+ import java .util .Objects ;
4
+ import lombok .AllArgsConstructor ;
5
+
6
+ public class ObjectIdentityString {
7
+
8
+ public static void main (String [] args ) {
9
+ Record record = new Record (1L , "record name" );
10
+
11
+ System .out .println (record );
12
+
13
+ System .out .println (record != null ? Objects .toIdentityString (record ) : "null" );
14
+
15
+ System .out .println (getIdentityString (record ));
16
+ }
17
+
18
+ static String getIdentityString (Object object ) {
19
+ return object .getClass ().getName () + "@"
20
+ + Integer .toHexString (System .identityHashCode (object ));
21
+ }
22
+ }
23
+
24
+ @ AllArgsConstructor
25
+ class Record {
26
+ long id ;
27
+ String name ;
28
+
29
+ @ Override
30
+ public String toString () {
31
+ return STR ."Record{id=\{id }, name='\{name }\{'\'' }\{'}' }" ;
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments