Constructor ? best practice

Hi folks,,
this is my piece of my code. i had a doubt on the  initializing the variable inside constructor or else before the constructor.?
    private java.net.URL xl = Thread.currentThread().getContextClassLoader().getResource("z.xml");
  private static Logger log;   
  sSessionBean csb = (sSessionnBean)Util.getMBean("ssbean");
  public cWrapper()
super();  
log = Logger.getLogger(sWrapper.class.getName());
consider x1,csb variable these two variable declared and initialized that place itself...
consider log variable this is declared in the appropriate declaration section and initialized in constructor.
which is best to practice to initialize.?
thanks

consider log variable this is declared in the appropriate declaration section and initialized in constructor.
No - it isn't. You defined 'log' as static.
private static Logger log; 
Therefore 'log' is initialized when the class itself is initialized. Since your code does not assign a value the variable will be initialized to 'null'.
Be careful that you understand the difference between 'initialization' and 'assignment'; they are two related, but different, things.
See section '8.3.2. Initialization of Fields' in the Java Language Spec
http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.2
  If the declarator is for a class variable (that is, a static field), then the variable initializer is evaluated and the assignment performed exactly once, when the class is initialized (§12.4.2). 
In the constructor you are merely assigning a new, non-null, value to the 'log' variable.
this is my piece of my code. i had a doubt on the  initializing the variable inside constructor or else before the constructor.?
which is best to practice to initialize.?
The decision of whether to initialize instance variables and, if so, where to physically place those initial assignment statements is up to you and should depend on when you need the instance variables to have a value.
The physical placement of the assignment might be before, within, or after (which you didn't mention) any particular constructor and may be performed within a method of the class or instance.
See this example code from the Java Language Spec showing an assignment statement physically after the constructor:
http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.2.3
class Test2 {
  Test2() { k = 2; }
  int j = 1;
  int i = j;
  int k;
You have over-simplified the possibilities:
1. There can be both static and instance variables - statics are ALWAYS initialized exactly once but can then, if not declared 'final' have new values assigned later in constructors or methods.
2. Variables can be declared as 'final' - in which case they will be initialized and given a value only once.
3. There are often multiple constructors - not just the one you have in your example. So an instance variable that needs the same common value regardless of the constructor being used would be given that value OUTSIDE of any constructor. It would be unnecessary, and poor practice, to repeat the variable assignments in every constructor.
Each of the constructors could also, if required, assign a different initial value to an instance variable.
4. Different class instances may need the variables initialized to different values. This is related to the previous example. A constructor may take parameters whose value is used to make an assignment to a variable. The constructor code may determine which variables to assign values to and what values to assign.
5. Some instances may seldom need a variable to be initialized and when they do will initialize it within a method. For those use cases neither the variable declaration nor any of the constructors will provide an initial value.
An often ask question related to yours is whether to physically put variable declarations for a class at the start of the class file or at the end. IMHO that is more of a personal preference; I don't believe there is a 'best practice'. An org will usually specify one or the other as part of their coding standards that are to be followed.

Similar Messages

  • JSF - Best Practice For Using Managed Bean

    I want to discuss what is the best practice for managed bean usage, especially using session scope or request scope to build database driven pages
    ---- Session Bean ----
    - In the book Core Java Server Faces, the author mentioned that most of the cases session bean should be used, unless the processing is passed on to other handler. Since JSF can store the state on client side, i think storing everything in session is not a big memory concern. (can some expert confirm this is true?) Session objects are easy to manage and states can be shared across the pages. It can make programming easy.
    In the case of a page binded to a resultset, the bean usually helds a java.util.List object for the result, which is intialized in the constructor by query the database first. However, this approach has a problem: when user navigates to other page and comes back, the data is not refreshed. You can of course solve the problem by issuing query everytime in your getXXX method. But you need to be very careful that you don't bind this XXX property too many times. In the case of querying in getXXX, setXXX is also tricky as you don't have a member to set. You usually don't want to persist the resultset changes in the setXXX as the changes may not be final, in stead, you want to handle in the actionlistener (like a save(actionevent)).
    I would glad to see your thought on this.
    --- Request Bean ---
    request bean is initialized everytime a reuqest is made. It sometimes drove me nuts because JSF seems not to be every consistent in updating model values. Suppose you have a page showing parent-children a list of records from database, and you also allow user to change directly on the children. if I hbind the parent to a bean called #{Parent} and you bind the children to ADF table (value="#{Parent.children}" var="rowValue". If I set Parent as a request scope, the setChildren method is never called when I submit the form. Not sure if this is just for ADF or it is JSF problem. But if you change the bean to session scope, everything works fine.
    I believe JSF doesn't update the bindings for all component attributes. It only update the input component value binding. Some one please verify this is true.
    In many cases, i found request bean is very hard to work with if there are lots of updates. (I have lots of trouble with update the binding value for rendered attributes).
    However, request bean is working fine for read only pages and simple binded forms. It definitely frees up memory quicker than session bean.
    ----- any comments or opinions are welcome!!! ------

    I think it should be either Option 2 or Option 3.
    Option 2 would be necessary if the bean data depends on some request parameters.
    (Example: Getting customer bean for a particular customer id)
    Otherwise Option 3 seems the reasonable approach.
    But, I am also pondering on this issue. The above are just my initial thoughts.

  • Best practice for declaring and initializing String?

    What is the best practice for the way Strings are declared in a class?
    Should it be
    private String strHello = "";
    or should I have the initialization in the constructors?

    The servlet constructor is usually called once, when the servlet is first accessed. But then again maybe something else happens, google servlet life cycle if you must know.
    But let's take a step backwards here. It seems like you are trying to put fields into servlets. Don't do that. When two users fetch the servlet's URL at the same time, the fields are shared between the two hits. If you store something like HTTP parameters in the fields, the two hits' parameters will get mangled. The hits can end up seeing each other's parameter values.
    The best way is not to have fields in servlets. (Except maybe "static final" constants, sometimes rarely something else.) Many concurrency worries go away, servlet life cycle worries go away, servlet constructors go away, init() usually goes away.

  • Best practice for setting or detecting screen size?

    Hi All,
    Trying to determine a best practice for setting or detecting the screen size. For playbook and iOS, I can set them. But for Android, the number of devices is too large so I'd rather detect. My first choice is to use the stage.stageHeight and stage.stageWidth. This works fine if I set my stage properties with standard meta data:
    [SWF(height="320", width="480", frameRate="64", backgroundColor="#010101")]
    However, if I use the application descriptor file to set the stage dimentions (as suggested by Christian Cantrell here http://www.adobe.com/devnet/flash/articles/authoring_for_multiple_screen_sizes.html)
    <initialWindow>
    <aspectRatio>landscape</aspectRatio>
    <autoOrients>false</autoOrients>
    <width>320</width>
    <height>480</height>
    <fullScreen>true</fullScreen>
    </initialWindow>
    Then the stage.stageHeight and stage.stageWidth are not the correct numbers when my main class is added to the stage. Sometime after the main class is added to the stage, then those numbers are fine. Is there an event I can wait for to know that the stage.stageHeight and stage.stageWidth are correct?
    Thanks in advance!

    Hi Lee,
    Thanks for the quick response! However, for some reason the heightPercent & widthPercent metadata tags are not working as expected for me.
    I have a wrapper class that I target for compiling, WagErgApplePhone.as where I've got my metadata
    [SWF(heightPercent="100%", widthPercent="100%", frameRate="64", backgroundColor="#010101")]
    sets some stage properties
    stage.quality=StageQuality.LOW;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align = StageAlign.TOP_LEFT;
    and instantiates my main class
    var main:Main = new Main();
    addChild(main);
    my main class constructor even waits for the stage
    public function Main(){
    if (stage) init();
    else addEventListener(Event.ADDED_TO_STAGE, init);
    in my init function, stage.stageHeight traces out as 375 (expecting 320).
    i have a function which is called via a button press event by the user, and stage.stageHeight traces out correctly (320) there. that's what makes me think that if i wait long enough, i can get the correct stageHeight before init/drawing. but i'm not sure what event to listen for, or if there's another trick.
    if i use Capabilities.screenResolutionX and Capabilities.screenResolutionY the correct values are provided for mobile, but these values are not useful for the desktop and web version of the app. if there's no other solution, i'll execute different code depending on platform.
    again, for reference, my app descriptor:
    <initialWindow>
    <aspectRatio>landscape</aspectRatio>
    <autoOrients>false</autoOrients>
    <width>320</width>
    <height>480</height>
    <content>bin-iOS/WagErgApplePhone.swf</content>
    <title>WAG ERG</title>
    <fullScreen>true</fullScreen>
    <renderMode>cpu</renderMode>
    </initialWindow>
    looking forward to any other ideas to try out & thanks so much for your thoughts! if you want to really dig in, this is an opensource project at code.google.com/p/wag-erg/

  • Best practice for adding text to Flex container?

    Hi,
    I'm having some troubles to lay a TextFlow class out properly
    inside a Flex container. What's the best practice to achieving
    this, for example adding a lot of text to a small Panel?
    Is it possible to pass anything other than a static width and
    height to DisplayObjectContainerController constructor, or is this
    not the place to implement this? I guess what I am looking for is
    the layout logic I'd normally pack into a custom Flex component and
    implement inside measure() and so on.
    My use case: a chat application which adds multiple TextFlow
    elements to a Flex container such as Panel. Or use TextFlow as a
    substitute for UITextField.
    Some example code would help me greatly.
    I'm using Flex 3.2.
    Regards,
    Stefan

    Thanks Brian, the example helps. However problems quickly
    arise if I modify it slightly to this (please compile it to see):
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" initialize="init()">
    <mx:Script>
    <![CDATA[
    import flashx.textLayout.compose.StandardFlowComposer;
    import
    flashx.textLayout.container.DisplayObjectContainerController;
    import flashx.textLayout.container.IContainerController;
    import flashx.textLayout.elements.TextFlow;
    import flashx.textLayout.conversion.TextFilter;
    private var _container:Sprite;
    private var _textFlow:TextFlow;
    private function init():void
    _container = new Sprite();
    textArea.rawChildren.addChild(_container);
    var markup:String = "<TextFlow xmlns='
    http://ns.adobe.com/textLayout/2008'><p><span>Hello
    World! Hello World! Hello World! Hello World! Hello World! Hello
    World! Hello World! Hello World! Hello World! Hello World! Hello
    World! Hello World! </span></p></TextFlow>";
    _textFlow = TextFilter.importToFlow(markup,
    TextFilter.TEXT_LAYOUT_FORMAT);
    _textFlow.flowComposer.addController(new
    DisplayObjectContainerController(_container, 200, 50));
    _textFlow.flowComposer.updateAllContainers();
    ]]>
    </mx:Script>
    <mx:Canvas width="100" height="100" id="textArea" x="44"
    y="46" backgroundColor="#F5EAEA"/>
    </mx:Application>
    What is the best way to make my textflow behave like a
    'normal' UIComponent in Flex? Should I use UIComponent instead of
    Sprite as a Container? Will that take care of resize behaviour?
    I have never before needed to use rawChildren.addChild for
    example, maybe you can explain why that's needed here?
    I realise that the new Textframework works on an AS basis and
    is not Flex or Flash specific, but this also poses some challenges
    for those of us using the Flex framework primarily.
    I think it would help to have some more basic examples such
    as using the new text features in a 'traditional' context. Say for
    example a TextArea that is just that, a TextArea but with the
    addition of inline images. I personally feel that the provided
    examples largely try to teach me to run before I can walk.
    Many thanks,
    Stefan

  • "Best practice" for components calling components on different panels.

    I'm very new to Swing. I have been learning from tutorials, but these are always relatively simple interfaces , in which every component and container is initialised and added in the constructor of a main JFrame (extension) object.
    I would assume that more complex, real-world examples would have JPanels initialise themselves. For example, I am working on a project in which the JFrame holds multiple JPanels. One of these Panels holds a group of JToggleButtons (grouped in a ButtonGroup). The action event for each button involves calling the repaint method of one of the other Panels.
    Obviously, if you initialise everything in the JFrame, you can simply have the ActionListener refer to the other JPanel directly, by making the ActionListener a nested class within the JFrame class. However, I would like the JPanels to initialise their own components, including setting the button actions, by using an extension of class JPanel which includes the ActionListeners as nested classes. Therefore the ActionListener has no direct access to JPanel it needs to repaint.
    What, then, is considered "best practice" for allowing these components to interact (not simply in this situation, but more generally)? Should I pass a reference to the JPanel that needs to be repainted to the JPanel that contains the ActionListeners? Should I notify the main JFrame that the Action event has fired, and then have that call "repaint"? Or is there a more common or more correct way of doing this?
    Similarly, one of the JPanels needs to use a field belonging to the JFrame that holds it. Should I pass a reference to this object to the JPanel, or should I have the JPanel use "getParent()", or some other method?
    I realise there are no concrete answers to this query, but I am wondering whether there are accepted practices for achieving this. My instinct is to simply pass a JPanel reference to the JPanel that needs to call repaint, but I am unsure how extensible this would be, how tightly coupled these classes would become.
    Any advice anybody could give me would be much appreciated. Sorry the question is so long-winded. :)

    Hello,
    nice to get feedback.
    I've been looking at a few resources on this issue from my last post. In my application I have been using the Observer and Observable classes to implement the MVC pattern suggested by T.PD.(...)
    Two issues (not fatal, but annoying) with this are:
    -Observable is a class, not an interface; since most of my Observers already extend JPanel (or some such), I have had to create inner classes.
    -If an Observer is observing multiple Observables, it will have to determine which Observer called its update() method (by using reference equality or class comparison or whatever). Again, a very minor issue, but something to keep in mind.I don't deem those issues are minor. The second one in particular, is rather annoying in terms of maintenance ("Err, remind me, which widget is calling this "update()" method?").
    In addition to that, the Observable/Observer are legacy non-generified classes, that incurr a loosely-typed approach (the subject and context arguments to the update(Observable subject, Object context) methods give hardly any info in themselves, and they generally have to be cast to provide app-specific information.
    Note that the "notification model" from AWT and Swing widgets is not Observer-Observable, but merely EventListener . Although we can only guess what reasons made them develop a specific notification model, I deem this essentially stems from those reasons.
    The contrasting appraoches are discussed in this article from Bill Venners: The Event Generator Idiom (http://www.artima.com/designtechniques/eventgenP.html).
    N.B.: this article is from a previous-millenary series of "Design Techniques" articles that I found very useful when I learned OO design (GUI or not).
    One last nail against the Observer/Observable model: these are general classes that can be used regardless of the context (GUI/non-GUI code), so this makes it easier to forget about Swing threading rules when using them (essentially: is the update method called in the EDT or not).
    If anybody has any information on the performance or efficiency of using Observable/ObserverI would be very surprised if this had any performance impact. If it had, that would mean that you have either:
    - a lot of widgets that are listening to one another (and then the Mediator pattern is almost a must to structure such entangled dependencies). And even then I don't think there could be any impact below a few thousands widgets.
    - expensive or long-running computation in the update methods. That's unrelated to the notification model itself.
    - a lot of non-GUI components that use the Observer/Observable to communicate among themselves - all the more risk then, to have a GUI update() called outside the EDT, see remark above.
    (or whether there are inbuilt equivalents for Swing components)See discussion above.
    As far as your remark 2 goes (if one observer observes more than one subjects, the update() method contains branching logic) : this also occurs with the Event Delegation model indeed: for example, it is quite common that people complain that their actionPerformed() method becomes unwieldy when the same class listens for several JButtons.
    The usual advice for this is, use anonymous listeners, each of which handles the event from only one source (and generally very close in code to the definition of that source), and that simply translates the "generic" event notification method into a specific method call of a Controller or Mediator .
    Best regards.
    J.
    Edited by: jduprez on May 9, 2011 10:10 AM

  • JSF best practice for managed bean population

    hi;
    consider a simple session scope managed bean with 1 attribute which is calculated dynamically.
    there seem to be 3 ways of populating that attribute (that i could think of):
    1. have the bean's get<attribute> get the data and populate it
    2. have the constructor of the bean get the data and populate it
    3. have an action get the data, and set it from the action code (maybe use a valueBinding to get the bean if the bean which needs population is not the same bean that holds the action) .
    option 1 seems ok for situations where i need my data to be calculated for every valueRef for that attribute but is an overhead for data that need not be calculated for every valueRef.
    option 2 will ensure that te data is calculated only once per session. but it still looks kinda strange to do it
    with option 3, it seems you should populate the dynamic content of the next page and its intuitive but some places in the page might be common content with dynamic data and this has nothing to do with navigation and the next page to be displayed.
    is there a best practice of how to populate a managed bean data?
    are different cases fit different ways?
    any thoughts are appriciated.

    I think it should be either Option 2 or Option 3.
    Option 2 would be necessary if the bean data depends on some request parameters.
    (Example: Getting customer bean for a particular customer id)
    Otherwise Option 3 seems the reasonable approach.
    But, I am also pondering on this issue. The above are just my initial thoughts.

  • Which wayis the best practice ?

    Hi ,
    I am doubt of which way is the best practice to initialize instance component in a Panel.
    ie .is there any diference, in terms of performance , between initializing component inside the constructor or just outside of constructor?
    1)
    public class MyPanel extends JPanel
    private static JScrollPane scrollPane = new JScrollPane();
    public CustomerTaskPane()
    2)
    public class MyPanel extends JPanel
    private static JScrollPane scrollPane = null;
    public CustomerTaskPane()
    scrollPane = new JScrollPane()
    }

    Correction for the above reply.
    *btw can i avoid from declaring the static field of a class itself when i need to implement the class which follows Singleton pattern like.
    public class CustomerMainPanel extends JPanel
    public static CustomerMainPanel customerMainPanel = null;
    public static synchronized CustomerMainPanel getInstance()
    if( customerMainPanel == null )
    customerMainPanel = new CustomerMainPanel();
    return customerMainPanel;
    }

  • Best practice for Exceptions

    I wrote my own Exception class. When using it, I'm NOT sure what the best practice is.
    This is a code snippet for a fire object:
    public void doSomething(){
                      try{
                        fire = true;
                        throw new ControllerException("Warning: Reactor meltdown");
                   catch(ControllerException e){
                        System.out.println("Warning: Reactor meltdown");
              public String toString(){
                           return "Warning: Reactor meltdown";
                    }The fire class extends the abstract Disaster class which means that I have to declare a doSomething() method. It is an overridden method. It will run for all subtype objects that are created. Also the toString() method will be run for every object. So I need those two methods. When I run the program, I get the message 3 times obviously.
    What I want to know is, where is the best place to send the message from? What is the best programming practice?
    For example, should I make my Exception class with a no-args constructor and then make the toString() method blank? Or should I eat the Exception (supposedly a bad practice) and use the Constructor to send the message?
    Edited by: SquareBox on Apr 12, 2011 10:24 AM

    Not sure I understand your question.
    SquareBox wrote:
    I wrote my own Exception class. When using it, I'm NOT sure what the best practice is.
    This is a code snippet for a fire object:
    public void doSomething(){
                      try{
                        fire = true;
                        throw new ControllerException("Warning: Reactor meltdown");
                   catch(ControllerException e){
                        System.out.println("Warning: Reactor meltdown");
              public String toString(){
                           return "Warning: Reactor meltdown";
    What class is this whose toString() method always returns "meltdown"? That makes no sense.
    Why are you throwing an exception and then immediately catching it in the same try statement? I really don't get what you're trying to show here.
    What I want to know is, where is the best place to send the message from? What do you mean "send the message"?
    What is the best programming practice?It depends.
    For example, should I make my Exception class with a no-args constructor Usually you would declare a no-arg c'tor, one that takes a String (message), one that takes a Throwable (cause), and one that takes both, all of which just invoke super(...) with the same args. Look at the code for the Exception class for an example.
    and then make the toString() method blank?You usually would not override toString(), since Throwable already does that.
    Or should I eat the Exception (supposedly a bad practice) and use the Constructor to send the message?No idea what you mean by "use the constructor to send the message".

  • Best Practice: Executing the same code from different triggers

    Swing supports the idea of Actions, which seems to be an implementation of the "Command" pattern. One can create an instance of an Action implementation and set it to several JComponents, like JButton and JMenuItem. Whenever the button or the menu item is triggered, the action gets executed. So far, so good.
    But there are more triggers in Swing that cannot get configured to trigger an action, namely Drops and pressing the window's [X] Close icon. Certainly these fire events, but they do not automatically trigger actions.
    Certainly one can react to importData(TransferSupport) and windowClosing() by manually calling the action's actionPerformed(ActionEvent) method, but as there is no setAction(Action) method at neither the TransferHandler class nor the WindowAdapter class, the question is: Where to take that Action instance from, and what command name to pass to it's constructor, and what to provide as the event source?
    It just seems like the Action framework has a gap here, as it nicely covers these questions for JComponents, but not for JFrame and JDialog.
    So unless there are JFrame.setDropAction(Action) and JFrame.setCloseAction(Action) methods added to the Swing framework (and I doubt they will get added any time near), my question is whether there have been establed some widely accepted best practices (i. e. something that 75% of the programmers will do, not something ONE programmer always does but just he does). Any Swing expert here answering this?

    The window decorations are handled by the OS. That [X] close button isn't a JButton at all.
    JFrame's and JDialog's, however, do have a root panes. And you can ask the root pane to take over window decorations via JFrame#setDefaultLookAndFeelDecorated(true). JDialog has a similar method. When the root pane takes over window decorations, then the [X] icon is a JButton and you could, in theory, set its action to an Action object.
    The the metal LAF window decorations, however, are ugly (I think at least) and I'm not sure how many programs actually use it.

  • JSF CDI : Conversation scope bean[s] best practice

    *JSF CDI : Conversation scope bean[s] best practice*
    Hello, im currently learning about JSF 2.0 and im so glad for the existence of this conversation scope feature, which is very helpful in opening a new tab or a new window on the same page and having separate resources, not overriding one another.
    But im curious on how to implement this in a good way, about when to start the conversation and when to close it.
    In my case, i have each CDI bean for each JSF page. And let's say that i have a menu, and when it's clicked, this will lead to page A, and from A, could lead to B, B could lead to C, C could lead to D, all these 4 pages are connected in one chain.
    Accessing A's bean properties from B or C or D beans is possible, accessing B's properties is also possible from C or D beans and so forth.
    Now im quite confused about :
    * whether all these A B C D should be in conversation scope or not, or perhaps just A ? Because i think sometimes from another page that is outside the ABCD chain, like a page F, it could navigate to page B, although i dont know how to supply the data to the bean B yet.
    * whether all these A B C D should be combined into one bean
    * where and when to start the conversation, im thinking about the constructor, but i dont think it's a good idea, because i prefer starting the conversation when first accessing the page, not the bean
    * where and when to stop the conversation, so that there wont be unused resources hanging around
    Regards,
    Albert Kam

    There are also some commandButtons on the view page, which performs actions on Product object, fetched by passed ID.

  • Building complex flash game in Flash Builder 4 - Workflow/Best Practices

    I'm investigating switching to Flash Builder 4 for building a complex game that currently lives purely inside Flash CS4.  CS4 is a pretty terrible source code editor and debugger.  It's also quite unstable.  Many crashes caused by bad behavior in the SWF will take out the entire IDE so are almost impossible to debug.  And I've heard other horror stories.  To be clear, for this project I'm not interested in the Flex API, just the IDE.
    Surprisingly, it seems Flash Builder 4 isn't really set up for this type of development.  I was hoping for an "Import FLA" option that would import my Document Class, set it as the main entry point, and figure out where other assets live and construct a new project.  What is the best workflow for developing a project like this?
    What I tried:
    -Create a new Actionscript Project in the same directory where my CS4  lives
    -Set the primary source file to match the original project's source file and location
    -Set my main FLA as "export to SWC", and added "SWC PATH" to my flash builder 4 project.
    -Compile and run.. received many errors due to references to stage instance. I changed these to GetChildByName("stagename").  Instead, should I declare them as members of the main class?  (this would mimic what flash CS4 does).
    -My project already streams in several external SWF's.  I set these to "Export SWC" to get compile-time access to classes and varaibles. This works fine in cs4, the loaded SWF's behave as if they were in the native project.  Is the same recommended with FB4?
    -Should I also be setting the primary FLA as "export to swc"?  If not, how do I reference it from flex, and how does flex know which fla it should construct the main stage with?
    Problems:
    -I'm getting a crash inside a class that is compiled in one of the external SWF's (with SWC).  I cannot see source code for the stack inside this class at all.  I CAN see member variables of the class, so symbol information exists.  And I do see the stack with correct function names.  I even see local variables and function parameters in the watch window! But no source.  Is this a known bug, or "by design"? Is there a workaround?  The class is compiled into the main project, but I still cannot see source.  If FLEX doesn't support source level debugging of SWC's, then it's pretty useless to me.   The project cannot live as a single SWF.  It needs to be streaming and modular for performance and also work flow. I can see source just fine when debugging the exact same SWC/SWF through CS4.
    -What is the expected workflow with artists/designers working on the project?  Currently they just have access to all the latest source, and to test changes they run right through flash.  Will they be required to license Flash Builder as well so they can test changes?  Or should I be distributing the main "engine" as a SWF, and having it reference other SWF files that artists can work on?  They they compile their SWF in CS4, and to test the game, they can load the SWF I distribute.
    A whitepaper on this would be awesome, since I think a lot of folks are trying to go this direction.  I spent a long time searching the web and there is quite a bit of confusion on this issue, and various hacks/tricks to make things work.  Most of the information is stale from old releases (AS2!).
    If a clean workflow I would happily adopt Flash Builder 4 as the new development tool for all the programmers.  It's a really impressive IDE with solid performance, functional intellisense, a rich and configurable interface, a responsive debugger..I could go on and on.  One request is shipping with "visual studio keyboard layout" for us C++ nerds.
    Thanks very much for reading this novel!

    Flash builder debugging is a go!  Boy, I feel a bit stupid, you nailed the problem Jason - I didn't have "Permit Debugging set".  I didn't catch it because debugging worked fine in CS4 because, well, CS4 doesn't obey this flag, even for externally loaded SWF files (I think as long as it has direct access to the SWC). Ugh.
    I can now run my entire, multi SWF, complex project through FB with minimal changes.  One question I do have:
    In order to instantiate stage instances and call the constructor of the document class, I currently load the SWF file with LoaderContext.  I'm not even exporting an SWC for the main FLA (though I may, to get better intellisense).  Is this the correct way of doing it?  Or should I be using , or some other method to pull it into flex?  They seem to do the same thing.
    The one awful part about this workflow is that since almost all of my code is currently tied to symbols, and lives in the SWF, any change i make to code must first be recompiled in CS4, then I have to switch back to FB.  I'm going to over time restructure the whole code base to remove the dependency of having library symbols derive from my own custom classes.  It's just a terrible work flow for both programmers and artists alike.  CS5 will make this better, but still not great.  Having a clean code base and abstracted away assets that hold no dependencies on the code  seems like the way to go with flash.  Realistically, in a complex project, artists/designers don't know how to correctly set up symbols to drive from classes anyway, it must be done by a programmer.  This will allow for tighter error checking and less guess work.  Any thoughts on this?
    Would love to beta test CS5 FYI seeing as it solves some of these issues.
    Date: Thu, 21 Jan 2010 15:06:07 -0700
    From: [email protected]
    To: [email protected]
    Subject: Building complex flash game in Flash Builder 4 - Workflow/Best Practices
    How are you launching the debug session from Flash Builder? Which SWF are you pointing to?
    Here's what I did:
    1) I imported your project (File > Import > General > Existing project...)
    2) Create a launch configuration (Run > Debug Configuration) as a Web Application pointing to the FlexSwcBug project
    3) In the launch config, under "URL or path to launch" I unchecked "use default" and selected the SWF you built (I assume from Flash Pro C:\Users\labuser\Documents\FLAs\FlexSwcBug\FlexSwcBugCopy\src\AdobeBugExample_M ain.swf)
    4) Running that SWF, I get a warning "SWF Not Compiled for Debugging"
    5) No problem here. I opened Flash Professional to re-publish the SWF with "Permit debugging" on
    6) Back In Flash Builder, I re-ran my launch configuration and I hit the breakpoint just fine
    It's possible that you launched the wrong SWF here. It looks like you setup DocumentClass as a runnable application. This creates a DocumentClass.swf in the bin-debug folder and by default, that's what Flash Builder will create a run config for. That's not the SWF you want.
    In AdobeBugExample_Main.swc, I don't see where classCrashExternal is defined. I see that classCrashMainExample is the class and symbol name for the blue pentagon. Flash Builder reads the SWC fine for me. I'm able to get code hinting for both classes in the SWC.
    Jason San Jose
    Quality Engineer, Flash Builder
    >

  • Best practices for connecting to DB

    Hi,
    I am having 3 different java classes which will contact the DB for getting the data from the table. I wrote a separate java class for DB connection like this :
    public class DBConnection {
    private Connection con;
    public Connection getConnection() {
    try {
    Class.forName("org.apache.derby.jdbc.ClientDriver");
    con = DriverManager.getConnection("jdbc:derby://localhost:1527/StrutsDB", "username", "password");
    } catch (SQLException ex) {
    Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
    Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
    return con;
    How to use this single connection object in all of the 3 classes? What are all the ways of doing so?
    Is there any best practices for connecting to DB?
    Thanks in advance,

    The problem with "best practice" is it really depends on your situation. If you are creating a single user, desktop application then what you are doing will work but would be more efficient if the connection was declared as static and you used the singleton pattern.
    public class DBConnection {
        private static final Connection con;
        private DBConnection() {
            try {
                Class.forName("org.apache.derby.jdbc.ClientDriver");
                con = DriverManager.getConnection("jdbc:derby://localhost:1527/StrutsDB", "username", "password");
            } catch (SQLException ex) {
                Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
        public static Connection getConnection() {
            return con.
    }The private constructor guarantees only one instance of the class will be created (since you can't use 'new' to create one) and initialized the database connection. Then any other object that require a connection simply call DBConnection.getConnection() and they will get the same database connection each time.
    Note that this is a little simplistic and is not thread safe. If your classes will be executing on different threads you will need a more sophisticated approach. You will also need to make sure you commit or rollback any transactions when done or the next time you get the connection you may be in the middle of an existing transaction.

  • Logical level in Fact tables - best practice

    Hi all,
    I am currently working on a complex OBIEE project/solution where I am going straight to the production tables, so the fact (and dimension) tables are pretty complex since I am using more sources in the logical tables to increase performance. Anyway, what I am many times struggling with is the Logical Levels (in Content tab) where the level of each dimension is to be set. In a star schema (one-to-many) this is pretty straight forward and easy to set up, but when the Business Model (and physical model) gets more complex I sometimes struggle with the aggregates - to get them work/appear with different dimensions. (Using the menu "More" - "Get levels" does not allways give the best solution......far from). I have some combinations of left- and right outer join as well, making it even more complicated for the BI server.
    For instance - I have about 10-12 different dimensions - should all of them allways be connected to each fact table? Either on Detail or Total level. I can see the use of the logical levels when using aggregate fact tables (on quarter, month etc.), but is it better just to skip the logical level setup when no aggregate tables are used? Sometimes it seems like that is the easiest approach...
    Does anyone have a best practice concerning this issue? I have googled for this but I haven't found anything good yet. Any ideas/articles are highly appreciated.

    Hi User,
    For instance - I have about 10-12 different dimensions - should all of them always be connected to each fact table? Either on Detail or Total level.It not necessary to connect to all dimensions completely based on the report that you are creating ,but as a best practice we should maintain all at Detail level only,when you are mentioning any join conditions in physical layer
    for example for the sales table if u want to report at ProductDimension.ProductnameLevel then u should use detail level else total level(at Product,employee level)
    Get Levels. (Available only for fact tables) Changes aggregation content. If joins do not exist between fact table sources and dimension table sources (for example, if the same physical table is in both sources), the aggregation content determined by the administration tool will not include the aggregation content of this dimension.
    Source admin guide(get level definition)
    thanks,
    Saichand.v

  • Best practices for setting up users on a small office network?

    Hello,
    I am setting up a small office and am wondering what the best practices/steps are to setup/manage the admin, user logins and sharing privileges for the below setup:
    Users: 5 users on new iMacs (x3) and upgraded G4s (x2)
    Video Editing Suite: Want to connect a new iMac and a Mac Pro, on an open login (multiple users)
    All machines are to be able to connect to the network, peripherals and external hard drive. Also, I would like to setup drop boxes as well to easily share files between the computers (I was thinking of using the external harddrive for this).
    Thank you,

    Hi,
    Thanks for your posting.
    When you install AD DS in the hub or staging site, disconnect the installed domain controller, and then ship the computer to the remote site, you are disconnecting a viable domain controller from the replication topology.
    For more and detail information, please refer to:
    Best Practices for Adding Domain Controllers in Remote Sites
    http://technet.microsoft.com/en-us/library/cc794962(v=ws.10).aspx
    Regards.
    Vivian Wang

Maybe you are looking for