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.

Similar Messages

  • Using OR operator with string

    How we can use OR operator with string in java??

    Gaurav1 wrote:
    its logical OR operator;how can we use it with matcher classLike its been said already. The "logical OR" is used the same everywhere.
    Why don't you post the code you're having problems with. (Only the relevant areas, please. And use code tags.)

  • Why not use Bridge CS4 with PsCS3?

    I will post this on both the Bridge and Ps User-to-User forums as it applies to both.
    I have PsCS3 and PsCS4 installed side by side in the default folders assigned by Adobe but have shifted my Bridge CS4 Cache (containing all the thumbnails and previews) from C:Documents and Settings\etc to a subfolder within My Documents, which I had previously moved to my F: drive - my main data drive.
    I have found Bridge CS4 to be much more stable than Bridge CS3. Additionally, Bridge CS4 has certain features which make it more attractive and easier to use than Bridge CS3. I want to use Bridge CS4 in conjunction with PsCS3 until Adobe has sorted out the problems with PsCS4 - which at the moment is simply unuseable on my rather old and humble system.
    On my system, I seem to be able to use Bridge CS4 with PsCS3 without any problems detected so far. I even have things set up such that any JPEG, TIFF or PSD file double clicked within Bridge CS4 or within Windows Explorer (Win XP Pro SP3) automatically opens the file in PsCS3 and not PsCS4 (provided, of course, that PsCS4 is not itself already running). Furthermore, even with PsCS3 running beside Bridge CS4, from within Bridge CS4 I can open any RAW, JPEG or TIFF file in Camera Raw 5.1 and use its new features (Adjustment Brush, Graduated Filter, extra vignetting capabilities, etcetera) which were not available in the last release of Camera Raw (4.6 I think) associated with PsCS3. The only problem comes when trying to open edits made in Camera Raw 5.1 in PsCS3 using the "Open Image" button in ACR - it does nothing/won't work, this is, it won't open the image with the ACR adjustments in PsCS3. That's not a big deal for me - as I am currently not doing any work within ACR (any version) and if I needed to I could simply save the ACR edits and then open the files in PsCS4, save the files as PSDs and then open them in PsCS3 to finalise them there.
    Has anyone else had a similar experience, or does anyone else know of any reason(s) why I should not continue to use this workflow, at least in the short term?

    I've been away. Thanks John, Bart and Buko for your responses. Think you misunderstood my post Bart, but it does not matter now. John got the correct message. Buko: of course CS3 cannot use ACR 5.x - that was implicit in my post.

  • 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

  • Why r we allowed to create String objects with & without using new operator

    While creating any object, usage of the new operator is a must...but only for the string object we can create it with and also without new operator how is it possible to create an object without using new operator.

    Because Mr. (Dr.?) Gosling is a kindly soul who realizes that programmers have deadlines and, when he designed Java, was not so rigid or unbending as not to realize that from time to time, certain shortcuts are warranted, even in a relatively pure language such as Java. The direct String literal assignments are a shortcut over using the new operator making Java programming (and execution; there's also a performance benefit) more streamlined.
    So look not the gift horse in the mouth, but simply bask in the simplification and ease on the eyes and directly assign your little literals to your heart's content.

  • Why does the new operating system not delete the moved files from their original location - it seems like an enormous waste of space, time and effort to clean up every file once you've moved it

    Why does the new operating system not delete the moved files from their original locations - it seems like an enormous waste of space, time and effort to clean up every file once you've moved it - also, when transferring large amounts of files it becomes a very large problem remembering which files were transferred and which not.

    You're going to need to be more specific, as I'm not quite sure I understand what you're talking about.
    If you're referring to copying from an external hard drive or flash drive, and you want to actually move files rather than copy them, you can hold down the option key to force it to do a "move" rather than a "copy." This is not new behavior, though... the Mac OS has worked this way as long as I can recall (and I've been using it since 1984).
    If you're having a problem with trying to move files from one place to another on a single drive causing them to be copied instead, that is likely because of some permissions issue preventing you from actually being able to move them.

  • 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)

  • Error while using between operator with sql stmts in obiee 11g analytics

    Hi All,
    when I try to use between operator with two select queries in OBIEE 11g analytics, I'm getting the below error:
    Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
    Location: saw.views.evc.activate, saw.httpserver.processrequest, saw.rpc.server.responder, saw.rpc.server, saw.rpc.server.handleConnection, saw.rpc.server.dispatch, saw.threadpool.socketrpcserver, saw.threads
    Odbc driver returned an error (SQLExecDirectW).
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27002] Near <select>: Syntax error [nQSError: 26012] . (HY000)
    can anyone help me out in resolving this issue.

    Hi All,
    Thank u all for ur replies, but I dint the exact solution for what I'm searching for.
    If I use the condition as
    "WHERE "Workforce Budget"."Used Budget Amount" BETWEEN MAX("Workforce Budget"."Total Eligible Salaries") AND MAX("Workforce Budget"."Published Worksheet Budget Amount"",
    all the data will be grouped with the two columns which I'm considering in the condition.
    my actual requirement with this query is to get the required date from a table to generate the report either as daily or weekly or monthly report. If I use repository variables, variables are not getting refreshed until I regenerate the server(which I should not do in my project). Hence I have created a table to hold weekly start and end dates and monthly start and end dates to pass the value to the actual report using between operator.
    please could anyone help me on this, my release date is fast approaching.

  • Why not use notifyall

    now I'm reading this book "Java Threads 2nd edition" by Scott Oaks and Henry Wong. Writer provide a class called BusyFlag to simulate the mutex.
    I wonder why not use notifyall() to replay notify().
    public class BusyFlag {
         protected Thread busyflag = null;
         protected int busycount = 0;
         public synchronized void getBusyFlag() {
              while (tryGetBusyFlag() == false) {
                   try {
                        wait();
                   } catch (Exception e) {
         public synchronized boolean tryGetBusyFlag() {
              if (busyflag == null) {
                   busyflag = Thread.currentThread();
                   busycount = 1;
                   return true;
              if (busyflag == Thread.currentThread()) {
                   busycount++;
                   return true;
              return false;
         public synchronized void freeBusyFlag() {
              if (getBusyFlagOwner() == Thread.currentThread()) {
                   busycount--;
                   if (busycount == 0) {
                        busyflag = null;
                        *notify();*
         public synchronized Thread getBusyFlagOwner() {
              return busyflag;
    }

    naficbm wrote:
    now I'm reading this book "Java Threads 2nd edition" by Scott Oaks and Henry Wong. Writer provide a class called BusyFlag to simulate the mutex.
    I wonder why not use notifyall() to replay notify().Looks like it should work with notifyall as well.

  • Why not invent a tablet with a i5 or i7 reader, DVI, USB ... who would wear the name of ipac or imad

    why not invent a tablet with a i5 or i7 reader, DVI, USB ... who would wear the name of ipac or imad

    Not sure why a tablet would need a Core i5 or a Core i7, particularly given that it would shorten battery life dramatically, but you can submit your suggestion to Apple here:
    http://www.apple.com/feedback
    The current iPad can output via DVI (using an HDMI to DVI adapter), by the way.
    Regards.

  • Itunes 11.1.5 will not sync new apps with iPhone 5 iOS 7.0.6 and gives grayed out "install" no message?  How does one work around this?

    Itunes 11.1.5 (MacBook Pro,OS 10.6.8) will not sync new apps with iPhone 5 iOS 7.0.6 and gives grayed out "install" no message?  How does one work around this?

    Just reboot your laptop... While its rebooting try to reboot your phone also by holding the home and power buttonn for 10-15 seconds...When your phone is turned off try to connect it to iTunes and it will recognize your phone in recovery mode.
    If you have the .ipsw file for iOS 7.0.6 saved in your desktop then in itunes press shift and click on Restore.
    Select the ipsw file and let it restore.
    If you dont have it downloaded then simply click on restore.
    I hope it works
    Cheers !

  • I can not use CanoScan N670U with my Macbook pro. I download canoscan toolbox 4.1 from Cannon website. It keep saying "the scanner plug-in was not found". Please help

    I can not use CanaScan N670U with my Macbook Pro. I download Canoscan toolbox 4.1 from Cannon websit. It still keep saying "The scanner plug-in was not found". Please help

    There is a solution (I'm running Snow Leopard on a Core2Duo iMac, but this problem arose when I was running Leopard on a G4 PowerBook too).
    Problem:
    You download the OS X driver for the scanner from Canon's site. I already had the CanoScan Toolbox (4.1) stored on an external drive.
    You unzip the driver and run the VISE installer. After a search it finds your copy of Photoshop (and maybe even the CanoScan Toolbox), and you click to install on that/those location(s).
    You get a couple of error messages, which you click through.
    You restart your computer and try to run the scanner but you get an error that the driver is wrong or missing and the process will abort.
    Solution:
    BEFORE you restart, and with the installer package still open -
    1. Copy the Into_CFMSupport_Login & Into_CMPrefs folders to
    Applications : Canon Utilities
    Applications : Canoscan Toolbox
    and remove the prefix Into_ from each folder
    2. Check whether the installer placed N067U_Library.shlb into the top level (not User level)
    Library : CFMSupport
    and if it didn't, move it there yourself
    THEN restart, and try again. It worked for me (via Photoshop), but whether it will work for everyone, I don't know.

  • Why not use paper label on finished DVD project?

    I also use printed paper labels for my DVD covers
    why not use them?
    please advise?

    Hi
    The DVD get's unbalanced = Laser can't read track
    DVD are several times more sencitive than CD (not advicable to put lables on them either)
    And DVDs/CDs that are unbalanced also give more strain to the player mechanism
    that eventually stops working.
    Yours Bengt W

  • Why not use interfaces for constants?

    Hi,
    I have been getting conflicting views about why not use interfaces for constants?
    Can anyone shed some light on it?
    Piyush

    How so?
    If the constants are only used in a single classhow
    does it help to put them in a separate structute?
    (Ignoring the a type safe enumeration of course.)Well, mainly for readability. Suppose that you have a
    web application which has a servlet class
    "RedirectServlet", which takes a variable to redirect
    to a given JSP file. In the JSP files, you want to
    create forms which take this servlet as their action.
    You could of course put all these "redirect"
    constants in the RedirectServlet itself, but then
    it's kind of weird that you have to import a
    servlet in your jsp file to include these constants
    and to be able to write
    <form action="servlet/RedirectServlet?key=<%=
    RedirectServlet.HOMEPAGE %>> or so.
    Instead, you could create an interface called
    "RedirectConstants", and then your servlet
    RedirectServlet could implement this interface. Then
    your JSP can also access these constants via this
    interface.
    But then again, this is merely a matter of style, I
    fully agree that there is never a real _need_ to put
    constants in a separate structure if they're only used
    in a single class.Are you claiming that your example above is a single class?

Maybe you are looking for

  • IPhone 4S 5.0.1 upgrade to 6.1.3 by on air. Is it possible?

    Good day! Exuse me for my fluent English-I am from Russia)) I have Bought a new iphone 4s 64 GB recently. It has 5.0.1 firmware. Today it offered me to update on air to 6.1.3. (it's strange,because ios 7 is actually now) Can I do it or my iphone will

  • Select query is taking lot of time to fetch data.....

    Select query is taking lot of time to fetch data.     SELECT algnum atanum  abdatu abzeit abname abenum bmatnr bmaktx bqdatu bqzeit bvlenr bnlenr bvltyp bvlber b~vlpla            bnltyp bnlber bnlpla bvsola b~vorga INTO TABLE it_final FROM ltak AS a

  • HTTP Post Method

    Hi experts, Here my scenario is ABAP proxy to PI to HTTP. I am sending the data via proxy to PI. From PI data sent to the third party using below url using (here PI need post the data using below Url then Pi will get the response)  https://developer.

  • Deliver to an email whose address is not listed as accepted domain

    Hi Exchange experts! I have a question regarding transport servers behaviour for smtp addresses that are not listed in accepted domains. I have a mailbox with a secondary smtp address : [email protected] , and aaaa.com is not listed as accepted. Assu

  • InDesign Runtime Error - Urgent

    Can someone please help?  I just downloaded a trial of CS4 and am using InDesign (in hopes of making a purchase), and there is a RunTime error every time I try to open InDesign and it shuts down.  If it's going to be this difficult to edit a document