Loading...

Follow Random Thoughts on Java Programming on Feedspot

Continue with Google
Continue with Facebook
or

Valid

The times move fast. Must faster than I do, when it comes to computer hardware.

As mentioned in the last blog, I would reveal what kind of monitor I have been using for all this time.

Above is a picture of my new setup.

The Old Monitor

An Iiyama original. The Vision Master Pro 454 HM903DT B

It was quite a good monitor at the time and it did manage to perform fine for decades.

The New Monitor

The new monitor is visible at the top of the blog. It's a HP1 Z2n G2 27 inch monitor and it is awesomeness.

Some notes:

the stand very sturdy heavy metal adjustable stand incredible contrast especially compared to my old monitor. I had to up the anti-aliasing on my games, as the jaggies were very noticeable, now that the contrast is awesome. easy setup just a little difficult to find the buttons. the brightness the brightness needs some getting used to, especially if the screen is a bright white. Especially in the evenings, the brightness needs to be turned down. size/weight it's obviously a huge difference in size and weight. The desktop (the real one) has a lot more real estate now. Getting used to having more room to put the keyboard. energy I expect a lot of energy savings with the new monitor, as well as a reduction in generated heat. operating system zero problems in all my operating systems in getting the highest resolution. Almost didn't have to do anything at all.

Conclusion: with the new graphics card and the new monitor I sit and stare in silent admiration at the beautiful images that my games can conjure up for me.

References HP Website - HP Z27n G2 27 Monitor https://store.hp.com/NetherlandsStore/Merch/Product.aspx?id=1JS10AT&opt=ABB&sel=MTO
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I tend to postpone upgrading my computers until it either breaks down or it gets too cramped in performance/memory/etc. This tends to take a long time.

So a colleague of mine was upgrading his computer, and I managed to get his old graphics cards.

Seeing as I am on a budget, I was looking into what the difference in performance were for second hand graphics cards.

A lot of graphics cards are replaced because there are better ones, even though the old cards still work perfectly fine.

And he just happens to buy the latest and greatest, which is still a pretty good deal after 7 years, compared to what I buy.

My original graphics card

It's a AMD Radeon HD 5700 Series.

"New" graphics card

It's a Nvidia GeForce 770.

Notes

Some notes of mine.

typeyou cannot tell any more what kind of graphics card it is from just looking at the physical hardware. With any luck you can find the manufacturer, but that's it. There's just not more room or not important.external connectorsSo, no more VGA connector. And of course my old monitor only has a VGA Connector. (Don't ask, I'll write about it in the next blog about how ancient it is). It gave me an excuse to upgrade my monitor.internal power cable for PCI Express cardsThe old graphics card had only one internal power connector, a 6 pin. The new graphics card had both a 6 pin and an 8 pin. Time to look in the attic for my spare cables box.noiseit's rather depressing that the new graphics card has three fans and is more quiet than my old graphics card which has only one fan.heavinesswith all the fans, and the cooling fins, this new graphics card is a seriously heavy beast in pure weight. I hope my motherboard can cope with it.plasticinstead of screws, my case has plastic easy-to-use click-and-go thingies to fasten cards. Of course, plastic is the first thing to become brittle after several years. No surprises there.

All in all, I am extremely happy. Except for a few little surprises mentioned above, I had the entire setup working relatively quickly.

ReferencesNVidia - GeForce GTX 770https://www.geforce.com/hardware/desktop-gpus/geforce-gtx-770/specifications
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Back from vacation.

Just quickly putting this in my notes:

$ cd payara5
$ cd bin
$ ./asadmin delete-domain
Enter the value for the domain_name operand> domain1
Domain domain1 deleted.
Command delete-domain executed successfully.
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I recently wished to convert some of my childrens DVDs to MP4, so I could put them on their individual tablets.

I've dabbled with this in the past, on Linux, and it has always been quite a chore to do.

Everything from obscure commandline commands and GUIs that provided a lot of options that were basically meaningless to me (without proper research).

Of course, this caused a lot of grief. Sound not synchronised to the video, or the entirely wrong soundtrack, or converted only the trailers, etc.

But recently I found Handbrake1, and I was much impressed. A nice gui that only takes a little while to learn, and only for special cases (say for example if you do not wish to have the default English soundtrack).

It has sensible defaults.

The only issue was the installation, as it requires, of course, libcss and all that.

References[1] Handbrakehttps://handbrake.fr/
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I was talking with a colleague on the way home, when we started talking about his troubles with his bike.

In short, he could turn the pedals like crazy, and the bike was not moving an inch.

That's when I realized that this is a perfect example of the difference between Unit Testing and Integration Testing.

In short:

unit test

write a unit test, to see if we can properly turn the pedals in the proper direction.

Conclusion: Success! Software works fine. In fact it works extremely well. We achieved a performance increase of over 500%! Yay!integration test

write an integration test, to see if when we turn the pedals, the bicycle will move.

Conclusion: Failure! Pedals turn fine, but the bicycle doesn't move.

It turns out the integration between the component "pedals" and the component "wheels" was busted.

It totally shows that though Unit tests may all pass, it is not a guarantee that your software is actually doing what it should.

Lesson learned.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

