Java
Contents
class
template
- template 是 compilation feature, cannot instantiate a template with dynamic class at runtime
enum
- enum 默认是 String
- 用
enum.valueOf(str)
convert toenum
- integer enum
|
|
- 用 index 访问
Type.values()[index]
Project
classpath
- 访问 resources 也是需要在 classpath 中声明的
Serialize
Gson
- Gson 应该是还比较好的方案了吧, 没有什么CVE问题
Process
阻塞
- process 创建时默认重定向到 pipe, 如果主线程不及时读取 pipe 的内容, pipe buffer 会堵塞
format
Conversion | Argument Category | Description |
'b', 'B' | general | If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(). Otherwise, the result is "true". |
'h', 'H' | general | If the argument arg is null, then the result is "null". Otherwise, the result is obtained by invoking Integer.toHexString(arg.hashCode()). |
's', 'S' | general | If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invoking arg.toString(). |
'c', 'C' | character | The result is a Unicode character |
'd' | integral | The result is formatted as a decimal integer |
'o' | integral | The result is formatted as an octal integer |
'x', 'X' | integral | The result is formatted as a hexadecimal integer |
'e', 'E' | floating point | The result is formatted as a decimal number in computerized scientific notation |
'f' | floating point | The result is formatted as a decimal number |
'g', 'G' | floating point | The result is formatted using computerized scientific notation or decimal format, depending on the precision and the value after rounding. |
'a', 'A' | floating point | The result is formatted as a hexadecimal floating-point number with a significand and an exponent |
't', 'T' | date/time | Prefix for date and time conversion characters. See Date/Time Conversions. |
'%' | percent | The result is a literal '%' ('\u0025') |
'n' | line separator | The result is the platform-specific line separator |
date
format
|
|
2022-04-18 20:53:33.000538
duration
|
|
iterator
iterator and remove
|
|
File
Path
- 一般直接用 Path 处理路径
- Path.toFile() 直接转 File
join
|
|
list file
|
|
copy&move
move
Option
- REPLACE_EXISTING
- ATOMIC_MOVE
|
|
copy
|
|
file exist
|
|
Write to File
BufferedWriter 写 String
|
|
FileOutputStream 写 bytes
|
|
Reflect
from class
|
|
Object
copy
deep-copy
problem
- A common solution to the deep copy problem is to use Java Object Serialization (JOS).
Unfortunately, this approach has some problems, too:
- It will only work when the object being copied, as well as all of the other objects references directly or indirectly by the object, are serializable. (In other words, they must implement java.io.Serializable.) Fortunately it is often sufficient to simply declare that a given class implements java.io.Serializable and let Java’s default serialization mechanisms do their thing.
- Java Object Serialization is slow, and using it to make a deep copy requires both serializing and deserializing. There are ways to speed it up (e.g., by pre-computing serial version ids and defining custom readObject() and writeObject() methods), but this will usually be the primary bottleneck.
- The byte array stream implementations included in the java.io package are designed to be general enough to perform reasonable well for data of different sizes and to be safe to use in a multi-threaded environment. These characteristics, however, slow down ByteArrayOutputStream and (to a lesser extent) ByteArrayInputStream.
log
log4j2
dynamic setting
from system property
|
|
|
|
Disassembly
class
- Parse class file
|
|
options | description |
-c | Disassemble the code |
jar
- extract
|
|
java-version
archlinux
|
|