Java 17 Recipes


Download 3.2 Mb.
Pdf ko'rish
bet90/245
Sana02.06.2024
Hajmi3.2 Mb.
#1839910
1   ...   86   87   88   89   90   91   92   93   ...   245
Bog'liq
Java 17 Recipes

4-20. Period of Day
 Problem
You want to express the periods of a day not as a.m. or p.m. but as “in the morning” or 
“in the afternoon” or “at night”.
 Solution
Java 16 addresses that goal with a new formatter pattern, called B. In the following 
example, the period of the day is translated into text according to the time of the day.
public static void main(String[] args) {
final String whatPeriodOfTheDay
= DateTimeFormatter.ofPattern("B").format(LocalTime.now());
System.out.println("Pattern B: " + whatPeriodOfTheDay);
}
The following is the output in Italian.
Pattern B: del pomeriggio (in the afternoon)
Chapter 4 Numbers aNd dates


150
 How It Works
In Java 16, the period of the day was added to java.time formats.
4-21. Summary
Numbers and dates play an integral role in most applications. This chapter reviewed 
some techniques that can be used for rounding and formatting numbers and generating 
random values. It also provided a brief overview of some commonly used date-time 
features.
Chapter 4 Numbers aNd dates


151
© Josh Juneau, Luciano Manelli 2022 
J. Juneau and L. Manelli, Java 17 Recipes
https://doi.org/10.1007/978-1-4842-7963-2_5
CHAPTER 5
Object-Oriented Java
Object-oriented programs consist of many different pieces of code that all work 
together in unison. Rather than write a program that contains a long list of statements 
and commands, an object-oriented philosophy is to break functionality into separate 
organized objects. Each of the objects contains functionality that pertains to it, and as 
the objects are pieced together, they can be used to develop sophisticated solutions. In 
this chapter, we touch on some of the key object-oriented features of the Java language. 
From the basic recipes covering access modifiers to the advanced recipes that deal 
with inner classes, this chapter contains recipes that help you understand Java’s object- 
oriented methodologies.

Download 3.2 Mb.

Do'stlaringiz bilan baham:
1   ...   86   87   88   89   90   91   92   93   ...   245




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling