Pair is missing in Java 11. JavaFX is no longer part of the JDK.
Create Date: October 22, 2020 at 06:01 PM         | Tag: JAVA         | Author Name: Sun, Charles |
Five Alternative to Pair Class in Java
Java - How to create new Entry (key, value)
There's public static class AbstractMap.SimpleEntry
. Don't let the Abstract
part of the name mislead you: it is in fact NOT an abstract
class (but its top-level AbstractMap
is).
The fact that it's a static
nested class means that you DON'T need an enclosing AbstractMap
instance to instantiate it, so something like this compiles fine:
Map.Entry entry =
new AbstractMap.SimpleEntry("exmpleString", 42);
As noted in another answer, Guava also has a convenient static
factory method Maps.immutableEntry
that you can use.
You said:
I can't use
Map.Entry
itself because apparently it's a read-only object that I can't instantiate newinstanceof
That's not entirely accurate. The reason why you can't instantiate it directly (i.e. with new
) is because it's an interface Map.Entry
.
Caveat and tip
As noted in the documentation, AbstractMap.SimpleEntry
is @since 1.6
, so if you're stuck to 5.0, then it's not available to you.
To look for another known class that implements Map.Entry
, you can in fact go directly to the javadoc. From the Java 6 version
Interface Map.Entry
All Known Implementing Classes:
Unfortunately the 1.5 version does not list any known implementing class that you can use, so you may have be stuck with implementing your own.
New CommentUnderstanding Your Performance Characteristics
Create Date: September 07, 2019 at 10:46 AM         | Tag: JAVA         | Author Name: Sun, Charles |
Performance tuning:
- microbenchmarking
- statistical measurements
- database query tuning
- concurrency basics
- understand your performance characteristics
- java application profiling
- jvm tuning
- search and data structures
- memory management
- optimizing concurrent code
- avoid doing expensive operations
Utilization, Saturation and Errors method (USE)
- CPU cycle
- RAM capacity
- Disk capacity
- Disk I/O
- Network I/O
//check version
lsb_release -a
vmstat 1 10
sudo apt install sysstat
iostat -xm
- netstat
- nicstat
- typeperf
- sar
- GUI tools
Performnace measurements:
- latency (response time): is the amount of time required to complete a unit of work
- elapsed time: measures the time taken for a batch of operations to complete
- throughput: is the amount of work that an application can accomplish per unit of time
The higher the latency of an application, the higher it's throughput is.
New Comment
Venkat Subramaniam: Kotlin for Java Programmers
Create Date: August 14, 2019 at 06:17 PM         | Tag: KOTLIN         | Author Name: Sun, Charles |
here's so much you know as a Java programmer and yet there is so much more that Kotlin offers. It's a language that is built on strong foundations and, at the same time, brings along phenomenal concepts to favor low ceremony, fluency, sensible warnings, safe types, pragmatic mixture of object-oriented and functional programming, and so much more.
In this presentation, you'll start with what you already are familiar with, and dive into Kotlin, to learn about its strengths and capabilities.
About Dr. Venkat Subramaniam
Dr. Venkat Subramaniam is an award-winning author, founder of Agile Developer, Inc., creator of agilelearner.com, and an instructional professor at the University of Houston.
He has trained and mentored thousands of software developers in the US, Canada, Europe, and Asia, and is a regularly-invited speaker at several international conferences. Venkat helps his clients effectively apply and succeed with sustainable agile practices on their software projects.
Venkat is a (co)author of multiple technical books, including the 2007 Jolt Productivity award winning book Practices of an Agile Developer. You can find a list of his books at agiledeveloper.com. You can reach him by email at venkats@agiledeveloper.com.
You can find Venkat on Twitter @venkat_s (https://twitter.com/venkat_s).
what's kotlin:
- statically typed
- compiles to
- java
- javascript
- fluent, elegant, brings wonderful features enjoyed in other language
programming in kotlin
- semicolon is optional
- sensible warnings
- type inference
- val vs var
- string templates
- multiline strins
- trimmargin() or trimMargin("|")
- expression over statements
Functions:
- let's have some fun
- return type inference
- specifying return type
- void function
- default arguments
- can use previous parameters
- named arguments
- mixing positional and named arguments
- vararg and spread
For and Range:
- for x in 1..10
- until
- step
- downTo
- downTo and step
- over a listOf
- indices
when:
- value
- else
- multiple values
- in
- type is
- auto casting
Null Type;
- return
- parameter
- ?. and ?:
- auto casting
functional style:
- creating a lambda expression
- fileter, map, reduce
extension methods:
- classes are open
- not really part of the class
00:
classes
- finall by defaul
- properties
- backing fields
- private set
- static methods
- companion objects
- data classes
- properties
- componentN()
- inheritance
Delegation:
- lazy
- to delegate
Fluency:
- infix