-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be2b69b
commit 4cfd20f
Showing
19 changed files
with
203 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
study-utility-classes/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/com/example/StudyCurrency.java=UTF-8 | ||
encoding//src/com/example/StudyDateTimeFormatter.java=UTF-8 | ||
encoding//src/com/example/StudyString.java=UTF-8 | ||
encoding//src/com/example/StudyStringComparison.java=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
greeting=Hi {0}! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
greeting=Merhaba, {0}! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example; | ||
|
||
import java.text.DecimalFormat; | ||
import java.text.DecimalFormatSymbols; | ||
import java.util.Locale; | ||
|
||
public class StudyCurrency { | ||
|
||
public static void main(String[] args) { | ||
var money = 12_345_678.9; | ||
Locale locale = Locale.JAPAN; // new Locale("tr", "TR"); | ||
var df = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale); | ||
//var dfs = DecimalFormatSymbols.getInstance(locale); | ||
//dfs.setCurrencySymbol("\u20BA"); | ||
//df.setDecimalFormatSymbols(dfs); | ||
System.out.println(df.format(money)); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
study-utility-classes/src/com/example/StudyDateTimeFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.example; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.FormatStyle; | ||
import java.util.Locale; | ||
|
||
public class StudyDateTimeFormatter { | ||
|
||
public static void main(String[] args) { | ||
ZonedDateTime now = ZonedDateTime.now(); | ||
Locale tr = Locale.JAPAN; // new Locale("tr", "TR"); | ||
var dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.FULL) | ||
.withLocale(tr); | ||
System.out.println(dtf.format(now)); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
study-utility-classes/src/com/example/StudyDynamicString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example; | ||
|
||
public class StudyDynamicString { | ||
|
||
public static void main(String[] args) { | ||
// StringBuffer: TS, StringBuilder: NOT TS | ||
var s = new StringBuffer(488891); | ||
var start = System.currentTimeMillis(); | ||
for (var i=0;i<2_000_000;++i) { | ||
s.append(i); // dynamic string | ||
} | ||
var stop = System.currentTimeMillis(); | ||
System.out.println("s.length(): "+s.length() | ||
+ ", duration: " + (stop-start) + " ms."); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.example; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Locale; | ||
import java.util.ResourceBundle; | ||
|
||
public class StudyI18N { | ||
|
||
public static void main(String[] args) { | ||
Locale tr = Locale.US; // new Locale("tr", "TR"); | ||
var bundle = ResourceBundle.getBundle("messages", tr); | ||
String fullname= "Jack Bauer"; | ||
var formatter = new MessageFormat(bundle.getString("greeting"),tr); | ||
System.out.println(formatter.format(new Object[] {fullname})); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example; | ||
|
||
import java.util.Locale; | ||
|
||
public class StudyString { | ||
|
||
public static void main(String[] args) { | ||
// String: immutable class -> object caching/pooling | ||
String name = "jack"; | ||
System.out.println(name); | ||
name = name.toUpperCase(); | ||
System.out.println(name); | ||
var city = "izmir"; | ||
// Internationalization: i18n | ||
var tr = new Locale("tr","TR"); | ||
System.out.println(city); | ||
city = city.toUpperCase(tr); // supports i18n | ||
System.out.println(city); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
study-utility-classes/src/com/example/StudyStringComparison.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example; | ||
|
||
import java.text.Collator; | ||
import java.text.ParseException; | ||
import java.text.RuleBasedCollator; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public class StudyStringComparison { | ||
|
||
public static void main(String[] args) throws ParseException { | ||
List<String> names = new ArrayList<>(); | ||
names.add("şule"); | ||
names.add("şima"); | ||
names.add("sema"); | ||
names.add("zehra"); | ||
names.add("ayşegül"); | ||
names.sort(String::compareTo); | ||
System.out.println(names); | ||
String name1 = "müller"; | ||
String name2 = "mueller"; | ||
System.out.println("name1.equals(name2): "+name1.equals(name2)); | ||
// Collation | ||
String basicRules= "< z < b < c < ç < d < e < f < g < ğ < h "+ | ||
"< ı < i < j < k < l < m < n < o < ö < p "+ | ||
"< r < s < ş < t < u < ü < v < y < a "; | ||
String trExpension= "& ü ; ue & s ; ş" ; | ||
final Collator collator= new RuleBasedCollator(basicRules + trExpension); | ||
Collator.getInstance(new Locale("tr","TR")); | ||
collator.setStrength(Collator.PRIMARY); | ||
System.out.println("name1.equals(name2): "+collator.equals(name1,name2)); | ||
System.out.println("sima==şima: "+collator.equals("sima","şima")); | ||
names.sort(collator::compare); | ||
System.out.println(names); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
greeting=Hi {0}! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
greeting=Merhaba, {0}! |