Jdeveloper shouldn't suggest not using new + contructor for Strings

Hullo all,
I found a snippet of code on the net which was quite instructive . 5 string creation/assignments and 5 equality tests :
String s1 = "abc";
String s2 = s1;
String s5 = "abc";
String s3 = new String("abc");
String s4 = new String("abc");
System.out.println("== comparison :" + (s1 == s5));
System.out.println("== comparison : " + (s1 == s2));
System.out.println("Using equals method : " + s1.equals(s2));
System.out.println("== comparison : " + s3 == s4);
System.out.println("Using equals method : " + s3.equals(s4));
now, in Jdev11g if you create a String using "new" it grumbles about it : "superfluous string constructor should be removed"
However, it turns out that String s1 = "zzz" and String s1 = new String("zzz") are very different things in java.
Run the code above to see what I mean. There are five comparison tests. You would expect them all to be "true" but
the fourth comparison : System.out.println("== comparison : " + s3 == s4); returns FALSE.
My understanding is that this is due to the optimization of "immutibility of strings" When you say :
String s1 = "zzz" and String s2 = "zzz" then the characters "zzz" exist only once in the heap and both s1 and s2, secretly, reference the same storage, at least until the value is changed.
However using the 'new' keyword forces the JVM to create two separate strings, hence the false result for test #4.
It's nit-picking I know, but I personally found the above code snippet quite instructive, which shows the difference between the statements.

Hi Colin,
good point about the difference in how specifc JVM's (my assumption) can treat this differently.
You can turn off this behaviour via Preferences->Audit->Profiles->Edit then under Rules->API->String Constructor
Best,
John

Similar Messages

  • Why not use "new" operator  with strings

    why we not use new when declaring a String .because in java String are treated as objects. we use new operator for creating an object in java .
    and same problem wiht array when we declare array as well as initialize .here we are alse not using new for array
    why

    Strings aren't just treated as objects, Strings are Objects.
    As for why not using new for Strings, you can, if you want.:
    String str = "this is a string";
    and
    String str = new String("this is a string");
    do the same thing (nitty-gritty low level details about literals aside). Use whatever you like, but isn't it simpler not to type new String(...) since you still need to type the actual string?
    As for arrays, you can use new:
    int[] ints = new int[10];
    or
    int[] ints = { 0, 1, 2, 3, ..., 9 };
    But the difference here is you are creating an empty array in the first one, the second creates and fills the array with the specified values. But which to you often depends on what you are doing.

  • HT5463 I changed  password but can not use new password on phone. Why?

    I changed  password but can not use new password on phone. Why?

    Start with the Settings app
    Settings > iTunes and App Store > tap on your Apple ID and then tap on Sign Out
    Then sign in with your correct Apple ID and password.

  • Why JSP not use new class that I compile again?

    I use bean class with JSP. But When I add some code and compile new bean. JSP not use new been class it use old class.
    I try to set file server.xml and set <DefaultContext reloadable="true"/> and restart Tomcat. But it not work?
    any help please?

    I run JSP in http://localhost:8080/stringbean.jsp
    is context name mean localhost
    in c:\tomcat\work has following directory
    standalone (level1 dir)
    localhost (level2 dir)
    - (level3 dir)
    examples (level3 dir)
    manager (level3 dir)
    tomcat-doc (level3 dir)
    webdav (level3 dir)

  • When I use my IPhone 4S to view the Shaw Go Movie Central App when I am at home I only use WiFi which is automatic, I start watching a show and sometimes I will get a message like "you can not use your cellular for video playback" or something close to th

    When I use my IPhone 4S to view the Shaw Go Movie Central App when I am at home I only use WiFi which is automatic, I start watching a show and sometimes I will get a message like "you can not use your cellular for video playback" or something close to that. Then I received an email from Telus saying I had used my 3G instead of Wi-Fi  using 75% of my data. How can this happen when I'm on Wi-Fi at home? If it switched to 3G for some reason I should have been disconnected and not just transferred to 3G network using up my data. What is the fix for this??

    It doesn't have to be that complicated, Verizon iPhones come unlocked, just tell VZ you're going on Holiday/Traveling and suspend the service, no need to pay for service if you're not going to be using it. Pick up local SIM cards in the countries of your choosing, pop them in, re-activate iMessage and you're set!
    I recommend getting a SIM card from the Three network in England, they have great EU roaming rates and free like-home roaming in Italy.
    Set your phone's region to match the country you're in, it'll save from some headaches when calling local/international numbers.
    To answer your questions,
    1. If you choose not to have a local SIM card, it is good to keep your phone in Airplane mode to save battery.
    2. Make sure the two iPhones have different names to reduce sync/restore issues.
    3. If husband has an iPhone also, you can chat with iMessage/Facetime, just give him heads up about the new number you'll have. Otherwise, use Whatsapp if he's got an Android. You can activate Whatsapp with your American number or the international number if you choose to get a SIM in Europe.
    Also, Get the MagicJack app and/or Google Hangouts, both of those apps provide you with free calling to the USA and Canada using any internet connection. Google Voice is another good way to SMS across the seas.
    Let me know if you need any more tips for iPhoning across the pond.

  • "do not use proxy server for local (intranet) addresses" IEM setting

    Hi, i would like to find out where can i find the following setting in GPO which used be found in IEM.
    "do not use proxy server for local (intranet) addresses" Enabled/Disabled
    as currently im setting the IE proxy exception list via GPP, i don't see that option.

    Hi,   
    As you notice that when we use GPP Internet Setting item to configure bypass proxy servers, there is no "do not use proxy server for local (intranet) addresses" option in GPP Internet
    Setting item. However, as suggested by zanderol24’s reply, we can use bypass proxy server for local addresses option under
    Proxy server to achieve the same function.
    Best Regards,
    Erin

  • Could not allocate new page for database 'TEMPDB'

    Dear All,
    When I try to fill up the aggregate of a cube, the job is cancelled after 16484 Seconds due to runtime error .
    I couldnt do fillup though I tried lot of times. The system log information is given below.
    Database error 1101 at EXE
    Could not allocate new page for database 'TEMPDB'. There are no more pages available in filegroup DEFAULT. Space can be created by dropping objects, adding additional files, or allowing file growth
    Database error 1101 at EXE
    Perform rollback
    Run-time error "UNCAUGHT_EXCEPTION" occurred
    Short dump "080101 025044 Eapsapp1 POTARU91" generated
    Transaction Canceled 00 671 ( UNCAUGHT_EXCEPTION 20080101025044Eapsapp10021 POTARU91 0011 )
    Perform rollback
    System Details:
    BW Version : 3.5
    Support Level: 19
    Datebase : MS SQL Server 2000
    Cube's E Table Details:
    Total Rows : 318,230,953
    Data Szie(KB) : 121,358,760
    Index(KB) : 55,241,264
    Min. Row Size: 371
    Max Row Size: 393
    TEMPDB database information:
    DB Size(MB): 139,999
    Size Used(MB): 3
    Free (MB): 139,996
    Log Size(MB): 342
    Log Used(MB): 117
    TEMPDB is having 9 Database files. Out of nine, three database file information is given below.
    Logical File Name: tempdev
    File Size(MB): 20,000
    Used Space(MB): 0
    File Size Limit(MB): 20000
    File Growth Step: 250MB
    Free on Disk(MB): 459,204
    Logical File Name: tempdb_1_Data
    File Size(MB): 14,999
    Used Space(MB): 0
    File Size Limit(MB): 15000
    File Growth Step: 550MB
    Free on Disk(MB): 2,674
    Logical File Name: tempdb_2_Data
    File Size(MB): 15,000
    Used Space(MB): 0
    File Size Limit(MB): 15000
    File Growth Step: 0MB
    Free on Disk(MB): 2,674
    Collectively for all the 9 database file size is 140GB.
    Please let me know what has to be changed in above TEMPDB size settings to avoid the issue in future.
    Advanced Thanks for your solution for this issue.
    Regards
    Guna.

    Hello,
    as the message stated correctly is the tempdb full:
    Logical File Name: tempdev
    File Size(MB): 20,000
    File Size Limit(MB): 20000
    Logical File Name: tempdb_1_Data
    File Size(MB): 14,999
    File Size Limit(MB): 15000
    Logical File Name: tempdb_2_Data
    File Size(MB): 15,000
    File Size Limit(MB): 15000
    All files of the tempdb are restricted in size and already expanded to their maximum size. You now can either
    - add another file on a disk with free space and let the file grow
    - let the existing files grow to an higher amount
    Best regards
      Clas

  • Media Encoder CC not using GPU acceleration for After Effects CC raytrace comp

    I created a simple scene in After Effects that's using the raytracer engine... I also have GPU enabled in the raytracer settings for After Effects.
    When I render the scene in After Effects using the built-in Render Queue, it only takes 10 minutes to render the scene.
    But when I export the scene to Adobe Media Encoder, it indicates it will take 13 hours to render the same scene.
    So clearly After Effects is using GPU accelleration but for some reason Media Encoder is not.
    I should also point out that my GeForce GTX 660 Ti card isn't officially supported and I had to manually add it into the list of supported cards in:
    C:\Program Files\Adobe\Adobe After Effects CC\Support Files\raytracer_supported_cards.txt
    C:\Program Files\Adobe\Adobe Media Encoder CC\cuda_supported_cards.txt
    While it's not officially supported, it's weird that After Effects has no problem with it yet Adobe Media Encoder does...
    I also updated After Effects to 12.1 and AME to 7.1 as well as set AME settings to use CUDA but it didn't make a difference.
    Any ideas?

    That is normal behavior.
    The "headless" version of After Effects that is called to render frames for Adobe Media Encoder (or for Premiere Pro) using Dynamic Link does not use the GPU for acceleration of the ray-traced 3D renderer.
    If you are rendering heavy compositions that require GPU processing and/or the Render Multiple Frames Simultaneously multiprocessing, then the recommended workflow is to render and export a losslessly encoded master file from After Effects and have Adobe Media Encoder pick that up from a watch folder to encode into your various delivery formats.

  • I cannot load Maverick on my iMac HD.  It reports that my HD is used for Time Machine backups and will not load to that drive.  I do not use this drive for backups.  Help.

    I cannot load Maverick on my iMac HD.  It reports that my HD is used for Time Machine backups and will not load to that drive.  I do not use this drive for backups.  I use an external 1 TB WD My Book for backups as well as Super Duper Backups. Can anyone offer advice.   Thanks.

    Welcome to Apple Support Communities
    You have got the "Backups.backupdb" folder in the root level of your hard drive. This is the folder used by Time Machine to save backups to, and the OS X Mavericks installer thought that your hard drive is being used to store Time Machine backups
    To fix this, open a Finder window, select the Go menu (on the menu bar) > Go to Folder, and type:
    Then, delete "Backups.backupdb" and empty the Trash. Finally, open the Mavericks installer from the Applications folder and follow the steps

  • I'm a normal user, using cad programme, not using my laptop for games, my question is: do I need to get 16 gb ram in my retina macbook pro or 8  gb ram is pretty enough?

    I'm a normal user, using cad programme, not using my laptop for games, my question is: do I need to get 16 gb ram in my retina macbook pro or 8  gb ram is pretty enough?
    Thanks for support.

    8 GB may be sufficient for CAD but 16 would be a much better idea.
    All the Macs I have ever owned were eventually upgraded to the maximum amount of memory they could use. Considering that as of now, the RAM you specify is all the RAM you will ever have, get as much as you can. That is the only way to maximize its economic life.
    If Apple offered a 32 GB version I'd get it.

  • Why not use Redo log for consistent read

    Oracle 11.1.0.7:
    This might be a stupid question.
    As I understand if a select was issued at 7:00 AM and the data that select is going to read has changed at 7:10 AM even then Oracle will return the data that existed at 7:00 AM. And for this Oracle needs the data in Undo segments.
    My question is since redo also has past and current information why can't redo logs be used to retreive that information? Why is undo required when redo already has all that information.

    user628400 wrote:
    Thanks. I get that piece but isn't it the same problem with UNDO? It's written as it expires and there is no guranteee until we specifically ask oracle to gurantee the UNDO retention? I guess I am trying to understand that UNDO was created for effeciency purposes so that there is less performance overhead as compared to reading and writing from redo.And this also you said,
    >
    If data was changed to 100 to 200 wouldn't both the values be there in redo logs. As I understand:
    1. Insert row with value 100 at 7:00 AM and commit. 100 will be writen to redo log
    2. update row to 200 at 8:00 AM and commit. 200 will be written to redo log
    So in essence 100 and 200 both are there in the redo logs and if select was issued at 7:00 data can be read from redo log too. Please correct me if I am understanding it incorrectly.I guess you didnt understand the explaination that I did. Its not the old data that is kept. Its the changed vector of Undo that is kept which is useful to "recover" it when its gone but not useful as such for a select statement. Whereas in an Undo block, the actual value is kept. You must remember that its still a block only which can contain data just like your normal block which may contain a table like EMP. So its not 100,200 but the change vectors of these things which is useful to recover the transaction based on their SCN numbers and would be read in that order as well. And to read the data from Undo, its quite simple for oracle to do so using an Undo block as the transaction table which holds the entry for the transaction, knows where the old data is kept in the Undo Segment. You may have seen XIDSEQ, XIDUSN, XIDSLOT in the tranaction id which are nothing but the information that where the undo data is kept. And to read it, unlke redo, undo plays a good role.
    About the expiry of Undo, you must know that only INACTIVE Undo extents are marked for expiry. The Active Extents which are having an ongoing tranaction records, are never marked for it. You can come back after a lifetime and if undo is there, your old data would be kept safe by oracle since its useful for the multiversioning. Undo Retention is to keep the old data after commit, something which you need not to do if you are on 11g and using Total Recall feature!
    HTH
    Aman....

  • I have received text messages from mailer-daemon. Do not use my 4S for email. Is it a virus?

    I have received 2 text message from 'mailer-daemon'  I do not use my 4S for email. Is it a virus?

    No

  • Ipad2 does not change orientation. I have not used the switch for lock rotation it is used for mute

    Ipad2 does not change orientation. I have not used the switch for lock rotation it is used for mute

    Is there a lock symbol at the top of the screen next to the battery indicator ? If so, and as you've got the switch set to notification mute, then have you checked the taskbar (the function that the switch isn't set to is controlled via the taskbar instead) : double-click the home button, slide the taskbar to the right, and it's the icon far left.
    If you havn't got the lock symbol at the top then try a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Can I use a USB drive with the Airport extreme (not the new one) for Time Machine?

    I thought I heard that using USB drive for Time Machine over wifi will work with the new, tall Airport Extreme, but not with the previous model, which I have. Anybody know for sure?
    thanks.

    It is not recommended.. Apple says it doesn't work.. for some people it does for others it is unreliable.. do you really want unreliable backups.
    See http://pondini.org/TM/Airport.html

Maybe you are looking for