Puzzles
Puzzles copied to clipboard
OpenHFT Puzzles
= Puzzles Peter Lawrey
These are some Puzzles and exercises to get you thinking about low level Java programming and using Chronicle's OpenHFT software
While each answer is very short, and if you know it you can answer it quickly, it can take a significant amount of time to understand the code and find that answer.
This is typical of the work we do. We are not looking for large amounts of code or code changes, but thoughtful and necessary ones. Sometimes you can be the most productive changing a single line of code. Other days you might write hundreds of lines of code and documentation.
NOTE: These puzzles will exposure you to parts of Core Java and ways of using it that developers with 10 or 20 years experience may have never used it. In many cases, deliberately so as we are looking to put Java to its limits.
== Puzzlers
These are simpler Puzzlers where you have to make a short fit to the code and answer one or more questions
=== Setup
You will need
- Install an IDE such as link:https://www.jetbrains.com/idea/download/[IntelliJ Download]
- a Download ZIP of this repository, see the [Code] button in the top right and unpack it.
- Open the project via the
pom.xmlin your IDE. - Check you can do a maven install of the root project (on the right in IntelliJ)
=== Stack Traces
In link:https://github.com/OpenHFT/Puzzles/blob/main/Puzzlers/stack/src/main/java/net/openhft/stackpuzzler/PrintStackTraceMain.java[PrintStackTraceMain] the code prints the stack trace two different ways.
- Why does the stack trace include the createStackTrace method?
- Why is it different the second time. Hint: stepping through the code in your debugger should help.
In link:https://github.com/OpenHFT/Puzzles/blob/main/Puzzlers/stack/src/main/java/net/openhft/stackpuzzler/AnotherStackTraceMain.java[AnotherStackTraceMain] the code prints a stack trace from another thread.
- What does the line
at net.openhft.stackpuzzler.AnotherStackTraceMain.thinking(AnotherStackTraceMain.java:19)show? - There is a stack trace line
net.openhft.puzzlers.stack.AnotherStackTraceMain$$Lambda$1/214126413.runwhat does this mean?
=== Ping Pong example
In link:https://github.com/OpenHFT/Puzzles/blob/main/Puzzlers/CAS/src/main/java/net/openhft/caspuzzler/PingMain.java[PingMain.java] and link:https://github.com/OpenHFT/Puzzles/blob/main/Puzzlers/CAS/src/main/java/net/openhft/caspuzzler/PongMain.java[PongMain.java] two program alternate a value via shared memory.
- What does
10 * time / count / 10.0do? - What is the difference between milli-seconds, micro-seconds, nano-seconds?
- When you run these two programs, what are the results?
- How do you know this is writing to memory but not to disk with each operation?
== Exercises
These are exercises where you need to write some code and provide longer answers.
TBD