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
LVL 7
gudii9Asked:
Who is Participating?
 
dpearsonCommented:
There was a capability added recently which allows strings to be "de-duplicated" so you only have 1 instance at a time with the same character array:  https://blog.codecentric.de/en/2014/08/string-deduplication-new-feature-java-8-update-20-2/

I guess if you enabled that, you might be able to do string comparisons using == rather than .equals() but that seems risky at best.

There's lots of big changes that came in with Java 8 - but I don't think Strings were really changed.  If you're interested in the new features there's a nice summary here:
http://blog.takipi.com/5-features-in-java-8-that-will-change-how-you-code/

but explaining those features is well beyond the scope of this question :)

Doug
0
 
rrzCommented:
I just saw this
http://java.dzone.com/articles/joining-strings-jdk-8 
I don't know why I haven't heard about these before now.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
zzynxSoftware engineerCommented:
0
 
gudii9Author Commented:
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?
0
 
dpearsonCommented:
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
0
 
gudii9Author Commented:
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
0
 
dpearsonCommented:
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
0
 
gudii9Author Commented:
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
0
 
zzynxSoftware engineerCommented:
>> 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)
0
 
gudii9Author Commented:
i will try
0
 
dpearsonCommented:
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
0
 
zzynxSoftware engineerCommented:
i will try
... and the outcome is?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.