Quote of the Day


Quotes and sayings

Archives

Categories

  • 11Apr

    Item 1. Consider static factory methods instead of constructors.

    Advantages:

    1. One advantage of static factory methods is that, unlike constructors, they have names.
    2. They are not required to create new objects each time they are invoked. This allows immutable classes to use preconstructed instances, or to cache instances as they are constructed.
      Help to increase performance.
    3. Another advantage is that, unlike constructors, they can return an object of any subtype of their return type. This gives you flexibility in choosing the class of the returned object.
    4. They reduce the verbosity of creating parameterized type instances.

    Disadvantages:

    1. The main disadvantage of providing only static factory methods is that classes without public or protected constructors cannot be subclassed.
    2. They are not readily distinguishable from other static methods. Also they do not stand out in the API documentation as constructors do.

    Item 2. Consider a builder when faced with many constructor parameters.

    Static factories and constructors share a limitation: they do not scale well to large numbers of optional parameters.

    Alternative one:

    Traditionally, programmers have used the telescoping constructor pattern, in which you provide a constructor with only the required parameters, another with a single optional parameter, another with two optional parameters and so on, culminating in a constructor with all the optional parameters.
    The telescoping constructor pattern works, but it is hard to write client code when they are many parameters, and harder still to read it.

    Alternative two:

    JavaBeans pattern, in which you call a parameterless constructor to create the object and then call setter methods to set each required parameter and each optional parameter of interest.
    This pattern has none of the disadvantages of the telescoping constructor pattern. Unfortunately, the JavaBeans patter has serious disadvantages of its own. Because construction is split across multiple class, a JavaBean may be in an inconsistent state partway through its construction.

    Third alternative (the good one):

    Using the Builder pattern which combines the Telescoping pattern and the JavaBeans pattern. Instead of making the desired object directly, the client calls a constructor (or static factory) with all of the required parameters and gets a builder object. Then the client calls setter-like methods on the builder object to set each optional parameter of interest. Finally, the client calls a parameterless build method to generate the object, which is immutable. The builder is a static member class of the class it builds.
    The Builder pattern is more verbose than the telescoping constructor pattern, so it should be used only if there are enough parameters, say four or more (but you may want to add parameters in the future).
    In summary: The builder pattern is a good choice when designing classes whose constructors or static factories would have more than a handful of parameters.

    From Effective Java: http://java.sun.com/docs/books/effective/

    Tags: ,

  • 14Aug

    Technically, a portal is a container of resources and functionality that can be made available to end users through views. These portal are called desktops in WebLogic Portal.

    Benefits to the users:

    • Aggregation – From a simple page user can gradually get a page with multiple content and applications.
    • Customization – The user determines how the portal looks and feels.
    • Personalization – Specific content  according to the user’s interests and needs.
    • Organization – The user can arrange the content and applications to make better sense of the information.
    • Integration – The user can work with multiple applications and content sources in a unified fashion.

    Portals typical functionality:

    • Search – Enterprise and web-based search facilities
    • Content Management – Creation, management, and delivery of content
    • Content Repurposing – Including content from multiple disparate data sources

    Frequently, portals also include the following features and benefits:

    • Workflow – Business process management
    • Single Sign-On – Allows users to log on once for all applications within the portal

    For Weblogic Portal, you usually create the parts of a portal using Workshop (WebLogic IDE) and then you assemble it into a desktop using the WebLogic Portal Administration Console (WPAC). When you create a new portal using the WPAC, you are really creating an empty portal to hold different versions of the portal (desktops) that can be targeted to specific users.

    It is the desktops to which you add the portal resources and navigation such as books, pages, and portlets that make a dynamic portal.

    The next step is to complete the following tutorial:

    http://download.oracle.com/docs/cd/E13155_01/wlp/docs103/tutorials/index.html

    Tags: ,

  • 27May

    Today I started using EclEmma which is a free Java code coverage tool for Eclipse IDE.

    Basically it helps to identify the areas in your code that are (and are not) covered by a test case. This will help to improve the way you code and create JUnits.  You may become the one in your team with a 100% code coverage  :)

    More info here.

    Tags: , ,

  • 25Apr

    This happened to me some time ago but it can help someone else. At the time I had some troubles sending emails with SMTP and JavaMail. My code was based on the examples provided by chuidiang (The explanation in Spanish here, the Java code here). The code perfectly works with gmail (smtp.gmail.com), but not with our servers. In fact we couldn’t access the mail Server and got exceptions as:

    javax.mail.MessagingException: Could not connect to SMTP (smtp_host):(port)

    I asked to gaussmath and he gave me “a recipe” for testing whether we were seeing the mail server or not. I believe the next tips can be helpful to others.

    The basic idea to connect via telnet from our local box or the server where our application will be running to the SMTP host and execute the next tests:

    • Step-1-> Telnet (smtp_host) (port)
    • Step-2-> Helo (domain.com)
    • Step-3-> mail from: (fromMail@domain.com)
    • Step-4-> RCPT To:(toMail@domain2.com)
    • Step-5-> DATA
    • Step-6-> Test mails
    • Step-7-> .
    • Step-8-> quit

    Some other issues you should be aware are:

    1. Are you able to ping the SMTP host?
    2. Can you connect with Telnet to the SMTP host using port 25?
    3. Check firewall. Is it enabled/disabled? Is port 25 open?

    If you are working with Windows Vista and cannot execute Telnet, the reason is that Telnet is disabled by default. But you can enabled it. You can check the steps here for this.

    Tags: , , , ,

  • 13Apr

    What I did and what I didn’t like about certifications.  First of all, what are these things? Well it is a way to show “the world” (specially “recruiters” part of the world) that you are proved in certain area. My story about certifications it is not long but also not that short, currently I held 3 of them and more are in process.

    In order to get the certifications; I studied by my own for some of them and I attended to lessons for some others. What was the difference? Well! I took some lessons because I didn’t feel with enough knowledge to get the certification and even more I expected to learn something else from my classmates (and I did!).

    For example, SCJP, obtaining this one it was not an easy deal. I studied by myself during a month trying to understand the nuts and bolts of the Java language, it best reward was to practically became some sort of Java pre-compiler. That for sure helps a lot when coding :)

    Obtaining the CAPM was a totally different story! By that time I have some experience with “software project” terms but I was not an expert at all. So I decided to enroll for some lessons (well! It is also a requirement but I have done this even if it were not a requirement); the course last for 3 months and all I can say “It was awesome!”. I learned a lot from my classmates who have much more experience than me managing projects for all kind of companies bank, insurance, software and government.

    So what I like about the certifications? The process! You have to pass some days figuring out things, reading, learning and even meeting people (that in the future can become a job contact and/or a very good friend).

    What I didn’t like? Specially this happened with CAPM, I was disappointed when answering the exam I realize that almost everyone who had previously memorized the material (PMBOK) would be able to pass the exam. I not saying that certification doesn’t worth it, I am just saying that I expected that exam show more challenges than just memorize. 

    If you want some good reading material for Java certifications, you can check Javaranch also you can look for head first series books. For PMI certifications almost all you need it is in ther site (There is a Head First Book, but I haven’t read it). 

    I will talk about my experience about certifications and job market, later…

    See you,

    Buho

« Previous Entries   

Recent Comments

  • brilliant!! We need more of this....
  • Yes it definitely helps, after that I saw software projects ...
  • I didnt know about the CAPM until I read your post, so do yo...