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
190
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
Kotlin Coroutines
pohjus
0
330
Android HTTP Clients
pohjus
0
330
Android HTTP Clients - v2
pohjus
0
9
Introduction to Jetpack Compose
pohjus
1
480
Java Exceptions
pohjus
0
260
Quick Start to React - Update 2024-01-03
pohjus
2
5.5k
Java Tools
pohjus
0
180
Node.js Development with ES2015 ->
pohjus
0
3.9k
LibGDX: Tiled Maps
pohjus
1
1.2k
Other Decks in Technology
See All in Technology
PHPカンファレンス小田原2024
ysknsid25
3
660
Next'24 事例セッションの紹介とクラウド資格を活用したキャリア形成について語りMuscle
yasumuusan
1
340
0→1開発における技術選定において一番大切なこと
bicstone
1
330
Data and AI Governance: Existing Challenges and Emerging Trends
scotthsieh825
0
160
Vertex AI を中心に 生成AIのアップデートを共有します
kaz1437
0
140
The CloudCompare project by Dr. Daniel Girardeau-Montaut
kentaitakura
0
510
エンタープライズ環境下での Active Directory の運用 TIPS
tamaiyutaro
1
1.6k
「共通基盤」を超えよ! 今、Platform Engineeringに取り組むべき理由
jacopen
25
5.9k
カオナビの利用実績をアウトカムへつなげる旅 / example-of-data-management-startup-in-kaonavi
kaonavi
0
120
複雑な構成要素を持つUIとの向き合い方 〜新・支出グラフでの実例〜 / B43 TECH TALK
nakamuuu
0
110
人間の尊厳、幸福、アクセシビリティ / 第116回「WEB TOUCH MEETING」アクセシビリティSP
nulabinc
PRO
2
180
2024/4/26 コンピュータ歴史博物館解説告知
toshi_atsumi
0
200
Featured
See All Featured
From Idea to $5000 a Month in 5 Months
shpigford
377
45k
Product Roadmaps are Hard
iamctodd
43
9.7k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
356
22k
Gamification - CAS2011
davidbonilla
76
4.6k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
6
990
Scaling GitHub
holman
457
140k
Building Better People: How to give real-time feedback that sticks.
wjessup
354
18k
For a Future-Friendly Web
brad_frost
171
8.9k
Thoughts on Productivity
jonyablonski
57
3.8k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
658
120k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
18
1.7k
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()); } }