So, sometimes when you have an existing software structure, with lots of domain rules inside, it becomes difficult to change. Especially when there is a lot of cohesion between your classes.

This is the problem of tight coupling, as opposed to loose coupling1.

I recently encountered this in our software.

And of course, I needed to change something deep inside.

Now, I didn't need to change anything about the domain logic. It was very good and working as intended.

But I needed a change purely for technical reasons. In this case, the domain logic was used in a Batch Processing on Hibernate Entities, and the domain logic was (in this case, not normally) generating a lot of Entities, and they were all persisted in the Session Context, which naturally grew. And then the dirty check and the session closing takes a long time, etc, etc. See reference [2] on why this's bad.

So I was looking for a way to persist entities, without adding them to all the collections with the CascadeType without changing the domain logic too much, and also keep the default behaviour as standard.

I didn't want to use inheritance, as it was a persisted Hibernate Entity.

So, I came up with the following hack:

Quite simply, I can now add behaviour to an Entity when I need it.

For example:

As me and my colleague say "A seemingly innocent first step on a slippery slope to hell."

Of course, this kind of abuse has always been possible, but it is now easier to do than ever (without having to create an entire class for the priviledge).

References[1] Wikipedia - Loose couplinghttps://en.wikipedia.org/wiki/Loose_coupling[2] Vlad Mihalcea - The best way to do batch processing with JPA and Hibernatehttps://vladmihalcea.com/the-best-way-to-do-batch-processing-with-jpa-and-hibernate/
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

I recently had to do a insert on the database, if the records weren't there, and an update if it was.

Performance was a problem.

Colleague of mine had the same problem when using an insert and update statement with an (exists (select 1)) on 2.5 million records.

After 5 minutes, 5000 rows were done. It would have taken 41 hours to fix them all.

After a merge1 statement, the entire thing was done in 2.5 minutes.

So, I had to get to grips with the merge statement as well. I hadn't used it before.

There's plenty of tutorials on how it works.

Oracle allows a DELETE statement in the MERGE statement, which seems not to be defined in the SQL Standard.

References[1] Wikipedia - Merge(SQL)https://en.wikipedia.org/wiki/Merge_(SQL)[2] Oracle PL/SQL Documentation - MERGEhttps://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_9016.htm#SQLRF01606
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Using Optional is hard in the beginning.

Especially for first-timers one has a tendency to use the wrong methods.

Take the following sequence of refactoring for example:

First without any kind of Optional:

A first bad attempt at an optional:

It looks like the person just... kind of removed the Optional back to a situation that he knew and was more familiar with.

Let's try this again:

Now this is a good try. It is very common to see the two Optional class methods being used together. isPresent() and get().

But we can do better.

It's often the same: we wish to do something, only when there's a value available.

Like so:

Of course, it's sometimes better to create a method reference:

But I do find this proliferates the number of methods, but it's an acceptable side effect.

We finally arrive at something concise and easy to read, once you get the hang of it.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Some time ago, I received a security notification from Github regarding a vulnerability1 2 in Antisamy.

It took me a while to find out that it was a false positive.

But the issue in [1] did mention that Antisamy seems to be lacking a maintainer. A worthwhile replacement was suggested as being HTML Sanitizer3 5 6.

I started using the HTML Sanitizer in my project and I like it. The fact that I don't need an XML configuration file is a plus.

There's a StackOverflow answer on why and how of the two projects4.

Only thing missing are the policy configuration files from AntiSamy, which are not present in any way in HTML Sanitizer, so you either have to write your own or get them from here7.

The file is called HTMLSanitizerAntiSamyPolicy.java.

References[1] Github - Antisamy issueshttps://github.com/nahsra/antisamy/issues/32[2] CVE details - CVE-2018-1000643https://www.cvedetails.com/cve/CVE-2018-1000643/[3] OWASP Java HTML Sanitizer Projecthttps://www.owasp.org/index.php/OWASP_Java_HTML_Sanitizer_Project[4] Java: Owasp AntiSamy vs Owasp-java-html-sanitizehttps://stackoverflow.com/questions/28577738/java-owasp-antisamy-vs-owasp-java-html-sanitize/29259874[5] GitHub - OWASP/java-html-sanitizerhttps://github.com/OWASP/java-html-sanitizer[6] MailingList - HTML Sanitizerhttps://lists.owasp.org/pipermail/owasp-leaders/2011-March/004883.html[7] GitHub - ESAPI/esapi-java-legacy - New file to use Java HTML Sanitizer that implements old AntiSamy poliā€¦https://github.com/ESAPI/esapi-java-legacy/commit/d48e5a6f07601322c44c113058526eb133b777a5#diff-72ca1caf39f169db1ab83d2af2ec6cc3l
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

So, as often happens, I encountered the following code at work:

It's basically a zipped file, containing other zipped files, containing supermarket sales item data. This little bit of code just decides if a file should be parsed.

SonarLint quite rightly complained "Refactor this method to reduce its Cognitive Complexity".

And I quite quickly came up with the thought that it's really a list, where we can stop evaluating the list after the first match.

So, it becomes something like:

But, of course we have streams now:

It looks better, no?

It's a trivial example, but I like it.

Read for later

Articles marked as Favorite are saved for later viewing.
close
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview