18 March 2012

NetBeans 7 new features (edit)

NetBeans 7 is approved for release now. Here's a list of new features
  • Remote glassfish interaction
  • Java 7 support
    • string switch
    • enhanced try/catch
      • multicatch
      • catch(IOException | FileNotFoundException ex){...}
      • java.lang.AutoCloseable resources
    • java.nio.file: revamped file handling
    • literal enhancements:
      • binary numbers
      • int localhost=0b1111111000000000000000000000001;
      • underscores (for readability)
      • double million=2_000_000.00;
    • static java.util.Objects utilities, like
      • null tolerant equals/hashCode/toString
      • hash (Object... values)
    • CSS styled javadoc
  • Maven 3 support
  • HTML 5 support
  • JSON formatter
  • Git natively integrated
  • JUnit is now an unbundled plugin (Oracle legal had problems with the old CPL license)
  • easy JPA 2 metamodel generation
The netbeans 7.0/Glassfish 3.1 combination is still a bit flaky though.

      15 March 2012

      Java How To Program: alternate labs

      Chapter 2

      Preparation

      1. Make sure your PATH environment variable contains the JDK bin directory
        1. On windows separate PATH entries using ; (semicolon)

      Blogger Rijkswatch - Edit post - Mozilla Firefox_2012-03-14_21-40-17 - cropped

      Body Mass Index Calculator

      1. Using an editor create a file called BmiTest.java
      2. Add a public class called BmiTest to the file
      3. Add a main method to the BmiTest class. In the main method
        1. Ask the user for his weight in grams
        2. Ask the user for his height in centimeters
        3. Print the Body Mass Index of the user, using the formula

          BMI = weight x 10 / (height x height)

      4. Save the file
      5. Compile the file using the javac compiler
      6. Run the file using the java command
      7. Correct any errors.
      8. Compile, run and correct errors until all is well.

      Chapter 3

      Body Mass Index Calculator

      1. Create a new Java Application project called javase
        1. Consult the tutorial on creating a NetBeans Java project
          1. Do not create a main class
      2. In the project browser window, right click your project and select New => Java Class
        1. Call the class Bmi
      3. Add private double fields to the class called weight and height
      4. Add a constructor to the class
        1. constructor signature: public Bmi (double myWeight, double myHeight)
        2. In the constructor initialise the object fields using the constructor parameters
      5. Add a method that calculates the BMI
        1. Signature: public double calculate()
        2. In the method return the calculated bodymass. Adapt the calculation to use weight in kilogram and height in meters.
      6. Copy the BmiTest class to the project
      7. Modify the class to
        1. Request weight in kilogram and height in meters
        2. Accept floating point numbers
        3. Replace the calculation with
          1. Creation of a Bmi object called bmi
          2. Calculate the body mass index using the calculate() method on the  bmi object
      8. In the main method, print out the result of the calculation
      9. Run the main method by clicking on the green arrow button in the top toolbar
      10. Correct any errors and run again until all is well.

      Chapter 4

      Body Mass Index Calculator

      A normal BMI is between 18.5 and 24.9.

      1. In the BMI class add a method with signature: public double deviation()
        1. The method should return 0.0 if the BMI is within the normal range
        2. The method should return a negative number indicating the difference with 18.5 if the BMI is lower
        3. The method should return a positive number indicating the difference with 24.9 if the BMI is higher
      2. In the BmiTest main class
        1. print a message indicating that the weight is normal if the difference with the bounds is less than 0.1
        2. otherwise print a message indicating how much the weight should change to be within the normal range
      3. create a main class

      Chapter 5

      Facebook Growth Prediction

      In July 2010 facebook had 500 million users and was growing with a rate of 5% each month.

      Assume the  growth continues at this pace.

      Write a class called FacebookFuture with a main method that lists the number of users for each of the following months, until the number of users exceeds one billion. For each month print out a line with

      • an incrementing number indicating how many months this is from the start date
      • the month and year in a mm/yyyy format
      • the number of users

      Align numbers vertically in each line of output.

      Tip: since Java 7 you may use underscores in numbers to enhance readability. Example:

      long billion=1_000_000_000;

      Info: At the beginning of 2012 facebook numbered 850.000 users

      Chapter 6

      Facebook Growth Prediction

      To calculate the target amount you have after a number of months the formula is

      target = (1 + rate)months X amount

      To calculate the number of months it takes to the target amount, the formula is

      log(target/amount)/log(1+rate)=months

      1. Create a class GrowthPrediction. 
        1. Add an attribute for the current amount (double)
        2. Add a constructor that initializes the amount.
        3. Add a method with signature: public int growthCycles(double target, double rate).
      2. Create a test class called GrowthPredictionTest
        1. Right click the GrowthPrediction class and select Tools => Create JUnit Tests
          1. Accept all defaults
          2. Use JUnit 4
        2. In the testGrowthCycles method add a test that verifies the numbers you obtained in the previous excercise.
          1. Put the number of months obtained in the previous exercise in the expResult variable
          2. Remove the fail statement and the comment above it
          3. Print out a message saying how many months it would take for the number of facebook users to reach one billion
        3. Run the test using the top menu Run => test
        4. Using the same conditions add code to the test method to calculate how many months it would take for facebook to have as many users as a world population of 7_000_000_000
          1. Print out the result

      Chapter 7

      Game of Craps

      1. Make these modifications to the Craps code (Fig 6.9):
        1. Comment out all printing in the Craps class
        2. Make the number of rolls and the result attributes instead of local variables
        3. Add methods
          1. public int getRolls();
          2. public boolean getResult();
      2. Make these modifications to the CrapsTest class.
        1. Run the games for a number of times passed as a command like argument 
          • Run CrapsTest from the command line
          • If you run in netbeans, in the project pane, right click the project => properties => run and set the command line arguments
        2. Print out how many games were won and lost on the first, second,… , twentieth roll and after the twentieth roll.
        3. Print out the percentage of games won
        4. Print out the average number of rolls in a game

      Chapter 8

      Bank

      Implement the Bank case study.

      1. Put classes in two packages
        1. jhtp.bank
        2. jhtp.bank.atm
      2. Start with the classes at the right bottom of Fig 8.24 and work up
      3. Return dummy 0 equivalents from the methods to comply with the method return types
      4. Add attributes for the relations in Fig 8.25

      Cards

      1. Add two new enum classes to example 7.09:
        1. Face
        2. Suit
      2. Modify the example to use the enums
      3. Replace the decksize (52) with a number calculated from the available enums
      4. Run the test program and correct errors until it succeeds

      Chapter 9

      Bank

      1. Make the SavingsAccount from exercise 8.6 a subclass of the Account from the ATM case study.
      2. Replace the usage of the savingsBalance with getter/setter methods using the totalBalance of the Account class.
        1. Add the necessary support to the Account class
      3. Remove the savingsBalance attribute
      4. Test the modified savingsBalance using the SavingsAccount test and correct errors until it succeeds

      Javadoc

      1. Comment the bank classes, methods and attributes with javadoc
      2. In the project browser richt click on the project and select Generate javadoc
      3. Review the generated javadoc, adapt and regenerate
      4. Go to the files prowser tab and open the dist/javadoc directory where the javadoc is generated. Open the file stylesheet.css and append the contents of this file to it and save it. Reload the javadoc in another browser tab and check if anything changed in the presentation.

      Chapter 10

      Bank

      1. Add The Transaction class to the Bank exercise

      CommissionEmployee

      1. Start from the BasePlusCommissionEmployee code in example fig09_12_14
      2. BasePlusCommissionEmployee inherits from CommissionEmployee. We will replace inheritance with composition.
      3. Rename CommissionEmployee to CommissionOnlyEmployee
      4. Create an interface CommissionEmployee that contains the public methods of CommissionOnlyEmployee (except toString())
        1. In CommissionOnlyEmployee choose Refactor => Extract Interface
      5. Adapt BasePlusCommissionEmployee  to delegate to CommisionOnlyEmployee instead of inheriting from it
        1. Replace inheritance in BasePlusCommissionEmployee  with inplementation of the CommissionEmployee interface.
        2. Add an attribute CommissionOnlyEmployee called delegate to BasePlusCommissionEmployee 
        3. Instantiate the attribute in the constructor
        4. Replace all calls to super with calls to delegate
        5. implement all interface methods and call the corresponding method on delegate from them.

      Chapter 13

      Game Of Craps

      Add exception handling to handle bad program parameters to the CrapsTest class in the Game Of Craps from Chapter 7.

      Handle two specific exceptions using one catch statement:

      1. no command line parameter was supplied
      2. the command line parameter was not an integer

      Chapter 19

      FileMatch

      1. Rewrite exercise 14.8, this time loading all accounts in a Collection in memory.
      2. Make sure the output is still ordered by account number.

      14 March 2012

      NetBeans hints (edit)

      Your first NetBeans project
      1. On the start page click the Learn & Discover tab
      2. Under Demo's and Tutorials select Java SE applications
      3. Start the Java Quick Start Tutorial 
      Keyboard shortcuts
      • view, search (NB >= 6.7) & change shortcuts: tools => options => keymap
        • You can set the keymap to a profile from another IDE (Eclipse, IntelliJ...) here as well.
      • help => keyboard shortcuts card. The pdf that is shown, lives in
        netbeansInstallDir
        /nb/shortcuts.pdf. Some additional useful shortcuts:
        • CTRL SPACE: autocomplete popup (+ javadoc)
        • CTRL K: complete to recently typed word
        • CTRL click: go to definition
          • CTRL ALT click: go to implementation
        • CTRL –/+: fold/unfold code
        • CTRL ; => add semicolon at end of line
        • CTRL/ALT SHIFT F12: inspect members/hierarchy current selection
      Running code
      • After you ran a program, and corrected some errors Rerun using the >> buttons. Other buttons are Rerun with different parameters and Stop.







      • Similar options are available for (individual) tests.
        • You can also launch an individual test by  positioning the cursor in the method and selecting "Run focused test" from the right click menu.

      13 March 2012

      QR code shopping

      Uniway adds QR codes to TV shopping program.
      You can consult product info on your smartphone and get called by the call center to take your order.

      7 February 2012

      Java EE web technology version history (edit)


      JSR numbers are included as links

      Java EEservletJSPELJSTLJSFWhat’s new
      2.1
      1.0
      ServletContext, RequestDispatcher
      1.2
      2.2
      1.1
      war
      1.3
      53 2.3
      53 1.2
      filters
      1.4
      154 2.4
      152 2.0
      1.0
      52 1.1
      5
      2.5
      2.1
      2.1
      1.2
      127 1.2
      annotations
      6
      315 3.0
      2.2
      2.2
      1.2
      314 2.0
      asynchronous servlets more...
      7
      340 3.1
       341 3.0

      344 2.2
      HTML 5, 353 JSON 1.0

      Java EE component versions overview (edit)

      The table below lists the components in latest versions of the Java Enterprise Edition.

      • I put the most important changes in red.
      • Components with a (version number) between brackets are  proposed for removal in a future release.
        • JAX-WS is intended to replace JAX-RPC
      • An x indicates a technology is removed from the specification
        • JSR's are shown as hyperlinked numbers.
        • SE indicates that an API was moved to the standard edition 
          • eventually followed with the version number
        • Web front end technologies are in a separate table
        • I added some application servers at the bottom of the table. 
          • State of application servers with Java EE6 can be found here.
        Technologies151
        J2EE 1.4

        2003
        244
        Java EE5

        2006
        316
        Java EE6

        2009
        342
        Java EE7

        Q3 2012
        Java SE59 1.4176 5270 6336 7
        EJB153 2.1220 3.0318 3.1345 3.2
        Servlet/JSP2.42.53.03.1
        JMS 914 1.11.11.1343 2.0
        JTA 9071.01.1

        JavaMail 9191.31.41.4
        Connector (JCA)112 1.51.5322 1.6
        Java Activation Framework
        (JAF)
        925
        1.01.1SE:1.1.1
        Web Services 1091.11.21.3
        Web Services Metadata
        2.0SE
        JAX-RPC 1011.11.1(1.1)x
        JAX-WS 2241.02.0SE:2.1
        REST (JAX-RS)

        311 1.1339 2.0
        JAXB 222
        2.0SE:2.1
        JAXR (UDDI Registry)1.01.0(1.0)
        SOAP with attachments
        (SAAJ)
        67
        1.21.3SE
        StAX 173
        1.0SE
        JMX1.2SESE
        container authorisation (JACC) 1151.01.11.4
        container authentication (JASPIC) 196

        1.0
        Common annotations 250
        1.01.1
        Java Persistence (JPA)
        1.0317 2.0338 2.1
        Bean Validation

        303 1.0349 1.1
        Managed Beans

        1.0
        Interceptors

        1.1
        CDI for Java EE

        299 1.0346 1.1
        DI for Java 330

        1.01.1
        Concurrency utilities 236


        1.0
        JCache 107


        1.0
        State management 350


        1.0
        Batch processing 352


        1.0
        Servers
        Sun JSAS89.1
        Glassfish23 (12/2009)
        JBoss457 (7/2011)
        IBM Websphere678 (6/2011)
        Oracle Weblogic91012c(12/2011)
        Apache Geronimo123 (beta)
        • J2EE 1.3(2001) introduced
          • Message Driven  Beans
          • Local interfaces
        • Profiles are a subset of the spec.
          • Java EE6 Web profile (only profile currently defined)
            • contents
              • java SE
              • web technologies,
              •  JTA, common annotations, JPA, validation, managed beans, interceptors, CDI, DI
              • EJB Lite
                • Stateless, Stateful, and Singleton session beans
                • only local EJB interfaces or no interfaces
                • interceptors
                • security
                • transactions
                • No Message Driven, remote or asynchronous beans, no Timer service
            • implemented by
              • Resin 4
              • Apache TomEE 
          • Java EE7 Web profile will include JAX-RS

            30 January 2012

            Telesys opent bescheiden datacenter in Oudenaarde

            De foto in Datanews toont wat bedoeld wordt met bescheiden :













            Voeg daarbij een website met 404 links in het nieuws menu...
            Het motto van Telesys maakt alles duidelijk: