Good Programming Pratice

Hi,
I am a Java Programmer that do programming. Not an expert but still learning. I have a scenario in building codes with java good pratices.
Scenario:
I have coded a Java Program with following structure in seebeyond:
public void receive(){
a = startProcess(String, object, object);
public ArrayList startProcess(String, object, object){
addressObject = createNewAddress(String, object, object);
arrayList.add(addressObject);
return arrayList;
public Object createNewAddress(String, object, object){
object = constructAddressObject(String, object);
return object;
public void constructAddressObject(String, object){
object.setAddress1 = 'A';
object.setAddress2 = 'B';
}the question here is the void constructAddressObject function.
1.Shall i use void here or it is a good practice if i return a back the object i set earlier ?
2.What will be the drawback if i use void and if i chose to return a value, and what will be the Java good pratice in coding this since both void and returning a value works here.
3.My supervisor raise a issue that it is unsafe if i use void in this situation, is that true ? He wants me to change to return back the object.
hope to get some good advice here.

1.Shall i use void here or it is a good practice if i
return a back the object i set earlier ? From your code, it looks like you are changing the state of the object only. So, it is fine to use void. If you had some complex operations performed, you should return a boolean to indicate the status of the actions.
2.What will be the drawback if i use void and if i
chose to return a value, and what will be the Java
good pratice in coding this since both void and
returning a value works here.This should be decided in the design phase. Your method should either return a value and the type should be known, or it should not return anything. Is there any prupose for returning a value from that method?
3.My supervisor raise a issue that it is unsafe if i
use void in this situation, is that true ? He wants
me to change to return back the object. If you are directly modifying the state of the object by calling its method, as I assume your case to be, I don't see any reason for returning an object back. If this is not the case, your supervisor might be correct. The "correct" practice would be decided by the purpose of the method.

Similar Messages

  • What's a good program to use to make flyers and handouts with?

    What's a good program to use to make flyers and handouts with? I'm not a wiz with computers so nothing too sophisticated is needed. Thanks!

    Pages would be fine but there are hundreds, I'd recommend using the Mac App Store.

  • What is a good program to install windows via a flashdrive...Have the iso

    What is a good program to install windows via a flashdrive...Have the iso...

    What are you trying to do?
    You can install Windows in a Boot Camp partition and have a Dual Boot system where you run one operating system at a time. Either Windows or Mac OS X.
    Or you can use one of the 3 available virtual machine software parograms to install Windows in a virtual machine on top of Mac OS X. Then you can run both Windows and OS X at the same time.
    If you go with the Boot Camp option then you really need to burn that ISO file onto a DVD disc as Boot Camp likes to install from disc.
    If you go with the virtual machine option then you can use that ISO file as it is to install Windows. You will just point the VM to the USB thumb drive to find the Windows OS to do the install from.

  • Is Windows A Good Program To Use On Mac?

    I have a macbook and i would like to know, is it a good program to use on a macbook or any mac?

    Windows is not a program. It's an operating system that you run programs on. Whether or not you install Windows on you Mac is up to you. What is making you think you should install it? Do you have Windows only programs you need to run?

  • I am looking for a good program to edit existing websites for about $99.00

    I am looking for a good program to edit existing websites for about $99.00 or less, any suggestions?
    Thanks,
    New MacBook owner.
    Martin

    Welcome to Apple Discussions!
    http://www.barebones.com 's Textwrangler. Use http://www.anybrowser.org/ as a guide for good HTML composition.
    If a web editor does not give you power to do full text editing and claims to be WYSIWYG, don't believe it. Chances are, it uses assumed standards of specific browsers, which are not fully http://www.w3.org/ compliant.

  • Assistance with good programming

    Hey!
    I'm new to this Java game like most of the rest of us on here. I've just finished testing my first big project (calling methods etc.- all quite basic stuff)
    but I'm wondering if anyone out there could spare five minutes just to help me on the 'good programming' side of things.
    I didn't bother posting the code, but if someone can help me out I can get it to them.
    Many MANY thanks, and hopefully one day I'll be able to answer some of the other beginner questions myself!
    CoosMC

    From my limited programming knowledge, i believe that you are only suppose to put your variables outside of a method if absolutely necessary. This is because when the variables are declared outside of the method they are called global and will use up memory the entire time the program is running, compared to local variables which only use up memory when the specific method is called.
    As for the repeating of the variables as 0 or none outside AND inside the main method. If you are using global variables, then there is no need to repeat the numbers inside the main method, unless the values of the variables change AND the main method is called more than once in your program. Since your variables are within a while loop, then you will have to repeat the numbers if you want the same starting point every time. If you want the variables to keep the value of the previous loop, then do not put the 0 at the beginning.
    As for if private static int claimnum = 0 is necessary. take a look here to learn more about that and look at "Access Attributes" for more info as well as the rest of this tutorial.
    http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part1/page4.jsp
    anyone out there, please correct me if i'm wrong.
    i'm still a bit of a rookie myself.
    Andy

  • Good programming practices:   creating Iterator objects

    Hi,
    This is a question about Good programming practices for creating Iterator objects of ArrayList objects. The following line of code works fine in my program (as ridiculous as it may sound):
            Iterator cheesesIterator = cheeses.iterator();but I was wondering whether Java is automatically inserting the <Type> and new code to make:
            Iterator<String> cheesesIterator = new cheeses.iterator();and therefore whether it is good practice to use these everytime? Thank you. ("full" code shown below:)
    import java.util.ArrayList;
    import java.util.Iterator;
    public class DemonstrateIterator
        private ArrayList<String>  cheeses;
         * constructor:
        public DemonstrateIterator()
            cheeses = new ArrayList<String>();
            cheeses.add("Emmentaler");
            cheeses.add("Cheddar");
            cheeses.add("Stilton");
            cheeses.add("Brie");
            cheeses.add("Roquefort");
        public void listCheeses()
             //make an iterator object of the ArrayList object
            Iterator cheesesIterator = cheeses.iterator();
            while (cheesesIterator.hasNext()) {
                System.out.println(cheesesIterator.next());
            /** Exploring the toString and Super functions. **/       
            System.out.println("\na toString call to Super returns: " +
                                              super.toString() + "\n");
    }

    AJ-Phil wrote:
    Hi,
    This is a question about Good programming practices for creating Iterator objects of ArrayList objects. The following line of code works fine in my program (as ridiculous as it may sound):
            Iterator cheesesIterator = cheeses.iterator();but I was wondering whether Java is automatically inserting the <Type> and new code to make:
            Iterator<String> cheesesIterator = new cheeses.iterator();and therefore whether it is good practice to use these everytime? TFirst, new chesses.iterator() won't compile.
    iterator() is just a method that returns an iterator. It constructs an instance of a private or nested class that implements iterator, and returns a reference to it.
    As for the <T>, when you declare List<String>, that parameterizes that list with type String. The iterator() method returns Iterator<T>. You can look at the source code for yourself. It's in src.zip that came with your JDK download.
    Separate from that is your declaration of that variable as type Iterator, rather than Iterator<String>. Regardless of what you declare on the LHS, the iterator() method returns Iterator<T>. Your bare Iterator is essentially Iterator<Object> or Iterator<? extends Object> (not sure which, or what the difference is), which is assignment compatible with Iterator<T>. If you had declared it Iterator<String>, you wouldn't have to cast after calling next().
    Edited by: jverd on Nov 23, 2008 11:33 AM

  • Good programming tactics

    hi. i thought i'd like to start a thread on good programming tactics.
    ill start with a few questions:
    interfaces, abstract classes, and polymorphism, when are they REALLY useful?
    (and how does one REALLY use them?)

    Interface � An interface is like an agreement between you and another programmer. An example would be if you designed some software that needs an XML parser and you used an old XML parser that you wrote a few years ago. You know that the parser is not really, really good code but it�s good enough for your program. You also know that maybe someone who wants to use your code may want to add his or her own XML parser that work much better.
         If you use an interface to access the original parser in your code then you can give them the ability to rapidly add their own parser. What the interface does is give the other programmer a set of routines that he must have to work correctly with your program. If he can write a better parser that supports all these routines then he can use it and the interface is the guarantee that the compiler will use to verify that his program has all the proper methods to work with your program.
         Note: Some programmers use interfaces as a way to inherit multiple classes. java does not support extending (read inheriting) more than one class so a common way to get around this is to use interfaces which is not exactly the same but is the way to support this in java.     
    Abstract Class � An abstract class is similar in use to an interface. Where an interface is only a group of methods without any code, an abstract class is class that can never be created (instantiated), can have runnable code and will normally have some abstract methods which are similar to the methods in an interface.
    You can only use an abstract class to create other classes using the keyword extends and it must have it�s own version of every method that is abstract in the original abstract class. The use of abstract methods forces the programmer who uses your class to write methods that are necessary for the class to function correctly.
    An example of where to use this would be in graphics classes. You might have an abstract class called GraphicObject. This class would have several useful calls to methods ( i.e. setColor() ) and several useful fields and it might also have an abstract method called draw.
    The programmer would have to write a method to draw his GraphicObject as a circle would be drawn different than a rectangle.
    The original programmer knew that if you wanted to use his class GraphicObject then you must write a routine that will draw your GraphicObject. The absract class will take care of accessing the graphics card and setting up the environment to draw the object.
    The following I borrowed from http://www.developer.com/tech/article.php/983081 where you can read more about poly morphism if you want to. As you can see polymorphism is directly involved with interfaces and abstract classes.
    What is polymorphism?
    The meaning of the word polymorphism is something like one name, many forms.
    How does Java implement polymorphism?
    Polymorphism manifests itself in Java in the form of multiple methods having the same name.
    In some cases, multiple methods have the same name, but different formal argument lists (overloaded methods, which were discussed in a previous lesson).
    In other cases, multiple methods have the same name, same return type, and same formal argument list (overridden methods).
    Three distinct forms of polymorphism
    From a practical programming viewpoint, polymorphism manifests itself in three distinct forms in Java:
    Method overloading
    Method overriding through inheritance
    Method overriding through the Java interface
    Hope this helps and doesn't confuse you more. I am sure that someone is going to find things to correct but I believe the general ideas are right.

  • Good program to burn dvd's

    good program to burn dvd

    Hi manuweb_21.
    your thread contain an issue that apple prohibit user to post based on user agreement about ripping ditigal media with copyright.
    Do not submit software or descriptions of processes that break or otherwise ‘work around’ digital rights management software or hardware. This includes conversations about ‘ripping’ DVDs or working around FairPlay software used on the iTunes Store.
    Taken from:
    http://discussions.apple.com/help.jspa
    Good Luck.

  • Good programming practice - Abstract class

    Hi all,
    I have been trying to help another soul in this forum, and came to the conclusion that I don't know good
    programming practice when it comes to abstract classes.
    Is this correct?
    You CAN implement methods in an abstract class, but it's not recommended.
    I have NEVER done this...when is there possibly a need to?
    Regards.
    / k

    Yes, absolutely, you can implement methods in an abstract class. Any method that all subclasses will perform in the same way can be implemented in the abstract base class. If subclasses perform similiar functions depending on their type you declare those as abstract in the base class. Here is a contrived example that I have seen on job interviews.
    Suppose your developing an application that draws on a panel. We want to provide some canned shapes such as a circle, a square and a triangle. We want to be able to draw the shape set or get its color and calculate its area.
    Let's define an abstract base class Shape
    public abstract class Shape{
        private Color myColor;
       //  since color has nothing to do with what kind of shape we're working with, create concrete implementation
       public Color getColor(){
            return myColor;
    public void setColor(Color newColor){
       myColor = newColor;
    // however, drawing the shape and calculation its area are depending on the actual shape.
    public abstract void draw();
    public abstract double getArea();
    // so then Square would be something like
    public class Square extends Shape{
       public double get Area()
          return sideLength * sideLength  // assumes somehow we know sideLength
    public void draw(){
                  // concrete implementation
    }we can do the same things for Circle class and Triangle class.
    And, if you think about it you'll notice that we could have made a Rectangle class and then Square would be a subclass of Rectangle where both dimensions are equal.
    I hope that somewhat strained example helps answer your question.
    DB

  • Any good program for soundboard on skype?

    i got tons of voice clips that i want to use in skype chats but i cant find a good program that i can use as a soundboard any suggstions?

    please?

  • Do IOS app developers follow any good program practices?

    I've had my iPad (original) a little over two years now, and I can say without a doubt, it is the most unstable platform I've used in nearly 30 years of using computers.  Most apps crash routinely, usually while at least one other app is running in the background.  Unloading the crashed app from memory and reopening uually works, but is a huge nuisance (and reason enough to me why iPads are not business-ready, except for specific task applications requiring mobility).  As one trained in both software and systems engineering, with 20 years IT experience mostly in engineering, I have to conclude that IOS app developers use "code and fix" development, with little testing before release.  Of course, in theory it could be that IOS itself isn't well designed to handle multitasking and doesn't provide adequate process isolation.  Either way, it makes for a frustrating experience as a user.
    Has anyone else had similar issues?  Thoughts on why?

    The original iPad does poorly with multiple apps open, the memory is just too small at 256 MB.  The processor is very slow compared to those in the current generation iPads.  And then couple that with developers who are for the most part independent of Apple and merely submit there products to Apple and you get a totally unpoliced set of apps.  Some are true professionals and follow very good programming practices, one that comes to mind is the GoodReader PDF reader.  Very stable and very powerfully built.  then you get into the gamers and Is is almost like they never heard of writing effecient, compact code.
    The issue I see is a tightly controled operating system, with app developers handed a set of specs under which to code, but no real controls other than does the app run and is it free of malicious code.
    Just some thoughts.

  • Searching for a good programming text editor

    Does there exist a text editor for Linux that has got these features?
    -can open multiple documents
    -can easily switch to any open document, e.g. by just clicking the document in a list or tree on the left (tabs alone won't do because there's not enough space to slow 20+ documents if there are only tabs)
    -has a built in command prompt to type compile and debugging commands, which is by default in the folder where your documents are, if all documents are in the same folder at least, otherwise it doesn't really matter to me
    -can save sessions, projects, ..., which basically is a way to quickly open your multiple documents belonging to a certain project
    -has a super cool search function with options like "whole word" and "case sensitive" clearly visible in the search dialog, and remembering these settings for any open document you search in
    -can easily search through all open documents (e.g. like visual studio can)
    -has the type of text editing GUI where you can use the mouse to select text, use ctrl+a to select all, use ctrl+c/ctrl+v to copy paste, home/end to navigate the cursor to begin/end of line, F3 to search for next match, etc... (so no vi derivates I'm afraid)
    -has modern interface, menus, file save/open dialogs, etc..., not something that appears to come from 1995 (so I think emacs is out of the question)
    What I'm looking for is similar to Kate 3.5 or parts of MS Visual Studio. However Kate 4.1 isn't suitable anymore because they destroyed the search function of it. And preferably something that is independent of a desktop, because it's sad that Kate's features can get ruined by people who develop a desktop.
    Does anyone have ideas if there exists such a program?
    Last edited by aardwolf (2009-04-25 09:15:07)

    Wra!th wrote:You described SciTE
    Look good, but ONE thing: I found that F8 "Output" opens a screen that has some properties of a linux terminal except some weird "Exit code:1" messages. However, if I press the "up" arrow, it doesn't scroll through the console history but instead moves a cursor up. I need it to work like a linux terminal with history because I don't want to retype long commands all the time. It also doesn't show the correct type and color of my user prompt. Is there any way to get a more conventional console in the Scite window somewhere?
    Also, scite's interface also looks a bit 1995
    EDIT: oh hmmm and it appears to not be able to open more than 10 files. That's too limited I'm afraid
    Shame, it almost looked like what I needed.
    Last edited by aardwolf (2009-04-25 12:11:21)

  • What is a good program to recover erased photos?

    I accidently erased some photos, and I have found programs listed online to recover the erased images. Any suggestions on a good, safe program to download and use? Prefer free.
    Solved!
    Go to Solution.

    What brand card is it.  Sandisk and Lexar have there own like Sandisk RescuePro. Lexar Image Rescue.
    Or click here.  There are several free ones out there two.
    EOS 1Ds Mk III, EOS 1D Mk IV EF 50mm f1.2 L, EF 24-70mm f2.8 L,
    EF 70-200mm f2.8 L IS II, Sigma 120-300mm f2.8 EX APO
    Photoshop CS6, ACR 8.7, Lightroom 5.7

  • A good program to record WAVE to dvd 1 & 2 laye

    I have Audigy 4 pro , what I found is that I can't find a program that records wave to dvd & or 2 layer (it would be good if it burned cd too.) Can anyone recommend a program that will do this ( it would be nice if it did not break the bank if you know what I mean) nero or roxio will not do it . Thanks for any help with this simple problem. I have had no luck maybe one of you have the answer.

    Eric...Thanks a million. They look promising.
    As an aside, me being from San Diego, and therefore a frustrated Padres fan, I have to envy both your Cubs and your fans, especially the fans that can reach from the stands onto the field and almost catch a foul ball.
    I understand you folks lynched poor Mr. Sussman (I may be wrong on the name).
    Again, thanks-
    iMac Intel Duo/MacBook Pro 2 Gigs RAM ea. Sony VAIO/ 3 keyboards 2 hands   Mac OS X (10.4.7)   iMac 20" Intel core duo-250Gig HD-2Gig RAM/Macbook Pro Parallels/80/120/160 HD's

Maybe you are looking for

  • Issue in ALV List display

    Issue in ALV List display   Posted: Apr 5, 2008 10:25 AM     Edit      E-mail this message      Reply  Hi Friends, Can any one help me out in the logic to display the output in the ALV list. i want to get the out put as based on the field4 i have to

  • ALV Grid Total Text (OOPS)

    Hi All, I have a simple ALV Grid Report(OOPS), I would like to give a Text for Total Row. In REUSE_ALV_GRID we have the option of giving this text, but i am not able to figure it out how to get the same in OOPS. Regards Anup

  • Asm, instance and service failing to start 10g rac redhat el5

    hi, i have been following a how to guide from oracle's website about implementing a 10g rac system using el5 (http://www.oracle.com/technology/pub/articles/hunter_rac10gr2_iscsi.html), by the end of the installation and setup I had both the nodes up

  • Misspelled words in a converted PDF document

    I converted a PDF document into a Word 7 document. One word ("breakfast") was misspelled throughout the Word document. What happened to allow a misspelling?

  • Consuming Web Service from ABAP

    I'm using WAS 6.4 SP10. I'm trying to consume a web service from our Intranet using instructions from ABAP256 from Teched 04. I get an error when I try to create a Proxy object. From SE80 Enterprise Services>Create>Proxy Object URL/HTTP Destination: