Best Practice In Java

Dear Friends.
Which is the best method to use in looping ? For loop or While lopp. Please give me some idea about the performance.
Thanks in advance
Shaiju.P

The choice between for or while is pretty much a matter of readability and personal preference. I personally tend to use for loops only for dealing with situations where a numerical index is important (arrays and sometimes lists). For iterators, I tend to use while() loops, because it looks more natural to me.
I don't think there's any difference in performance pers�, but you always need to be aware of when and how many times your condition gets evaluated.

Similar Messages

  • Best practice for java script placement on a BC page?

    Hi guys just a general ask about where the best place for java script is on a BC page.
    I just watched the this very good video on optimization http://bcgurus.com/tutorials/how-to-do-website-performance-optimization and in it it says how you should try and load the scripts at the bottom of the page so that it loads quicker.
    now I want to do this but with it being a BC site i dont know if certain scripts have to be in the head of the doc. For instance the validate script I have? Does anyone know what I can and cant move from the head?
    I was going to do what kiyuco like to practice and add all my scripts to a content holder and then add that to my pages/templates. Will BC like me adding this to the bottom of the page and not the head?
    Thanks
    Dave

    http://forums.adobe.com/docs/DOC-2964

  • Current best practice with Java Runtime?

    I'd rather just live without Java Runtime, but it looks like one of my kids needs it for a school website.  I guess I have to install it and educate/monitor everyone on using and disabling it.  On a machine with multiple user accounts can it be enabled/disabled on a machine wide global basis, or is it only on a user/browser-preferences level?  What complications are there, if any with multiple users?  I assume it helps to be browsing in a non-admin account?

    It's been enabled on all my OSs and I suffer no issues. You could use if for the school app and then disable it in Safari's prefs if you're really worried about it.

  • Best practice for Java stand alone upgrade into maint org area?

    I have a Java standalone running EP 6.0 on SAP netweaver 04 at SP 20.
    I want to upgrade to SAP Netweaver 2004s.  I think the equivalent of SPS 20 of NW 04 in NW 2004s is SPS 11 (ie all the SCAs are named *11...).
    NW 2004s SPS 11 download requires use of maintenance_organizer.
    Does this mean I should change the SMSY definition of my java solution to reflect SAP Netweaver 2004s now, rather than after I actually upgrade, even though the upgrade may be several weeks away?
    Is changing the SMSY def the only way to get the SPS 11 media? 
    I am currently in the process of collecting all of the media required for a sucessful upgrade.
    Thx
    Ken Chamberlain
    University of Toronto

    kevjava wrote: Some things that I think would be useful:
    Suggestions reordered to suit my reply..
    kevjava wrote: 2. Line numbering, and/or a line counter so you can see how much scrolling you're going to be imposing on the forum readers.
    Good idea, and since the line count is only a handful of lines of code to implement, I took that option. See the [line count|http://pscode.org/stbc/help.html#linecount] section of the (new) [STBC Help|http://pscode.org/stbc/help.html] page for more details. (Insert plaintiff whining about the arbitrary limits set - here).
    I considered adding line length checking, but the [Text Width Checker|http://pscode.org/twc/] ('sold separately') already has that covered, and I would prefer to keep this tool more specific to compilation, which leads me to..
    kevjava wrote: 1. A button to run the code, to see that it demonstrates the problem that you wish for the forum to solve...
    Interesting idea, but I think that is better suited to a more full blown (but still relatively simple) GUId compiler. I am not fully decided that running a class is unsuited to STBC, but I am more likely to implement a clickable list of compilation errors, than a 'run' button.
    On the other hand I am thinking the clickable error list is also better suited to an altogether more abled compiler, so don't hold your breath to see either in the STBC.
    You might note I have not bothered to update the screenshots to show the line count label. That is because I am still considering error lists and running code, and open to further suggestion (not because I am just slack!). If the screenshots update to include the line count but nothing else, take that as a sign. ;-)
    Thanks for your ideas. The line count alone is worth a few Dukes.

  • Best practices in java documentation and coding

    is there any book,article,standard to how to document or code a java program ?

    JoachimSauer wrote:
    jwenting wrote:
    maybe, but any reasonably proficient project lead will adopt the "official" "standards" as put down by the language designers.Or at least use them as the base to build upon.And add a bunch of stupid standards, like no tabs and 80 chars per line limits, just to make the people too stubburn to learn something other than Vi happy.
    JSG

  • Best Practices Java 1.6.0.24 Runtime parameters

    Hi,
    We're deploying Java 1.6.0.24 for 300 end-users on ERP 11.5.10 CU2 on Linux.
    We would like to know what are the Best Practices for Java 1.6.0.24 Runtime parameters.

    Please also see these docs.
    Recommended Client Java Plug-in (JVM/JRE) For Discoverer Plus 10g (10.1.2) [ID 465234.1]
    Diagnosing Forms Mouse Focus Problems Using JRE [ID 760250.1]
    Login Loop on Internet Explorer after Session Timeout using JRE 1.6.0_18 [ID 1078228.1]
    How Are The Forms JAR Files Stored with Sun JRE [ID 1058882.1]
    Thanks,
    Hussein

  • JSP best practices, tips?

    let me know few tips and best practices on java server pages.. as i am working on jsp project

    JSP Best Practices.
    More JSP Best Practices
    But the most important Best Practice has already been given in this thread: use JSP pages for presentation only.

  • Best Practices for Defining NDS Java Projects...

    We are doing a Proof of Concept on using NDS to develop non-SAP Java applications.  We are attempting to determine if we can replace our current Java development tools with NDS/WAS.
    We are struggling with SAP's terminology and "plumbing" for setting up/defining Java projects.  For example, what is and when do you define Tracks, Software Components, Development Components, etc.  All of these terms are totally foreign to us and do not relate to our current Java environment (at least not that we can see).  We are also struggling with how the DTR and activities tie in to those components.
    If any one has defined best practices for setting up Java projects or has struggled with and overcome these same issues, please provide us with some guidance.  This is a very frustrating and time-consuming issue for us.
    Thank you!!

    Hi Peggy,
    In Component Model we divide software projects into small components.Components can use other components in well defined manner.
    A development object is a part of a component that can be changed or developed in some way; it provides the component with a certain part of its functionality. A development object may be a Java class, a Web Dynpro view, a table definition, a JSP page, and so on. Development objects are always stored as “sources” in a repository.
    A development component can be defined as a frame shared by a number of objects, which are part of the software.
    Software components combine components (DCs) to larger units for delivery and deployment.
    A track comprises configurations and runtime systems required for developing software component versions.It ensures stable states of deliverables used by subsequent tracks.
    The Design Time Repository is for versioning source code management. Distributed development of software in teams. Transport and replication of sources.
    You can also find lot of support in SDN for the above concepts with tutorials.
    Refer this Link for a overview on Java development Infrastructure(JDI)
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/java/java development infrastructure jdi overview.pdf
    To understand further
    Working with Net Weaver Development Infrastructure :
    http://help.sap.com/saphelp_nw04/helpdata/en/03/f6bc3d42f46c33e10000000a11405a/content.htm
    In the above link you can find all the concepts clearly explained.You can also find the required tutorials for development.
    Regards,
    Vijith

  • Best Practice for storing a logon to website in a desktop java app

    Hoping someone well versed in java related security best practices can point me in the right direction.
    I have a small java PC application that uses the Soap API to send various data to a 3rd party.
    Currently I am storing the logon credentials for this 3rd party in a local database used by the application.
    The username / password to connect to this database is encrypted and never accessed in clear text in the code.
    (Although, since the application is stand alone, everything needed to decrypt the database credentials is packaged
    with the application. It would not be easy to get the clear text credentials, but possible)
    The caveat in my case is that the user of the application is not even aware (nor should be) that the application is interacting with
    the 3rd party API at all. All the end user knows is that an entity (that they already have a relationship with) has asked them to
    install this application in order to provide the entity with certain data from the user.
    Is there a more secure way to do this will maintaining the requirement that the user not need know the logon credentials to the 3rd party?

    Moderator advice: Don't double post the same question. I've removed the other thread you started in the Other Security APIs, Tools, and Issues forum.
    db

  • Best practice of OSB logging Report handling or java code using publish

    Hi all,
    I want to do common error handling of OSB I did two implementations as below just want to know which one is the best practice.
    1. By using the custom report handler --> When ever we want to log we will use the report action of OSB which will call the Custom java class which
    Will log the data in to DB.
    2. By using plain java class --> creating a java class publish to the proxy which will call this java class and do the logging.
    Which is the best practice and pros and cons.
    Thanks
    Phani

    Hi Anuj,
    Thanks for the links, they have been helpful.
    I understand now that OSR is only meant to contain only Proxy services. The synch facility is between OSR and OSB so that in case when you are not using OER, you can publish Proxy services to OSR from OSB. What I didn't understand was why there was a option to publish a Proxy service back to OSB and why it ended up as a Business service. From the link you provided, it mentioned that this case is for multi-domain OSBs, where one OSB wants to use the other OSB's service. It is clear now.
    Some more questions:
    1) In the design-time, in OER no Endpoints are generated for Proxy services. Then how do we publish our design-time services to OSR for testing purposes? What is the correct way of doing this?
    Thanks,
    Umar

  • What are Best Practice Recommendations for Java EE 7 Property File Configuration?

    Where does application configuration belong in modern Java EE applications? What best practice(s) recommendations do people have?
    By application configuration, I mean settings like connectivity settings to services on other boxes, including external ones (e.g. Twitter and our internal Cassandra servers...for things such as hostnames, credentials, retry attempts) as well as those relating business logic (things that one might be tempted to store as constants in classes, e.g. days for something to expire, etc).
    Assumptions:
    We are deploying to a Java EE 7 server (Wildfly 8.1) using a single EAR file, which contains multiple wars and one ejb-jar.
    We will be deploying to a variety of environments: Unit testing, local dev installs, cloud based infrastructure for UAT, Stress testing and Production environments. **Many of  our properties will vary with each of these environments.**
    We are not opposed to coupling property configuration to a DI framework if that is the best practice people recommend.
    All of this is for new development, so we don't have to comply with legacy requirements or restrictions. We're very focused on the current, modern best practices.
    Does configuration belong inside or outside of an EAR?
    If outside of an EAR, where and how best to reliably access them?
    If inside of an EAR we can store it anywhere in the classpath to ease access during execution. But we'd have to re-assemble (and maybe re-build) with each configuration change. And since we'll have multiple environments, we'd need a means to differentiate the files within the EAR. I see two options here:
    Utilize expected file names (e.g. cassandra.properties) and then build multiple environment specific EARs (eg. appxyz-PROD.ear).
    Build one EAR (eg. appxyz.ear) and put all of our various environment configuration files inside it, appending an environment variable to each config file name (eg cassandra-PROD.properties). And of course adding an environment variable (to the vm or otherwise), so that the code will know which file to pickup.
    What are the best practices people can recommend for solving this common challenge?
    Thanks.

    HI Bob,
    As sometimes when you create a model using a local wsdl file then instead of refering to URL mentioned in wsdl file it refers to say, "C:\temp" folder from where you picked up that file. you can check target address of logical port. Due to this when you deploy application on server it try to search it in "c:\temp" path instead of it path specified at soap:address location in wsdl file.
    Best way is  re-import your Adaptive Web Services model using the URL specified in wsdl file as soap:address location.
    like http://<IP>:<PORT>/XISOAPAdapter/MessageServlet?channel<xirequest>
    or you can ask you XI developer to give url for webservice and username password of server

  • Best practice to install Bi-Java

    Hi,
    We are in the process of designing the system landscape for our client. We have installed NW04s usage type EP on one server. Now we need to decide on where to install the BI-Java usage type. So:
    1. Is adding BI-Java on the existing EP usage type is recommended
    2. What is the best practice:
      a> EP and BI-Java on the same server
      b> EP and BI-Java on separate servers
    What are the pros and cons of each choice.

    Hi,
    When you install BI JAVA, it will have its own EP and AS JAVA usage types under it. You have no option with this as they are required to run BI JAVA (just like you have AS ABAP under the BI usage type).
    The decisions you do have are:
    1. Should BI JAVA be installed on the same server as the BI usage type? (this is your choice)
    2. Should you use the EP usage type within the BI JAVA for your enterprise portal deployment or just keep it dedicated for BI usage only and use a separate EP usage type for your enterprise portal deployment. (most customers will do the latter option due to patching and upgrading options).
    Please see the SAP NetWeaver 2004s master guide for more information. In addition we are updating the master guide with more information on this area. It should be published quite soon.
    Cheers,
    Mike.

  • Slow starup of Java application - best practices for fine tuning JVM?

    We are having problems with a java application, which takes a long time to startup.
    In order to understand our question we better start with some background info. You will find the question(s) after that.
    Background:
    The setup is as follows:
    In a client-server solution we have a win xp, fat client running java 1.6.0.18.
    (Sun JRE). The fat client containt a lot of GUI, and connects to a server for DB access. Client machines are typical 1 to 3 years old (there are problems even on brand new machines). They have the client version of JRE - standard edition installed (Java SE 6 update 10 or better) Pretty much usual stuff so far.
    We have done a lot of profiling on the client code, and yes we have found parts of our own Java code that needs improving. we are all over this. Server side seems ok with good response times. So far, we havent found anything about shaky net connections or endless loops in the java client code or similiar.
    Still, things are not good. Starting the application takes a long time. too long.
    There are many complicating factors, but here is what we think we have observed:
    There is a problem with cold vs. varm starts of the application. Apparently, after a reboot of the client PC - things are really, really bad - and it takes (sometimes) up to 30-40 secs to start the application (until we arrive at the start GUI in our app).
    If we run our application, close it down, and then restart
    without rebooting, things are a lot better. It then usually takes
    something like 15 - 20 sec. which is "acceptable". Not good, but acceptable,
    Any ideas why?
    I have googled it, and some links seems to suggest that the reason could be disk cache. Where vital jar are already in disk cache on th warm start? Does that make any sense? Virus scanners presumable runs in both cases.
    People still think that 15 - 20 sec in start up on the warm start is an awful long time, even though there is a lot, a lot, of functionality in the application.
    We got a suggestion to use IBMs JRE - as it can do some tricks (not sure what) our SUN JRE cant do concerning the warm and cold start problem. But thats is not an option for us. And noone has come up with any really good suggestions with the SUN JRE so far?
    On the Java Quick Starter (JQS) -
    improves initial startup time for most java applets and applications.
    Which might be helpful? People on the internet seem more interested
    in uninstalling the thing than actually installing it though?
    And it seems very proprietary, where we cant give our Jar files to it?
    We could obviously try to "hide" the problem in some way and make it "seem" quicker. Where perceived performance can be just as good as actual performance. But it does seem a bad solution. So for the cold start we will probably try reading the jar files and thereby have them in disk cache before startup of our application. And see if that helps us.
    Still, ok the cold start is the real killer, but warm start isn't exactly wonderfull either.
    People have suggested that we read more on the JVM and performance.
    java.sun.com.javase/technologies/performance.jsp
    java.sun.com.docs/hotspot/gc5.0/gc_tuning_5.html
    the use of JVM flags "-Xms" "-Xmx" etc etc.
    And here comes the question .. da da ...
    Concerning various suggested reading material.
    it is very much appreciated - but we will like to ask people here - if it is possibe to get more specific pointers. to where the gold might be buried.
    I.e. in a an ideal world we would have time to read and understand all of these documents in depth. However, in this less than ideal world we are also doing a lot of very timeconsuming profiling in our own java code.
    E.g. java garbage collection is is a huge subject - and JVm settings also. Sure, in the end we will probably have to do this all very thoroughly. But for now we are hoping for some heuristics on what other people are doing when facing a problem like ours..?
    Young generation, large memory pages, garbage collection threads ect. all sounds interesting - but what would you start with?
    If you don't have info to decide - what kind of profiling would you be running and then adjust what JVM setting in your trials?
    In this pressed for time scenario. Ignorance is not bliss. But makes it hard to pinpoint the or those JVM parameters to adjust. So some good pointers from experienced JVM "configurators" will be much appreciated!
    Actually, If we can establish that finetuning of these parameters is a good idea, it will certainly also be much easier to allocate the time for doing so. - reading, experimenting etc. in our project.
    So, All in all , what kinds of performance improvements can we hope for? 5 out of 20 secs on the warm start? Or is it 10 % nitpicking? Whats the ball park figure for what we can hope to achieve here given our setup? What do you think based on above?
    Maybe someone out there have done some finetuning of JVM parameters in a similiar PC environments like, with similiar fat clients...? Finetuning so and so - gave 5 secs. So start your work with these one-two parameters?
    Something like that - some best practices? Thats what we are hoping for.
    best wishes
    -Simon

    Thanks for helpful answer from both you and kajbj.
    The app doesn't use shared network drives.
    What are you doing between main starts to get executed and the UI is
    displayed?
    Basicly, Calculating what to show in the UI. Accessing server - not so much, there are some reads from a cache, but the profiling doesnt indicate that it should be a problem. Sure, I could shift the startup time to some other slot, but sofar I havent found a place where the end-user wouldnt be annoyed.> Caching of something would seem most obvious. Normal VM stuff >seems unlikely. With profiling i basicly find that ''everything'' takes a lot longer in the cold start scenario. Some of our local java methods are going to be rewritten following our review. But what else can be tuned?You guys dont think the Java Quick Start approach, with more jars in disk cache will give something? And how should that be done/ what does people do?I.e. For the class loader I read something about
    1.Bootstrap class loader
    2.Extensions class loader
    3.System class loader
    and is wondering if this has something to do with the cold start problem?
    The extensions class loader loads the code in the extensions directories (<JAVA_HOME>/lib/ext
    So, we should move app classes to ext? Put them in one jar file? (We have many). Best practice about that?
    Otherwise it seems to me that it must be about finetuning the JVM?
    I imagine that it is a question about:
    1. the right heap size
    2. the right garbage collection scheme
    Googling heap size for XP
    CHE22 writes:
    You are right; -Xms1600M works well, but -Xms1700M bombs
    Thats one best practice or what?
    On garbage collection, there are numerous posts, and much "masters of Java black art" IMHO, And according to profiling GC is not really that much of a problem anyway? Still,
    Based on my description I was hoping for a short reply like "try setting these two parameters on your xp box, it worked for me" ...or something like that. With no takers on that one, I fear people are saying that there is nothing to be gained there?
    we read:
    [ -Xmx3800m -Xms3800m
    Configures a large Java heap to take advantage of the large memory system.
    -Xmn2g
    Configures a large heap for the young generation (which can be collected in parallel), again taking advantage of the large memory system. It helps prevent short lived objects from being prematurely promoted to the old generation, where garbage collection is more expensive.
    Unless you have problems with pauses, try granting as much memory as possible to the virtual machine. The default size (64MB) is often too small.
    Setting -Xms and -Xmx to the same value increases predictability by removing the most important sizing decision from the virtual machine. On the other hand, the virtual machine can't compensate if you make a poor choice.
    The -XX:+AggressiveHeap+ option inspects the machine resources (size of memory and number of processors) and attempts to set various parameters to be optimal for long-running, memory allocation-intensive jobs]
    So is Setting -Xms and -Xmx and -XX:AggressiveHeap
    best practice? What kind of performance improvement should we expect?
    Concerning JIT:
    I read this one
    [the impact of the JIT compiler is obvious on the graph: at startup the time taken is around 500us for the first few values, then quickly drops to 130us, before falling again to 70us, where it stays for 30 minutes,
    for this specific issue, I greatly improved my performances by configuring another VM argument: I set -XX:CompileThreshold=50]
    The size of the cache can be changed with
    -Xmaxjitcodesize
    This sounds like you should do something with JIT args, but reading
    // We disable the JIT during toolkit initialization. This
    // tends to touch lots of classes that aren't needed again
    // later and therefore JITing is counter-productiive.
    java.lang.Compiler.disable();
    However, finding
    the sweet spots for compilation thresholds has been tricky, so we're
    still experimenting with the recompilation policy. Work on it
    continues.
    sounds like there is no such straigth forward path, it all depends...
    Ok, its good, when
    [Small methods that can be more easily analyzed, optimized, and inlined where necessary (and not inlined where not necessary). Clearly delineated uses of data so that usage patterns and lifetimes are apparent. ]
    but when I read this:
    [The virtual machine is responsible for byte code execution, storage allocation, thread synchronization, etc. Running with the virtual machine are native code libraries that handle input and output through the operating system, especially graphics operations through the window system. Programs that spend significant portions of their time in those native code libraries will not see their performance on HotSpot improved as much as programs that spend most of their time executing byte codes.]
    I have the feeling that we might not able to improve performance that way?
    Any comments?
    otherwise i was wondering about
    -XX:CompileThreshold=50 -Xmaxjitcodesize (large, how large?)
    Somehow, we still feel that someone out there should have experienced similiar problems? But obviously there is no guarantee that the someone should surf by here!
    In c++ we used to just write everything ourselves. Here it does seem to be a question about the right use of other peoples stuff?
    Where you are kind of hoping for a shortcut, so you dont have to read endless number of documents, but can find a short document that actually addresses your problem ... well.
    -Simon
    Edited by: simoncpm on Mar 15, 2010 3:43 PM
    Edited by: simoncpm on Mar 15, 2010 3:53 PM

  • Java Server Faces best Practices

    Hello,
    I am starting to like JSF. But I want to know the following.
    Where is the contoller in a JSF application, is it the Managed Bean???? or a Backing Bean?
    Should I put my Business Delegate on a Managed Bean? or in a Backing Bean? What is the difference?
    Can anyone tell?.
    I would like to know JSF Best Practices? Blueprints?.
    Thanks.
    Saludos,
    <Rory/>

    Hi Senthruan,
    The documentation referenced by the following links is based on an older version of JavaServer Faces technology.
    Backing Beans:
    http://java.sun.com/webservices/docs/1.3/tutorial/doc/J
    FUsing3.html
    UI Components :
    http://java.sun.com/webservices/docs/1.3/tutorial/doc/J
    FUsing3.html (just as a visual example).You should instead use the J2EE tutorial (http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html), which is based on version 1.1 of JavaServer Faces technology. The JavaSErver Faces material starts with chapter 17. The topics have moved around a bit, but the tutorial has a nice search engine, so you shouldn't have trouble finding the information you need.
    Jennifer

  • Best practice concerning embedding script in report vs.  controlling from Java

    Hi,
    I'm faced(probably not the only one) with adding some intelligence to my reports.  In a prior post I was curious about displaying/hiding sections based on conditions found in the bean/pojo. 
    Is there a best practice concerning embedding logic in the report in the form of formula(s), vs. using Java to get or create a field and then creating a formula on the fly?  I suspect the answer has something to do with truely dynamic fields, and perhaps a little bit of both Java, and script.
    Anyone on staff care to try answering??
    Peter

    Hi,
    log into your SAP ERP system using the SAP GUI and choose in the SAP Menu the following path:
    SAP Menu -> Accounting -> Controlling -> Cost Cetner Controlling ->Environment->Set Controlling Area.
    Set the desired controlling area for your user there (DO NOT FORGET TO CLICK ON THE DISKETTE ICON) and try again.
    Regards,
    Stratos

Maybe you are looking for

  • How to assign values from multiple output(cursor) to fields(line item-one below other) in forms??

    Hi all, I have a Form which has text_field columns as below , created from table RECEIVED_FORM_15G. This table is blank. 1)     CUST_CODE with 1 line item. (Number of Items displayed=1) 2)     ACCT_FD_NO with 10 line items. (Number of Items displayed

  • All DCs broken: Buildspace unreachable.

    Hi Experts, We had modified the password for cmsadm. We applied following note: 896427 for fixing the error. After that note has been applied following errors are been faced. 1. Build space is unreachable. 2. DCs are in broken state. 3. The CBS-Make

  • Delivery qty - order status

    Hi experts, Case 1: sales order -  qty 100pc delivery - qty 100pc (PGI) Q1: By using the same order type & item category, why some sales orders show delivery qty zero in schedule line, while order status shows open? Q2: As long as cancelling delivery

  • What version is your CS3 Flash.exe?

    If you have Acrobat 8 Professional/CS3 and are up to date, what version number is your flash.exe file?  Not to be confused with flashplayer.  Thanks.

  • ZFS (ZEVO) formatted drive can't be used as event/project drive

    Started using Zevo ZFS recently and notices that a ZFS formatted drive doesn't show up in drive list where the events and projects are. Same disk worked before when it was HFS+ formatted. Would be great if FCPX would also support other filesystems. E