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
C / C++ - language
pohjus
1
360
TypeScript for JS Developers
pohjus
0
220
Introduction to SwiftUI V2
pohjus
0
160
Kotlin Coroutines
pohjus
0
440
Android HTTP Clients
pohjus
0
430
Android HTTP Clients - v2
pohjus
0
33
Introduction to Jetpack Compose
pohjus
1
650
Java Exceptions
pohjus
0
280
Quick Start to React - Update 2024-01-03
pohjus
3
5.7k
Other Decks in Technology
See All in Technology
AGIについてChatGPTに聞いてみた
blueb
0
130
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
OS 標準のデザインシステムを超えて - より柔軟な Flutter テーマ管理 | FlutterKaigi 2024
ronnnnn
0
160
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
1.2k
The Rise of LLMOps
asei
7
1.6k
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
290
複雑なState管理からの脱却
sansantech
PRO
1
150
AIチャットボット開発への生成AI活用
ryomrt
0
170
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
240
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
1
110
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
28
13k
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Building Applications with DynamoDB
mza
90
6.1k
Building an army of robots
kneath
302
43k
Facilitating Awesome Meetings
lara
50
6.1k
Site-Speed That Sticks
csswizardry
0
27
The Invisible Side of Design
smashingmag
298
50k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
890
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
The Cult of Friendly URLs
andyhume
78
6k
Become a Pro
speakerdeck
PRO
25
5k
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()); } }