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
210
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
120
Modern software development and fundamentals of AI
pohjus
0
110
C / C++ - language
pohjus
1
450
TypeScript for JS Developers
pohjus
0
380
Introduction to SwiftUI (2025-04-22)
pohjus
0
210
Kotlin Coroutines
pohjus
0
510
Android HTTP Clients
pohjus
0
490
Introduction to Jetpack Compose
pohjus
2
830
Java Exceptions
pohjus
0
310
Other Decks in Technology
See All in Technology
Amazon GuardDuty での脅威検出:脅威検出の実例から学ぶ
kintotechdev
0
130
AWSの最新サービスでAIエージェント構築に楽しく入門しよう
minorun365
PRO
8
480
Claude Codeは仕様駆動の夢を見ない
gotalab555
23
7.2k
20250818_KGX・One Hokkaidoコラボイベント
tohgeyukihiro
0
110
キャリアを支え組織力を高める「多層型ふりかえり」 / 20250821 Kazuki Mori
shift_evolve
PRO
2
120
Google Agentspaceを実際に導入した効果と今後の展望
mixi_engineers
PRO
3
810
サービスロボット最前線:ugoが挑むPhysical AI活用
kmatsuiugo
0
140
[kickflow]20250319_少人数チームでのAutify活用
otouhujej
0
170
アカデミーキャンプ 2025 SuuuuuuMMeR「燃えろ!!ロボコン」 / Academy Camp 2025 SuuuuuuMMeR "Burn the Spirit, Robocon!!" DAY 1
ks91
PRO
0
150
リモートワークで心掛けていること 〜AI活用編〜
naoki85
0
190
o11yツールを乗り換えた話
tak0x00
2
1.7k
サイボウズフロントエンドの横断活動から考える AI時代にできること
mugi_uno
3
1.1k
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Imperfection Machines: The Place of Print at Facebook
scottboms
268
13k
A Modern Web Designer's Workflow
chriscoyier
695
190k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
110
20k
How STYLIGHT went responsive
nonsquared
100
5.7k
Facilitating Awesome Meetings
lara
55
6.5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
9
770
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.6k
Music & Morning Musume
bryan
46
6.7k
Git: the NoSQL Database
bkeepers
PRO
431
65k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
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()); } }