Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Process API
Search
Jussi Pohjolainen
April 26, 2020
Technology
1
200
Process API
Simple examples how to execute shell commands using Java
Jussi Pohjolainen
April 26, 2020
Tweet
Share
More Decks by Jussi Pohjolainen
See All by Jussi Pohjolainen
Sustainability in Web Development - How to Optimize React Apps?
pohjus
0
68
Modern software development and fundamentals of AI
pohjus
0
84
C / C++ - language
pohjus
1
400
TypeScript for JS Developers
pohjus
0
350
Introduction to SwiftUI V2
pohjus
0
170
Kotlin Coroutines
pohjus
0
440
Android HTTP Clients
pohjus
0
440
Android HTTP Clients - v2
pohjus
0
38
Introduction to Jetpack Compose
pohjus
2
720
Other Decks in Technology
See All in Technology
RayでPHPのデバッグをちょっと快適にする
muno92
PRO
0
190
DevinでAI AWSエンジニア製造計画 序章 〜CDKを添えて〜/devin-load-to-aws-engineer
tomoki10
0
130
AWSアカウントのセキュリティ自動化、どこまで進める? 最適な設計と実践ポイント
yuobayashi
7
620
Ruby on Railsで持続可能な開発を行うために取り組んでいること
am1157154
3
160
アジャイルな開発チームでテスト戦略の話は誰がする? / Who Talks About Test Strategy?
ak1210
1
600
Exadata Database Service on Cloud@Customer セキュリティ、ネットワーク、および管理について
oracle4engineer
PRO
2
1.5k
IAMポリシーのAllow/Denyについて、改めて理解する
smt7174
2
210
Goで作って学ぶWebSocket
ryuichi1208
3
2.8k
Visualize, Visualize, Visualize and rclone
tomoaki0705
9
83k
実は強い 非ViTな画像認識モデル
tattaka
3
1.3k
手を動かしてレベルアップしよう!
maruto
0
220
設計を積み重ねてシステムを刷新する
sansantech
PRO
0
170
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Designing Experiences People Love
moore
140
23k
The World Runs on Bad Software
bkeepers
PRO
67
11k
Site-Speed That Sticks
csswizardry
4
410
4 Signs Your Business is Dying
shpigford
182
22k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
The Pragmatic Product Professional
lauravandoore
32
6.4k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
430
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
10
510
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
46
2.3k
Transcript
Properties API Jussi Pohjolainen
To store preferences • Simple API to • fetch •
store • key value pairs
import java.io.*; import java.util.*; class Main { public static void
main(String [] args) throws Exception { Properties prop = new Properties(); // set key and value prop.setProperty("fontSize", "24"); prop.setProperty("fontColor", "RGB(255,255,255)"); String optionalComments = "My preferences file"; prop.store(new FileWriter("./myfile.prop"), optionalComments); } }
myfile.prop #My preferences file #Sun Apr 26 10:56:55 EEST 2020
fontSize=24 fontColor=RGB(255,255,255)
Reading import java.io.*; import java.util.*; class Main { public static
void main(String [] args) throws Exception { Properties prop = new Properties(); prop.load(new FileReader("./myfile.prop")); System.out.println(prop.get("fontSize")); System.out.println(prop.get("fontColor")); } }
Storing XML import java.io.*; import java.util.*; class Main { public
static void main(String [] args) throws Exception { Properties prop = new Properties(); // set key and value prop.setProperty("fontSize", "24"); prop.setProperty("fontColor", "RGB(255,255,255)"); String optionalComments = "My preferences file"; prop.storeToXML(new FileOutputStream("./myfile.xml"), optionalComments); } }
myfile.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>My
preferences file</comment> <entry key="fontSize">24</entry> <entry key="fontColor">RGB(255,255,255)</entry> </properties>
Reading import java.io.*; import java.util.*; class Main { public static
void main(String [] args) throws Exception { Properties prop = new Properties(); prop.loadFromXML(new FileInputStream("./myfile.xml")); System.out.println(prop.getProperty("fontSize")); System.out.println(prop.getProperty("fontColor")); } }
Jackson
Jackson • Java classes to json mapping • External class
library, add dependency • You can use Jackson to save for example preferences file
Dependency <dependencies> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.10.3</version> </dependency> </dependencies>
Pojo public class Dog { private String name; public void
setName(String name) { this.name = name; } public String getName() { return this.name; } }
Main import com.fasterxml.jackson.databind.ObjectMapper; import java.io.*; class Main { public static
void main(String [] args) throws Exception { Dog spot = new Dog(); spot.setName("Spot"); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.writeValue(new File("./file.json"), spot); Dog temp = objectMapper.readValue(new File("./file.json"), Dog.class); System.out.println(temp.getName()); } }