Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

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
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

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?
Avatar of dpearson
dpearson

The article explains how to turn it on - you need to set a flag when starting Java:
-XX:+UseStringDeduplication

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
Avatar of gudii9

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:+UseStringDeduplication -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
Avatar of gudii9

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
-XX:+UseStringDeduplication

Open in new window

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)
Avatar of gudii9

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?