-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.xml
362 lines (362 loc) · 40.9 KB
/
index.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>T[h]ink]er[ing</title>
<link>https://torokmark.github.io/</link>
<description>Recent content on T[h]ink]er[ing</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<lastBuildDate>Sun, 06 Aug 2023 12:00:00 +0100</lastBuildDate>
<atom:link href="https://torokmark.github.io/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>IntelliJ Plugin: Java Development</title>
<link>https://torokmark.github.io/posts/intellij-plugin-java-development/</link>
<pubDate>Sun, 06 Aug 2023 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/intellij-plugin-java-development/</guid>
<description>This post presents some of the plugins of IntelliJ that can be useful during daily work.
These plugins are used mostly to develop Java related projects, and give a huge support in effective programming. Some of them are language or project agnostic.
Recommendation is represented as a list of star. Five is the most, zero is the lowest.
Material Theme UI &#x2b50; &#x2b50; &#x2b50; &#x2b50; &#x2b50; Rich, awesome, and configurable UI design to bring the best out of the look of your IDE.</description>
</item>
<item>
<title>Fix that Java: Uncompiling Compiler</title>
<link>https://torokmark.github.io/posts/fix-that-java-uncompiling-compiler/</link>
<pubDate>Sat, 05 Aug 2023 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/fix-that-java-uncompiling-compiler/</guid>
<description>Though, the following challenge seems easy, we have some restrictions. Unfortunatelly, the source codes of Main and JavaCompiler are not in our hands.
class Main { public static void main(String[] args) { JavaCompiler compiler = new JavaCompiler(&#34;hello.java&#34;); compiler.compile(); } } class JavaCompiler implements Compiler { private String path; JavaCompiler(String path) { this.path = path; } String getPath() { return path; } } interface Compiler { void compile(); } Take care of the code, and make it work!</description>
</item>
<item>
<title>Fix that Java: Increasing Value</title>
<link>https://torokmark.github.io/posts/fix-that-java-increasing-value/</link>
<pubDate>Wed, 28 Dec 2022 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/fix-that-java-increasing-value/</guid>
<description>Threads&rsquo; execution easily ends up in corrupted data.
class Main { public static void main(String[] args) throws InterruptedException { Counter counter = new Counter(); Thread thread = new CounterThread(counter); } } class Counter { private volatile int value = 0; public void increase() { value += 1; } public int getValue() { return value; } } class CounterThread extends Thread { private final Counter counter; public CounterThread(Counter counter) { this.counter = counter; } @Override public void run() { for (int i = 0; i &lt; 10000; i += 1) { counter.</description>
</item>
<item>
<title>Fix that Java: Mugs are not the Same</title>
<link>https://torokmark.github.io/posts/fix-that-java-mugs-are-not-the-same/</link>
<pubDate>Mon, 05 Dec 2022 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/fix-that-java-mugs-are-not-the-same/</guid>
<description>Ahh, either mugs or code but one of them is definitely broken&hellip;. or both.
public class Main { public static void main(String[] args) { Mug classic = new Mug(1.2); PlasticMug plastic = new PlasticMug(1.2, &#34;polycarbonat&#34;); System.out.println(plastic.equals(classic)); } } public class Mug { private double capacity; public Mug(double capacity) { this.capacity = capacity; } public double getCapacity() { return capacity; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null) { return false; } if (!</description>
</item>
<item>
<title>Do you know Java: Decorate your code</title>
<link>https://torokmark.github.io/posts/do-you-know-java-decorate-your-code/</link>
<pubDate>Sun, 27 Nov 2022 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-decorate-your-code/</guid>
<description>You do not need comments to decorate your code minimally.
Many years back then comments were the ultimate tool to decorate our code. And as it happened many times, sotware engineers glady used it to place ascii arts around their hotfixes or just simple seperate their solutions.
In this post I would like to show you a funny feature of operators which you can use to draw lines or more.</description>
</item>
<item>
<title>Fix that Java: The Broken Flash Drive</title>
<link>https://torokmark.github.io/posts/fix-that-java-the-broken-flash-drive/</link>
<pubDate>Tue, 15 Nov 2022 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/fix-that-java-the-broken-flash-drive/</guid>
<description>Sadly, one of our colleagues hasn&rsquo;t used version control system and the flash drive he has used was broken, so we have lost one part of the source code such as Starter class.
class App extends Starter { @Override public void start() { System.out.println(&#34;Start&#34;); } public static void main(String[] args) { launch(args); } } Implement the Starter class and make it work! Once you start the application it should call the start method of App class.</description>
</item>
<item>
<title>Fix that Java: The Broken Basket</title>
<link>https://torokmark.github.io/posts/fix-that-java-the-broken-basket/</link>
<pubDate>Sun, 13 Nov 2022 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/fix-that-java-the-broken-basket/</guid>
<description>Nice basket. We would like to put Jonathan apples only in that. But something is fishy here&hellip;
class Main { public static void main(String[] args) { Basket basket = new Basket(); basket.add(&#34;Jonathan&#34;); // ... } } import java.util.List; import java.util.ArrayList; class Basket { private List&lt;String&gt; apples = new ArrayList&lt;&gt;(); public void add(String apple) { if (apple.equals(&#34;Jonathan&#34;)) { apples.add(apple); } } @Override public String toString() { return apples.size() + &#34; piece(s) of Jonathan.</description>
</item>
<item>
<title>Fix that Java: Set is Bigger</title>
<link>https://torokmark.github.io/posts/fix-that-java-set-is-bigger/</link>
<pubDate>Thu, 01 Apr 2021 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/fix-that-java-set-is-bigger/</guid>
<description>As we see, the following code works bit different as we expect.
import java.util.Set; import java.util.HashSet; class Main { public static void main(String[] args) { Set&lt;Dog&gt; dogs = new HashSet&lt;&gt;(); Dog caesar = new Dog(&#34;German Shepherd&#34;); Dog rex = new Dog(&#34;German Shepherd&#34;); dogs.add(caesar); dogs.add(rex); System.out.println(caesar.equals(rex)); System.out.println(dogs.size()); } } class Dog { private String breed; public Dog(String breed) { this.breed = breed; } public int hashCode() { return breed.hashCode(); } public boolean equals(Dog o) { return breed.</description>
</item>
<item>
<title>Fix that Java: Challenge</title>
<link>https://torokmark.github.io/posts/fix-that-java-challenge/</link>
<pubDate>Thu, 01 Apr 2021 11:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/fix-that-java-challenge/</guid>
<description>In this series I am going to share short codes with well-known, or less well-known but common problems that we, developers face from time to time during our work.
The series is about learning the language, learning its features, functionalities, and limits. It is up to you how to do it!
I am going to post a code snippet with a hidden misfunctionality. Your challenge is to solve that keeping the rules and limitations that I attach to the snippet.</description>
</item>
<item>
<title>Do you know Java: Beware of instanceof in equals</title>
<link>https://torokmark.github.io/posts/do-you-know-java-beware-of-instanceof-in-equals/</link>
<pubDate>Wed, 31 Mar 2021 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-beware-of-instanceof-in-equals/</guid>
<description>One of the most important methods is equals. So, it is also important how it is implemented.
What is the real issue with instanceof and equals? Let us see an implementation of it. First, let us introduce a simple class and its inheritant that demonstrate the usage of equals`.
public class Mug { private double capacity; // ctor, setter, getter @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null) { return false; } if (!</description>
</item>
<item>
<title>Do you know Java: Hidden Keywords</title>
<link>https://torokmark.github.io/posts/do-you-know-java-hidden-keywords/</link>
<pubDate>Mon, 29 Jun 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-hidden-keywords/</guid>
<description>Java has a lot of keywords which are not used as identifiers or values.
Though, Java has a lot of keywords, some of them are less known or even not used. More over not used because they cannot be used at all.
The good old goto is one of the two. Since sequence, selection and iteration are enough for Turing machine, goto became unnecessarily, not to mention that understanding the code becomes hard to follow.</description>
</item>
<item>
<title>Do you know Java: Records</title>
<link>https://torokmark.github.io/posts/do-you-know-java-records/</link>
<pubDate>Mon, 25 May 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-records/</guid>
<description>Java 15 introduces record type.
Records are a new kind of class in the Java language. The purpose of a record is to declare that a small group of variables is to be regarded as a new kind of entity. As said in JEP 384.
Simple data carrier classes contain too much boilerplate code compared to the data itself. Fields, getter, setters, ctors, toString, equals, hashCode. On the other hand, quite difficult to figure out what the class represents.</description>
</item>
<item>
<title>Do you know Java: Pattern Matching for instanceof</title>
<link>https://torokmark.github.io/posts/do-you-know-java-instanceof-pattern-matching/</link>
<pubDate>Sat, 23 May 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-instanceof-pattern-matching/</guid>
<description>Java 15 brings a syntactic sugar, called Pattern Matching for instanceof, with which we can shorten the code and make it more safe.
In prior versions of Java, the instanceof operator workes as follows:
Object o = &#34;asdf&#34;; if (o instanceof String) { String s = (String) o; System.out.println(o); } Java 15 - and Java 14 as a preview feature - introduces an enhanced instanceof operator, which brings the ability to cast the eximined instance to the type of the right operand.</description>
</item>
<item>
<title>Do you know Java: Immutable Object</title>
<link>https://torokmark.github.io/posts/do-you-know-java-immutable-object/</link>
<pubDate>Sat, 16 May 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-immutable-object/</guid>
<description>Couple of thoughts about how to implement immutable objects.
Class has to be final. Fields have to be private and final. Hence, fields are set in constructor. No setters and setter-like methods. If object is passed in ctor parameter, make a clone of it. Do the same in getters as well. public final class Person { private final String name; private final int age; private final List&lt;PhoneNumber&gt; phoneNumbers; public Person(String name, int age, List&lt;PhoneNumber&gt; phoneNumbers) { this.</description>
</item>
<item>
<title>Do you know Java: Helpful NullPointerExceptions</title>
<link>https://torokmark.github.io/posts/do-you-know-java-helpful-nullpointerexceptions/</link>
<pubDate>Tue, 05 May 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-helpful-nullpointerexceptions/</guid>
<description>Java 14 has brought a helpful feature with that we can get information about the source of the raised NullPointerException
NullPointerException is not very friendly and can occur anywhere. All the placed where we don&rsquo;t want it to be. In this post I will show you how to track down its source.
The following source code is given:
String value = null; System.out.println(value.length()); Pre Java 14 Era The good old error message is the following:</description>
</item>
<item>
<title>Do you know Java: Text Blocks</title>
<link>https://torokmark.github.io/posts/do-you-know-java-text-blocks/</link>
<pubDate>Sun, 03 May 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-text-blocks/</guid>
<description>Text blocks is a new proposed feature, hopefully coming with Java 15.
Until then, let us see how it looks like in Java 14 as a feature preview.
Here is how we declare a multiline string value. Once we have to concatenate, and also have to place new line characters (\n).
String text = &#34;one line\n&#34; + &#34;and\n&#34; + &#34;another&#34;; When text is printed out:
one line and another The new feature looks like the following.</description>
</item>
<item>
<title>Do you know Java: I Need Dollars, Dollars, ...</title>
<link>https://torokmark.github.io/posts/do-you-know-java-i-need-dollars-dollars/</link>
<pubDate>Sat, 02 May 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-i-need-dollars-dollars/</guid>
<description>Some special characters are accepted as part of an identifier, dollar sign is among them.
Have you ever though about to write an application, whichever small that would be, and use as less identifier as possible.
And what if the identifier is weird itself already?
class $ { private String $; public void $(String $) { this.$ = $; } public String $() { return this.$; } } public class Main { public static void main(String[] args) { $ $ = new $(); $.</description>
</item>
<item>
<title>Do you know Java: Less known side of Enums</title>
<link>https://torokmark.github.io/posts/do-you-know-java-less-known-side-of-enums/</link>
<pubDate>Fri, 01 May 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-less-known-side-of-enums/</guid>
<description>Enums are easy and straigthforward at first sight, but this type has some hidden sides.
public enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY } For enumeration type, Java has a keyword called enum. That was introduced in Java 1.5. All enum types are implicitly inhereted from Enum class. Hence, all enum types has all methods that Enum has, like name, ordinal, etc. We cannot extend an enum, and enum does not extend custom types.</description>
</item>
<item>
<title>Easter Egg in C</title>
<link>https://torokmark.github.io/posts/easter-egg-in-c/</link>
<pubDate>Wed, 29 Apr 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/easter-egg-in-c/</guid>
<description>What does the following code print out?
#include &lt;stdio.h&gt; #define _ F--&gt;00||F-OO--; int F=00,OO=00;main(){F_OO();printf(&#34;%1.3f\n&#34;,4.*-F/OO/OO);}F_OO() { _-_-_-_ _-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_ _-_-_-_ } </description>
</item>
<item>
<title>Do you know Java: Execute Shell Commands</title>
<link>https://torokmark.github.io/posts/do-you-know-java-execute-shell-commands/</link>
<pubDate>Tue, 28 Apr 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-execute-shell-commands/</guid>
<description>Two ways are shown here about how to execute shell scripts and commands with Java.
In this post I am showing two ways to execute shell scripts or shell commands from a Java app.
ProcessBuilder ProcessBuilder class has been created to create and handle operating system processes.
ProcessBuilder#start method creates a single native process. Let us see how to do it.
ProcessBuilder builder = new ProcessBuilder(); builder.command(&#34;bash&#34;, &#34;-c&#34;, &#34;ping google.com&#34;); Process process; try { process = builder.</description>
</item>
<item>
<title>Do you know Java: Daemon Thread</title>
<link>https://torokmark.github.io/posts/do-you-know-java-daemon-thread/</link>
<pubDate>Sat, 25 Apr 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-daemon-thread/</guid>
<description>Application terminates when all threads are terminated. But what if some of them run endlessly?
Sometimes threads run until a condition is met, sometimes they run endlessly.
Once a thread is created and then started, it runs parallel with the main execution. Our app terminates when all threads are terminated including our main method as well.
What if a thread is infinite and still running though the main is already terminated?</description>
</item>
<item>
<title>Do you know Java: Use try-with-resource</title>
<link>https://torokmark.github.io/posts/do-you-know-java-try-with-resource/</link>
<pubDate>Fri, 24 Apr 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-try-with-resource/</guid>
<description>Try-with-resource gives a safer way to handle exceptions and resources.
A quite big drawback of try-catch-finally that we have to close resource at the end, otherwise the resource remains locked - not always, but sometimes!
So either we try not to forget to close the resouce, and place finally at the end, or apply something that does this job instead of us.
Try-Catch-Finally The hard part comes in finally, which encloses a try-catch, and null check is very easy to forget.</description>
</item>
<item>
<title>Do you know Java: Catch Multiple Exceptions</title>
<link>https://torokmark.github.io/posts/do-you-know-java-catch-multiple-exceptions/</link>
<pubDate>Wed, 25 Mar 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-catch-multiple-exceptions/</guid>
<description>Catching multiple exceptions is very useful when we are intended to do the same operations when they are raised.
The feature introduced in Java 7 and by using it we can place exceptions in the same catch branch.
The old way looked like as follows.
try { } catch (SQLException ex) { logger.log(ex); } catch (RemoteException ex) { logger.log(ex); } catch (NullPointerException ex) { logger.log(ex); } In Java 7 and onwards, we can place multiple exceptions in one catch branch.</description>
</item>
<item>
<title>Do you know Java: Instance from static launcher</title>
<link>https://torokmark.github.io/posts/do-you-know-java-static-launcher/</link>
<pubDate>Tue, 18 Feb 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-static-launcher/</guid>
<description>Instantiate the current class from its entry point by using static method. Interesting, isn&rsquo;t it?
I came across with JavaFX recently, and I saw an example about how to use it. This made me think, and brought the following question in my mind. How can we make an instance of the class that is the starting point of our application and how can we call its instance methods.
Let us see the code that we have if we start building a javafx application.</description>
</item>
<item>
<title>Do you know Java: PECS</title>
<link>https://torokmark.github.io/posts/do-you-know-java-pecs/</link>
<pubDate>Sat, 08 Feb 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-pecs/</guid>
<description>Do you remember the rule of PECS? If not, read the post quickly!
PECS stands for Produce-Extend, Consume-Super. What does that mean? Let us see an example with types from the standard.
Object void add(List&lt;Object&gt; list) { list.add(&#34;string&#34;); list.add(1); } Passing the followings are:
add(new ArrayList&lt;Object&gt;()); // not type safe add(new ArrayList&lt;String&gt;()); // compile time error The first is not type safe, the second one does not compile, since ArrayList&lt;String&gt; is not the subtype of List&lt;Object&gt;.</description>
</item>
<item>
<title>Do you know Java: JShell</title>
<link>https://torokmark.github.io/posts/do-you-know-java-jshell/</link>
<pubDate>Sun, 05 Jan 2020 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-jshell/</guid>
<description>JShell interpreter can process Java statements without requiring them to be placed in class and method body.
JShell interpreter and CLI were introduced in Java 9. That come handy when we would like to execute a statement, or call a subroutine to get their results.
Shell To enter the shell, we should type jshell in the command line and hit enter.
| Welcome to JShell -- Version 13 | For an introduction type: /help intro jshell&gt; | Welcome to JShell -- Version 13 | For an introduction type: /help intro jshell&gt; int i = 1 + 2; i ==&gt; 3 jshell&gt; System.</description>
</item>
<item>
<title>Do you know Java: Arrays as Generic Containers</title>
<link>https://torokmark.github.io/posts/do-you-know-java-arrays-as-generic-containers/</link>
<pubDate>Sat, 28 Dec 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-arrays-as-generic-containers/</guid>
<description>We can assign different type of elements to an array even the operation is accepted in compile-time, that raises error in run-time.
Sometimes Java is tricky, even it has static type system, we can assign different type of elements to an array, which is accepted in compile time, even array contains different type than the types of the element.
Covariance Let S &lt;: T mean that S is subtype of T and covariant is S &lt;: T =&gt; S' &lt;: T'.</description>
</item>
<item>
<title>Do you know Java: Parameter validation</title>
<link>https://torokmark.github.io/posts/do-you-know-java-parameter-validation/</link>
<pubDate>Sat, 21 Dec 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-parameter-validation/</guid>
<description>Checking method parameters is crutial to avoid inconvenient situations with null pointers or undesired values. Assertion and exception handling are two ways to give feedback to users about parameters.
What if we are intended to validate the parameters of a function? What if we liked to set up preconditions? How can we avoid working with null objects?
In this post we take a look at two approaches. At first, we see how we can check parameters with assertion and what its pros and cons are.</description>
</item>
<item>
<title>Interview: Implement a HashMap-like data structure in Java</title>
<link>https://torokmark.github.io/posts/interview-map/</link>
<pubDate>Sun, 15 Dec 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/interview-map/</guid>
<description>HashMap is one of the most used Map type in Java. A good experiment to implement our own one.
Not so long ago, I took a sit in an interview, and the interviewer asked me to implement a HashMap-like container which contains Integer types keys and Integer values. The trick was that I could not use any containers from the Collection API framework.
Steps we have to consider:
Basic API for our map!</description>
</item>
<item>
<title>Do you know Java: One more more more time</title>
<link>https://torokmark.github.io/posts/do-you-know-java-one-more-more-more-time/</link>
<pubDate>Mon, 18 Nov 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-one-more-more-more-time/</guid>
<description>Operators have arity. Sometimes we can make patterns out of them. Which is funny.
Every operator has an arity in Java. They can be either unary, binary, and ternary operators. Arity decides how many operands are accepted in the operation. This brings us the next riddle.
The Riddle What is the output of the next operation?
class Main { public static void main(String[] args) { int n = 0; int i = 1; n = i + + + + + + i; System.</description>
</item>
<item>
<title>Do you know Java: Underscore as identifier</title>
<link>https://torokmark.github.io/posts/do-you-know-java-underscore-as-identifier/</link>
<pubDate>Mon, 28 Oct 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-underscore-as-identifier/</guid>
<description>We could use underscore as a variable name until Java 7, but it cannot be used as an identifier from Java 9 and upwards.
Java has strict rules about how to name a variable, which characters are accepted in it or which one can be the first one. Underscore is a legal character among alphabetic characters and numbers. What if I did not use any other chars just underscore? Is that still valid variable name?</description>
</item>
<item>
<title>Ruby-like struct in Python #2</title>
<link>https://torokmark.github.io/posts/python-struct-2/</link>
<pubDate>Sat, 26 Oct 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/python-struct-2/</guid>
<description>Ruby provides a very handy type called OpenStruct to create objects. It brings the opportunity to add fields to objects during the runtime. Here is its Python counterpart.
In the previous post I showed Struct from esu which helps creating new types with fields and methods. That has a sibling, called OpenStruct which helps creating objects on the fly.
Usage Ruby&rsquo;s OpenStruct (doc:2.6.5) inspired it, and it looks as follows.</description>
</item>
<item>
<title>Ruby-like struct in Python</title>
<link>https://torokmark.github.io/posts/python-struct/</link>
<pubDate>Sat, 19 Oct 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/python-struct/</guid>
<description>Ruby provides a very flexible way to create new types with certain fields with Struct. Though Python does not have this functionality naturally, with esu package we can do the same.
Ruby types have rich API which is brought by the design, and the language features as well. Even though Python is very dynamic and flexible as well, some of the features are lacking in the languages.
In this post I would like to show you a Python package, name is esu, which brings a struct that can provide almost the same functionality.</description>
</item>
<item>
<title>Do you know Java: Varargs as Entry Point Parameter</title>
<link>https://torokmark.github.io/posts/do-you-know-java-varargs-in-entry-point/</link>
<pubDate>Tue, 15 Oct 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-varargs-in-entry-point/</guid>
<description>Java 5 was one of those versions that brought much more features and syntactic sugars than any other of them. Varargs is one of those. This provides a very comfortable way to pass different number of arguments to a method. Can we use it anywhere?
Varargs is just a syntactic sugar, it can be used in a more flexible way than its predecessor, the typed array. It has the same characteristics which means it supports indexing, it has an attribute called length, it is iterable.</description>
</item>
<item>
<title>Do you know Java: Underscores in Numeric Literals</title>
<link>https://torokmark.github.io/posts/do-you-know-java-underscores-in-numeric-literals/</link>
<pubDate>Thu, 05 Sep 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-underscores-in-numeric-literals/</guid>
<description>Underscore can be used in numeric literals to group digits in a numeric value. This way that can enhance code readability, decrease mistyping and helps visually keeping numeric values in range.
Code readability is one of the most important viewpoints of software development. The more readable the code is, the faster that can be understood by developers.
Java 7 introduced underscore as a comfortable way to separate digits of a numeric value into groups.</description>
</item>
<item>
<title>Do you know Java: Single Source File Code</title>
<link>https://torokmark.github.io/posts/do-you-know-java-single-source-file-code/</link>
<pubDate>Wed, 28 Aug 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-single-source-file-code/</guid>
<description>Java 11 introduced a new way of executing applications. That gives us the opportunity to do it without excplicitely compiling it. What&rsquo;s more, Java code can be run as a script.
In Java, compilation and execution of an app are two different steps. The java command gives us the feeling that we work with an interpreter.
The Pre-Java-11 era Compilation of the source code and execution of the app are separated commands before Java 11, as we see here:</description>
</item>
<item>
<title>Ruby's or operator precedence</title>
<link>https://torokmark.github.io/posts/rubys-or-operator-precedence/</link>
<pubDate>Fri, 23 Aug 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/rubys-or-operator-precedence/</guid>
<description>Operators have precedence and sometimes they can give us hard time to figure out why our code works as it does.
Ruby has three or operators, |, ||, and the readable or. All of them have different precedences. That is, the precedence, that makes some trouble if we do not care about which one we use.
The evaluation of logical operators are left-associative, that means the far left operator is evaluated at first, than its result will be the left operand of the next operator and so on.</description>
</item>
<item>
<title>Container types in shell script</title>
<link>https://torokmark.github.io/posts/container-types-in-shell-script/</link>
<pubDate>Thu, 15 Aug 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/container-types-in-shell-script/</guid>
<description>Shell script does not support container types like map, set, or queue, though with a third-party lib, presented here, we can use them in our scripts.
From time to time we need map, queue or any other kind of collections during our work. Shell script is definitely not the right choice to write applications but it may happen that we need some of the previously mentioned types to help our work.</description>
</item>
<item>
<title>Do you know Java: Entry Point in Interface or Enum</title>
<link>https://torokmark.github.io/posts/do-you-know-java-entry-point-in-interface/</link>
<pubDate>Fri, 09 Aug 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-entry-point-in-interface/</guid>
<description>All Java applications start with a class and an entry point in it. We can change the class type to others.
All Java applications start at one common point. That is a class which has at least one static method, called main as an entry point of the app. This method is called by JRE after the class is loaded when we execute java command with the appropriate name of the class.</description>
</item>
<item>
<title>Safe navigation in languages</title>
<link>https://torokmark.github.io/posts/safe-navigation-in-languages/</link>
<pubDate>Mon, 05 Aug 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/safe-navigation-in-languages/</guid>
<description>As we saw in the previous post, Ruby development team introduced a safe navigation operator to get rid of painful chaining of objects, which could raise NPE in case of null object in the middle. But Ruby is not the only language that came up with this idea. Most of the languages have introduced this operator, usually called null propagation, or some other approaches to achieve the same goal.
In this post I write some snippets to demonstrate what other languages provide to prevent the exception raised by referencing to a null object.</description>
</item>
<item>
<title>Benchmarking Ruby Control Flows and Datastructures</title>
<link>https://torokmark.github.io/posts/ruby-benchmark-control-flows/</link>
<pubDate>Sat, 03 Aug 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/ruby-benchmark-control-flows/</guid>
<description>Flexibility of Ruby brings many ways to achieve the same results, whether it is a loop, selection of elements from datastructures, or assignment of values.
Performance is one of the major metrics of an application. Ruby provides a module, natively brought by the language, called Benchmark, which helps us to observe the code and reflects the potential bottlenecks.
Sometimes that is very suprising which statement executes faster and which of them provides less performance.</description>
</item>
<item>
<title>Do you know Java: Double Brace Initialization</title>
<link>https://torokmark.github.io/posts/do-you-know-java-double-brace-initialization/</link>
<pubDate>Sun, 28 Jul 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/do-you-know-java-double-brace-initialization/</guid>
<description>Double brace initialization is a very comfortable way to add values to a collection or pairs to a map instance instead of having multiple statements next to each other.
One of the most popular languages, though Java is full of interesting parts that look wierd or unusual at first glance. In the sequence I call Do you know Java, I would like to present these less known or unexplained parts of the languages.</description>
</item>
<item>
<title>Safe navigation in Ruby</title>
<link>https://torokmark.github.io/posts/safe-navigation-in-ruby/</link>
<pubDate>Mon, 17 Jun 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/safe-navigation-in-ruby/</guid>
<description>Navigation through embedded objects can suprise us with an error if one of the fields, which are objects as well, is null. We are in the same situation if we have a hash object and want to get a value by key if key does not exist. The burning situation crops up if we chain up methods next to each other.
In this post I write some approaches, how to keep our code still clean, readable and safe if we liked to chain up calls next one another on an object or on a key-value pair container.</description>
</item>
<item>
<title>Pythonic way of count</title>
<link>https://torokmark.github.io/posts/pythonic-way-count/</link>
<pubDate>Tue, 09 Apr 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/pythonic-way-count/</guid>
<description>Writing code in a clean way differs in every language. Python also has its own style. Additionally, python is famous about its one-liners.
Pythonic way is an approach of how to use the language and how to take adventage of its syntax and semantic. Python can give a very elegant way of one-liners to achieve something that most of the languages can do, but not as short and still readable way as python does it.</description>
</item>
<item>
<title>Assertion framework in shell script</title>
<link>https://torokmark.github.io/posts/assertion-framework-in-shell-script/</link>
<pubDate>Sun, 31 Mar 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/assertion-framework-in-shell-script/</guid>
<description>A little lib that helps us checking our scripts with a unit test-like way.
The Missing Tool Unit testing is part of a lot of projects&rsquo; toolset. Though some part of the source code requires more attention than it gets payed. Shell scripts belong to them.
How can we make sure that our scripts do what we expect they do?
How can we make sure they are valid, return the right result&hellip;?</description>
</item>
<item>
<title>Implementing custom array in Python</title>
<link>https://torokmark.github.io/posts/implementing-custom-array/</link>
<pubDate>Wed, 27 Mar 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/implementing-custom-array/</guid>
<description>Python provides basic datastructures like dictionary, list, set, and tuple. If we need another datastruct which is different from the mentioned three, we have to implement ourones.
As I started using python in my daily work, more and more questions had cropped up about the language and its refinement. One of them was to implement a custom array.
What we would like to achieve is to have a datastruct which behaves like an array.</description>
</item>
<item>
<title>How to implement routing with n-ary tree</title>
<link>https://torokmark.github.io/posts/n-ary-routing/</link>
<pubDate>Tue, 19 Mar 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/n-ary-routing/</guid>
<description>Routing mechanism is one of the main parts of a web service. Here I provide one approach to achieve this. This implementation is based on n-ary tree and tree search.
Many ways are available to handle routes, from regex to n-ary trees to parse registered route one by one.
Different ways N-ary Trees In this approach we can consider the root node as / and all children nodes as route parts are separated by /.</description>
</item>
<item>
<title>The Multibuilder Pattern</title>
<link>https://torokmark.github.io/posts/multibuilder-pattern/</link>
<pubDate>Tue, 08 Jan 2019 12:00:00 +0100</pubDate>
<guid>https://torokmark.github.io/posts/multibuilder-pattern/</guid>
<description>In this post I would like to present a couple of solutions for builder pattern in python, and finally I show how I implemented a builder that I call multibuilder pattern.
Builder pattern comes in handy when we need to set a lot of fields of an object and we do not want to use many methods with multiple parameters.
All implementations are found in this repo: https://github.com/torokmark/builders_in_python
The Simple One Task: Let us implement a Person with the following fields like name, age, phone.</description>
</item>
<item>
<title>About</title>
<link>https://torokmark.github.io/about/</link>
<pubDate>Tue, 01 Jan 2019 17:51:15 +0100</pubDate>
<guid>https://torokmark.github.io/about/</guid>
<description>Thoughts about coding and everything.
Mark, software engineer and avid learner!
Java enthusiast and Ruby monk.
Software tinker and DevOps thinker.
GitHub :: https://github.com/torokmark Blog :: https://torokmark.github.io RSS :: https://torokmark.github.io/index.xml Gitter :: https://gitter.im/torokmark </description>
</item>
<item>
<title>Best practices to write an Entity in Spring/Hibernate</title>
<link>https://torokmark.github.io/posts/entity-best-practices/</link>
<pubDate>Mon, 01 Oct 2018 00:00:00 +0000</pubDate>
<guid>https://torokmark.github.io/posts/entity-best-practices/</guid>
<description>Every entity has to have a public default contstructor fetchType = FetchType.LAZY on @OneToOne, @OneToMany and @ManyToOne and other associations (EAGER is the default except @OneToMany) If an association is not mandatory: optional = false on association annotations @Column and @JoinColumn should contain nullable = false Entity should implement Persistable&lt;IDTYPE&gt; interface Create own interface with default implementation: public interface Identifiable extends Persistable&lt;Long&gt; { default isNew() { return getId() == null; } } All ids should be boxed like Long, Integer, String, etc.</description>
</item>
</channel>
</rss>