gudii9
asked on
java 8 new features
Hi,
I heard java 8 has bunch of new features. Especially java 8 has different way to deal with strings. Where can i find new features. How the == in java 8 string operation different from earlier versions. please advise
I heard java 8 has bunch of new features. Especially java 8 has different way to deal with strings. Where can i find new features. How the == in java 8 string operation different from earlier versions. please advise
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Interesting articles:
What's New in JDK 8
What's New in Java 8
Java 1.8 (JDK8): What's new? Code examples and performance
ASKER
https://blog.codecentric.de/en/2014/08/string-deduplication-new-feature-java-8-update-20-2/
With Java 8 Update 20 we now have access to a new feature called String Deduplication, which requires the G1 Garbage Collector and is turned off by default.how to turn it on. I wonder why it is risk?
The article explains how to turn it on - you need to set a flag when starting Java:
-XX:+UseStringDeduplicatio n
String a = "hello" ;
String b = "h" + "ello" ;
// Java says this test may fail (because a and b are not required to point to the same object in memory)
if (a == b) { ... }
// Java says this test will always succeed, because a and b both have the value "hello"
if (a.equals(b)) { ... }
Doug
-XX:+UseStringDeduplicatio
I wonder why it is risk?Using == for string equality is a risk. You should use ".equals()" to make sure your code is correct.
String a = "hello" ;
String b = "h" + "ello" ;
// Java says this test may fail (because a and b are not required to point to the same object in memory)
if (a == b) { ... }
// Java says this test will always succeed, because a and b both have the value "hello"
if (a.equals(b)) { ... }
Doug
ASKER
The article explains how to turn it on - you need to set a flag when starting Java:
-XX:+UseStringDeduplication
how to turn it on my windows 7 dell laptop. I do have java on it. But i never remember starting java on my laptop. please advise on how to set it on and test
When you run any program written in Java, you have to launch Java to run it.
This usually looks something like:
java -jar myjar.jar
To run it with this String dedup turned on you 'd do:
java -XX:+UseStringDeduplicatio n -jar myjar.jar
If you're using Eclipse to run your Java programs for you, you'd need to figure out where to enter these "JVM parameters" inside Eclipse. (I don't use Eclipse myself - so I can't help with that one).
Doug
This usually looks something like:
java -jar myjar.jar
To run it with this String dedup turned on you 'd do:
java -XX:+UseStringDeduplicatio
If you're using Eclipse to run your Java programs for you, you'd need to figure out where to enter these "JVM parameters" inside Eclipse. (I don't use Eclipse myself - so I can't help with that one).
Doug
ASKER
If you're using Eclipse to run your Java programs for you, you'd need to figure out where to enter these "JVM parameters" inside Eclipse. (I don't use Eclipse myself - so I can't help with that one).
i am using eclipse amost 99% of the projects, cases. I wonder what you use for development.
I searched on where to enter these "JVM parameters" inside Eclipse, but could not find any solid answer yet
>> I searched on where to enter these "JVM parameters" inside Eclipse, but could not find any solid answer yet
You enter
>> I wonder what you use for development.
I use IntelliJ IDEA (not free)
You enter
-XX:+UseStringDeduplication
in the "VM Arguments" text box of the "Arguments" tab (cf. screenshot 2 of this page)>> I wonder what you use for development.
I use IntelliJ IDEA (not free)
ASKER
i will try
I use IntelliJ IDEA (not free)I also use IntelliJ and while there is a paid version, there is also a free version. It's called the "Community" edition.
You can get it here:
https://www.jetbrains.com/idea/download/
Doug
i will try... and the outcome is?