Good Practices and Code Conventions

Hi All,
What are the good practices in java? Are there coding convention to be followed?
I would like to improve my coding standards and write better code. Please help me.
Thanks
Diana

Diana12 wrote:
Then how to make it excellent?Are you serious? Do you expect us to give you a 2-line summary of how to make "excellent" code?
It takes some time to learn to write excellent code and it can't easily be summarized into 1-2 sentences. If it could, then it would be much easier to learn (that would be nice!).
Experience, making mistakes, realizing they were mistakes, not making the same mistakes later on. Having your code criticized by someone who writes better code than you. That's how you learn to write excellent code.
Write simple code, keep it clean, make each method do one thing, write code that doesn't need documentation, document where you must, adhere to the open-close principle, adhere to the KISS principle, adhere to the YAGNI principle, ...
Grab [The Pragmatic Programmer|http://www.pragprog.com/the-pragmatic-programmer] and read it. Then read it again. Do some more exercises and read it a third time.

Similar Messages

  • Oracle BPEL standard, best practice and naming convention

    Hi, folks,
    Is there any standard or best practice associated with Oracle BPEL, regarding development, performace, what to avoid, etc? And is there any naming convention for the process, variable partner link name, etc? Similar to naming convention in writing Java code?
    Thanks
    John

    Hi,
    Here is the best practice guide:
    http://download.oracle.com/technology/tech/soa/soa_best_practices_1013x_drop3.pdf
    Thanks & Regards,
    Dharmendra
    http://soa-howto.blogspot.com

  • Implementation of Oracle Coding Standards and Code Quality Checks

    I wanted to implement a list of coding standards and code quality checks for my oracle packages,functions,views,tableetc .
    for example
    All variables with number datatype should start with N_ and charcter type with C_ in all my tables & views definition.
    This can be identified during peer review & can be corrected, but i think this is a repeated process which i don want to burden the developers rather i wanted a tool which does all these kind of checks which can be automated.
    Is there any tool which does this operation or can someone give me a little idea how can i automate these stuffs bu creating a generic oracle procedure which can run through all the tables,views and generate a error report for those which are deviating from the standards.
    Thus we can reduce the manual effort spent on peer review, please suggest.
    thanks in advance

    maru wrote:
    I wanted to implement a list of coding standards and code quality checks for my oracle packages,functions,views,tableetc .
    for example
    All variables with number datatype should start with N_ and charcter type with C_ in all my tables & views definition.Hungarian notation is dead. It has no place in modern programming languages. Has no place in PL/SQL. Anit ain't just me saying that.
    +"Encoding the type of a function into the name (so-called Hungarian notation) is brain damaged—the compiler knows the types anyway and can check those, and it only confuses the programmer."+
    Linus Torvalds
    +"No I don't recommend 'Hungarian'. I regard 'Hungarian' (embedding an abbreviated version of a type in a variable name) a technique that can be useful in untyped languages, but is completely unsuitable for a language that supports generic programming and object-oriented programming—both of which emphasize selection of operations based on the type an arguments (known to the language or to the run-time support). In this case, 'building the type of an object into names' simply complicates and minimizes abstraction."+
    Bjarne Stroustrup
    2) Conditional Statements
    IF (x = 1) --> Wrong
    IF ((x = 1) AND (y = 2)) --> wrong
    IF x = 1 AND y = 2 --> RightIdiotic rules. The simple rule should be readability of code. Not how many brackets to use, and when not to use brackets. Minute standards like detracts from designing and writing proper code, fast and efficiently.
    There are many more rules (which is specific to ur application) which can be incorporated in the tool, there by giving consistency ,readability and easy to maintain for the developers.Bull. The more rules there are, the more difficult it becomes for programmers to write code. As it is no longer about writing readable and flexible and performing code - it is about double checking every single statement line against a huge list of rules about do's and dont's. It is not about getting the programmer focusing on solving the problem - it is about distracting the programmer with a complex and large rule list of how the code should look like.
    Sorry - but this rubs me the wrong way. In that environment, I would be the first to tell you to shove your "+many more rules+".
    I've developed systems in over a dozen languages over the years. I've seen all kinds of standards. The standards that work are those that are short, simple and sensible. Hungarian notation is not sensible. Writing reserved words in uppercase is not sensible. Dictating how brackets should be used is not sensible.
    What is sensible is using the de facto naming standards in use today - as per .Net Guidelines for Names (MSDN) and Code Conventions for the Java Programming Language.
    What is sensible is providing guidelines like bulk collection needs to be justified (not possible using SQL only) and use the limit clause to manage memory spend on the collection variable. Or how packages need to be used to modularise code, providing a public interface and private implementation.
    Standards are about creating a sensible and easy-to-use framework for writing code. It is not about creating a list of a 1001 rules that a developer needs to remember and adhere to, as if the developer is now part of some weird religious sect that has rules for every single aspect of human behaviour.

  • Goods issue and goods receipt with bar code

    hi
    i need  to do goods issue and goods receipt using bar code
    using se 73 i craeted a bar code
    iwill print this bar code on external system
    after printing same one will be stikked to  the respective bins
    i need to trigger goods issue and goods recipt by reading
    barcode scanner
    plz suggest how to achive this
    regards
    sasikanth
    vst

    One of the ways of triggering transactions in SAP using external systems is IDOCs
    When the barcode scanner scans the barcode of the material, you can trigger the IDOC from that system which will send the material barcode, number of units, goods issue/goods receipt etc to your SAP system. Once that inbound IDOC is received in SAP, SAP will trigger the goods issue or goods receipt based on the kind of transaction.
    If you can give the idea of IDOCs to your technical guy, he should be able to enable the solution. You may have to configure an IDOC in your SAP system, using teh standard IDOC type/message types meant for GI/GR
    Hope this helps you

  • Practical Windows Code and Driver Signing discussion

    Hello, my name is David Grayson and I work at Pololu Robotics & Electronics. I recently went through the process of signing all of our company's USB drivers and most of our installers for Windows. I encountered
    so many problems along the way that could have been easily avoided if someone had told me about them ahead of time. In response, I have written a 7000-word document that hopefully explains everything you need to know about code and driver signing:
    Practical Windows Code and Driver Signing
    If you are going through the same process, I sincerely hope that this document can clear up all of your confusion and save you a lot of time. I learned the hard way and now you can learn the easy way.  The basic conclusion of it
    all is that you should probably stay away from Go Daddy's certificates and use GlobalSign, and I provide detailed justifications for that.
    Click here to read the entire document.
    If you have any comments or questions, please post them here! If I missed anything or got anything wrong, let me know.  If you found the document useful and just want to thank me, then you can do that here too!
    Also, if you found this document helpful, please click on the little green arrow to the left!
    --David Grayson

    David, 
    Thanks! Sorry, I would have replied earlier but got diverted to the latest crisis.
    David Wrote:
    "I don't know anything about a Go Daddy "Driver Signing Tool"; maybe you found that statement elsewhere."
    My bad, I meant to say Godaddy's "Driver Signing Cert" as opposed to their "Code Signing Cert".
    And Yes, I followed your instructions and everything works fine on Win7 now that I installed the root certs you recommended!!
    Still I must find a way for my driver package to install without the warning message in Win7 without having users install the cert.
    Godaddy support (I have little confidence in them) swears up and down that I can double sign my Catalog file by following instructions here:
    http://msdn.microsoft.com/en-us/library/windows/hardware/hh967734%28v=vs.85%29.aspx
    Signing a driver package with two signatures
    In some cases, you might want to sign a driver package with two different signatures. For example, suppose you want your driver to run on Windows 7 and Windows 8. Windows 8 supports signatures created with the SHA256 hashing algorithm, but Windows 7
    does not. For Windows 7, you need a signature created with the SHA1 hashing algorithm.
    Suppose you want to build and sign a driver package that will run on Windows 7 and Windows 8 on x64 hardware platforms. You can sign your driver package with a primary signature that uses SHA1. Then you can append a secondary signature that uses SHA256.
    You can use the same certificate for both signatures, or you can use separate certificates. Here are the steps to create the two signatures using Visual Studio.
    In the Solution Explorer window, right-click Solution SolutionName, and choose Configuration Manager. For the driver project and the package project, set Configuration to Win7
    Release, and set Platform to x64.
    Open the property pages for the driver package. Navigate to Configuration Properties > Driver Signing > General. In the Sign Mode drop-down list, select Production Sign. For Production
    Certificate, enter the path to your signing certificate.
    In the property pages for the driver package, navigate to Configuration Properties > Custom Build Step > General. For Description, select Performing Custom Build Step. For Execute
    After, selectDriverProductionSign. For Command Line, enter this command.
    Signtool sign /fd sha256 /ph /as /sha1 XX...XX $(TargetPath)
    where XX...XX is the hash of the certificate you are using for the the secondary signature.
    Note  To see the hash (also called the thumb print) of a certificate, open a Command Prompt window and navigate to the directory that contains your certificate. Enter the command certutil -dump CertName.pfx,
    whereCertName.pfx is the name of your certificate.
    From what I gather, the issue is:
    1. Godaddy's "Driver Signing Certs" defaults to signing with a SHA 256. For whatever reason, most Win7 installations do not have the appropriate root cert installed to support SHA 256.
    2. According to Godaddy if I resign my Catalog file again with SHA1 then everything should work. They claim they have done this with other users.
    3. According to Microsoft the  Signtool utility used with following parameters will resign a Catalog that's already signed with SHA1 to SHA256.
    Signtool sign /fd sha256 /ph /as /sha1 XX...XX $(TargetPath)
    But I need to resign to SHA1. If I can resign to SHA1, then everything should work properly with the GoDaddy root that's installed normally in Win7 machines.
    Questions:
    1. Is Godaddy giving me bad info? According to them I can sign my Catalog file twice with the same cert. According to you I will need another cert.
    2. If I can double sign the Cat file, what are the proper Signtool parameters to make sure its signed again with SHA1.
    The Microsoft sample is for going from SHA1 to SHA256, but I'll need to go from SHA256 to SHA1. If I was using Godaddy's Code Signing Cert this would be an issue.
    Thanks
    Randy
    Randy Feingersh

  • Looking for best practice on naming conventions

    Does anyone out there have a best practice on naming conventions that they could share.
    I'm starting to find the need to create objects and associated variables and actions.
    I can see this getting very messy, very quickly and would love to learn if someone has come up with a good set of guidelines that are both easy to follow and make perfect sense. (I know....what a balance to ask for!)
    Thanks
    Alan

    Hi Alan,
    Welcome to Adobe Community.
    There are couple of things that you can keep in mind while naming objects.
    When creating custom text caption styles, be sure to follow the correct naming conventions. Each caption style has a unique name, and you must
    use this name at the beginning of each associated bitmap filename. For example, if you create a text caption style named “Brightblue,” the five
    bitmap images that constitute the new style should be named as follows:
    Brightblue1.bmp, an image with no callouts
    Brightblue2.bmp, an image with a callout to the right or upper-right
    Brightblue3.bmp, an image with a callout to the left or upper-left
    Brightblue4.bmp, an image with a callout to the lower right
    Brightblue5.bmp, an image with a callout to the lower left
    Flash button-naming conventions
    Each SWF button contains three layers: a button, an icon, and an action layer.
    The SWF filename consists of the following elements:
    Acronym for playback control (“pbc”)
    Playback element identifier (“Btn” for button, “Bar” for bar, and so on)
    Name of the button (“play”).
    Hope this helps!
    Thanks!

  • What is a good practice to handle LOV in jdev apps?

    Hi, experts,
    In jdev 11.1.2.3,
    In our projects, there are many LOVs which the value are stored in a common dictionary table, for example in table refcode:
    refcode(id, low_value,high_value,meaning,domain_no),
    Different LOVs will retrieve value pairs(low_value,meaning) , or (high_value,meaning) from refcode table by using domain_no as the filtering criteria.
    In the end user's UI, the code/number field values should be displayed by a meaning word from refcode,
    To accomplish this goal, I will create numberous associations between different tables with refcode,
    and create VOs to have refcode entity view as a secondary entity view.
    I feel some odd in doing so(because so many associations with the same refcode table),
    Is that a good practice to handle LOV this way ?
    Thanks.

    On Fusion Developer's Guide for Oracle Application Development Framework
    10.3 Defining a Base View Object for Use with Lookup Tables
    (http://docs.oracle.com/cd/E37975_01/web.111240/e16182/bclookups.htm#BABIBHIJ)
    10.3.3 How to Define the WHERE Clause of the Lookup View Object Using View Criteria
    There are valuable information and suggestions on implement lookup features, especially by using view criteria
    (the View Criteria and View accessor is one of important and great idea in ADF)
    I think, by using of view criteria, the derivative attribute to display fk information can be implemented in a convinent way without FK associations definition.

  • Overloaded methods-yes or no & is this a good practice

    say i have two methods with the same name that take in the same parameters and have the same return type. the difference between the two is that one is static while the other is not. Also the methods contain different codes.
    are the methods going to function normally when i use em? also if they do function normally, is this essentially a good practice?
    if code is needed to answer this, please do mention it and i will think of a mini scenario where this can be applied and write a small piece of code for that.
    thanx. help will be appreciated.

    avi.cool wrote:
    duffymo wrote:
    each account has its own password that the user sets when the account is created-this password is declared as a state variable in the class file. One password per account? A bad model, IMO. My on-line banking software associates credentials with me, not my accounts. I see several accounts when I log in, and I don't have to log in individually for each one.
    besides that, theres also a bank password-this is declared and initialized as a static state variable in the class file. some of the operations require the bank password for access while others require account password.Static bank password? I'm very glad this is a throw-away student exercise, because you have no idea what you're doing.hahaaa, tru tru, its for a skool assignment for my first ever programming course. though not a throw away, i putting a lot of work into this :-) i m not actually trying to resolve any security issues here or strengthen account security. basically, I am only trying to exhibit a tiny bit of creativity while showing understanding of course contents. so nothing to stress on :-D i know not very creative but its all i got at this stage.
    i was trying to exhibit the use of overloaded methods in my program by having method to check the password that the user enters to access operations.
    now the ones that require account password, i was thinking of having the password check method as a non-static method since its associated with the object.
    while the ones that need bank password, i wanted to have as static method.
    i wanted both methods to have the same name.You've no idea what you're doing.
    how i solved it,
    i decided on having both methods as static methods. the one that checks account password, takes in two parameters, the account name(object name) and the string to be checkd. the one that checks bank password, takes in only one parameter- the string to be checked.Wrong.i would be really thankful if you could help me rectify my mistake and advice on how i should be doing this. is there a conceptual error? i am a bit confused now.
    Its exactly what I told you.. but now, you just have to come on here and post this :p
    and isn't this sort of like cheating? :P I mean this IS our exam you know... You're basically asking other for the arithmetic and logic lol.

  • Link between code and code groups and inspection type

    Hi All,
    I want to know the link between code and Code Group for UD and inspection type?
    There is an option of choosing Usage selected set in SPRO "Seeting for inspection type".If i dont enter anything there,will it show all the code groups in the system while taking UD?
    Pls guide

    Hi Shreya,
    Yes, the link between code and Code Group for UD and inspection type is specific selection of UD related to specific inspection type.  Ex. there are separate UD codes individually for Goods receipt against PO, Gr against Production or for In-process inspection ets. so If you assign the selected sets at SPRO Inspection type, then while doing UD system will show UD codes related to only that inspection type.
    If you don't enter anything there at SPRO, you will see all the code groups in the system while taking UD and one can get confused in selecting the relevant code.
    so assigning of UD selected sets, plant wise (tick) at " Inspection types" is best practice.
    Best Regards,
    Shekhar

  • Regarding good practice

    Hi,
    Can somebody let me know whether it is a good practice to have two declare section in same procedure in pl/sql programming. Is there any draw back for same?
    Regards,
    basil Abraham.

    user575682 wrote:
    Can somebody let me know whether it is a good practice to have two declare section in same procedure in pl/sql programming. Is there any draw back for same? It is good practice not to have declare sections at all - as PL/SQL code is best done inside the Oracle database as stored packages and procedure and functions. This does not require a declare section at all - unless when dealing with the exception of dynamic PL code. (an exception that requires very sound technical reasoning)
    For the external applications making PL/SQL calls using anonymous PL/SQL code blocks, these may use declare sections.. but usually not. Why?
    Declarations are typical for variables to be used in the anonymous block. As bind variables should be used by the application, there is very seldom the need to make use of a declare section.
    So the declare section is not something that you should often see and use in production PL/SQL code. Both in stored code in the database, and in anonymous block code in external applications.
    Mostly the declare section is found in code (anonymous PL/SQL blocks) used for purposes like testing. (e.g. typically adhoc code and not formal production code)

  • Good practice question

    there is a procedure p(i in number, o out number) that checks some data and finishes this way if some criteria are met:
    procedure p(i in number, o out number) is
    select count(*) into v_counter
    from ... ;
    if v_counter > 0 then
      o := 123;
      return;
    end if;
    exception
      when others then
      o := 99999;
    end;is this a good practice to finish this way (ie. return) or some other ways would be better in terms of "good practice" (like raising custom exception and handling it in exception block where out variable could be set up)?
    I would appreciate your suggestions about good practices in scenario above.
    thank you

    943276 wrote:
    there is a procedure p(i in number, o out number) that checks some data and finishes this way if some criteria are met:
    ..snipped..
    is this a good practice to finish this way (ie. return) or some other ways would be better in terms of "good practice" (like raising custom exception and handling it in exception block where out variable could be set up)?I would call using out params as exception/error codes wrong. Never mind good or acceptable practise. It is just plain wrong. As wrong in PL/SQL as it would be wrong in Java, C#, Pascal or another language that implements exceptions.
    Why? Because in such a language an exception is raised to indicate an error condition - an exception to the norm has occurred. If code suppresses the exception, that code is now saying that there is no error condition. It explicitly tells the caller that processing was successful and no exceptions to the norm have occurred.
    Returning the error code as an out parameter is not acceptable - as the "contract" in such a language, between the caller and that code, states that errors are handled as exceptions. That is how the language is designed to be used. That is how the run-time of the language works.
    Violating this fundamental concept in such a language makes absolutely no sense.

  • Good practice to initalize all instance variables with type String to emptr

    Is it a good practice to initalize all instance variables with
    type String to emptry string?
    #1 approach:
    public class A
    { private String name = "";
    private String address ="";
    //etc...
    rather than
    #2 approach:
    public class A
    { private String name;
    private String address;
    //etc...
    When I read Java books, the examples don't usually do #1 approach.
    The problem is if we don't initialize to empty string, when we call
    the getter method of that instance variable, it will return null.
    Please advise. Thanks!!

    Please advise. Thanks!!It depends on your coding style. If you can avoid lots of checks for null Strings in the rest of the code then why not initialize to "".
    You have the same situation when a method returns an array. If you under circumstances return a null array reference then you have to always check for this special case, but if you return a zero length array instead you have no special case. All loops will just run 0 iterations and everything will work fine.
    So in general I guess the return of zero objects instead of null references really boils down to whether it simplicates the rest of your code by removing lots of extra checks for the special null case. This usage is especially favourable in the zero length array case. See Effective Java by Bloch, item 27.

  • Is it good practice?

    Is it good practice when using "jsp:incluce" to have the jsp that your including to have its own html <head>, <body> tags? Or does it matter at all?

    The oldest browser I checked was IE4.0. Leaving those tags doesn't cause any significant problem, but it's better to include them as a part of development.
    There are plenty of HTML authoring tools available on the market (free and commerical) which includes these tags by default for any .html files. Of course some of these tools allows you to configure the templates, so that next time when you create a .html/.jsp file, you don't have to type any thing except your customized code.
    /Sreenivasa Kumar Majji.
    skmajji,
    would leaving these tags out cause a problem in older
    browsers?

  • Some notes about Java code conventions

    Hello!
    I read the book "Java Code Conventions". It' good conventions but I have some notes Here is my offer
    1.Classes's names start with "C", e.g.
    CMain, CFileTool.
    2.Interfaces's names start with "I", e.g.
    IObserver, IDigitalListener.
    3. Exceptions's names startw with "E", e.g.
    EMyException
    4.Member objects variables start wiht "m_obj". Not member objects variables (local objects variables) start with "obj" respectively, e.g.
    public class CMain {
    private CText m_objText = new CText(); //my class CText
    private void anyMethod() {
    CText objText = new CText();
    5. Vector member variable start with "m_vec" Not member vector variable start with "vec" respectively. Hashtable member variable start with "m_hash".Not member hashtable variable start with "hash" respectively, e.g
    private Vector m_vecElements = new Vector();
    private Hashtable m_hashElements = new Hashtable();
    private void anyMethod() {
    Vector vecElements = new Vector();
    Hashtable hashElements = new Hashtable();
    6. String member variable start with "m_str". Not member string variable start with "str" respectively, e.g.
    private String m_strText = new String();
    private void anyMethod() {
    String strText = new String();
    7. Primitive types starts with "n", "b" and so on. , e.g.
    int nIndex = 4
    boolean bIsCorrect = true
    char cSymbol = 'a'
    float fNumber = 3
    double dNumber = 1.2
    long lNumber=1
    short sNumber=2
    and respectively it's classes start as section 4, e.g
    Integer objIndex = new Integer(nIndex)
    Boolean objIsCorrect = new Boolean(bIsCorrect)
    and so on
    The main idea on my convention is when somebody will look at , e.g. object he at once should understand about what there is this object, and not scrolling java file to understand this.
    It will be pleasant for me to receive your answers.Thank you

    Vector member variable start with "m_vec" Not member vector variable start with "vec" respectively. Hashtable member variable start with "m_hash".Not member hashtable variable start with "hash" respectivelyThere are over 2000 classes in the 1.4 SDK. You need to extend this rule to cover all of them, don't you? For examples, GraphicsConfigTemplate member variables must start with "m_graphicsconfigtemplate"...

  • Is it good practice to define text elements in User exits & there by using?

    Hi Experts,
    Simple doubt that, am wrting code in a User Exit. So, here my code works only, if the DOC TYPE = 'XXX'.
    So, instead of using hard coding as 'XXX', I wuld like to use a text element, like
    if DOC TYPE = text-xxx.
    my logic.
    endif.
    and creating the same text element.
    so, let me know that,
    Is it safe/recommended to use text-element in exits?
    Is it good practice to define text elements in User exits?
    thanq

    u can also use SET ID's if u dont want to hardcode like that in ur program.
    if u use SET ids , no need of transport request in case of change in the DOC types , directly u can change values in that set it , its like a master id.
    sytax will be like this
    doc_type in g_doc_type(this is set id ).
    for creation of set ids see tcode GS01.
    regards
    Prabhu

Maybe you are looking for

  • Whatsapp para iPhone 3G não funciona mais

    Whatsapp para iPhone 3G não funciona mais! Eu pedi uma ajuda no suporte do aplicativo e tive a seguinte resposta: Olá, Obrigado por entrar em contato conosco! Para que você possa conectar ao WhatsApp, ou ativar o seu número, você precisará ter a últi

  • FCPX, just the tip of the iceberg

    I know that everybody on this forum felt, at some point, a kind of hesitation regarding the software "I don't want to call it upgrade because it's not". I felt the same, but for some reason, probably related to my blind trust in apple and in all what

  • I can't get a game on my iPod, what am i doing wrong?

    i just bought the sonic game for my 8 GB iPod nano 3rd gen, and it won't let me put the game on my iPod, can anyone help me?

  • Inetgrating MDM Java API's with Java proxies on XI side

    Hello friends Can anyone help me on integrating MDM JAVA API's used for talking to MDM Server and the Javaproxies we generate from the XI side.I am having an application class inside the Java API's (it contains the main function)which triggers the fu

  • So what is the Database setting in Preference for?

    In the years of using Safari, in the Preferences it has settings for Database under Security tab. I've left it at the default 5mb. Whenever I clicked Show Database nothing was ever in there. But yesterday there were two items. I Removed them not payi