- 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
18 March 2012
NetBeans 7 new features (edit)
15 March 2012
Java How To Program: alternate labs
Chapter 2
Preparation
- Make sure your PATH environment variable contains the JDK bin directory
- On windows separate PATH entries using ; (semicolon)
Body Mass Index Calculator
- Using an editor create a file called BmiTest.java
- Add a public class called BmiTest to the file
- Add a main method to the BmiTest class. In the main method
- Ask the user for his weight in grams
- Ask the user for his height in centimeters
- Print the Body Mass Index of the user, using the formula
BMI = weight x 10 / (height x height)
- Save the file
- Compile the file using the javac compiler
- Run the file using the java command
- Correct any errors.
- Compile, run and correct errors until all is well.
Chapter 3
Body Mass Index Calculator
- Create a new Java Application project called javase
- Consult the tutorial on creating a NetBeans Java project
- Do not create a main class
- Consult the tutorial on creating a NetBeans Java project
- In the project browser window, right click your project and select New => Java Class
- Call the class Bmi
- Add private double fields to the class called weight and height
- Add a constructor to the class
- constructor signature: public Bmi (double myWeight, double myHeight)
- In the constructor initialise the object fields using the constructor parameters
- Add a method that calculates the BMI
- Signature: public double calculate()
- In the method return the calculated bodymass. Adapt the calculation to use weight in kilogram and height in meters.
- Copy the BmiTest class to the project
- Modify the class to
- Request weight in kilogram and height in meters
- Accept floating point numbers
- Replace the calculation with
- Creation of a Bmi object called bmi
- Calculate the body mass index using the calculate() method on the bmi object
- In the main method, print out the result of the calculation
- Run the main method by clicking on the green arrow button in the top toolbar
- 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.
- In the BMI class add a method with signature: public double deviation()
- The method should return 0.0 if the BMI is within the normal range
- The method should return a negative number indicating the difference with 18.5 if the BMI is lower
- The method should return a positive number indicating the difference with 24.9 if the BMI is higher
- In the BmiTest main class
- print a message indicating that the weight is normal if the difference with the bounds is less than 0.1
- otherwise print a message indicating how much the weight should change to be within the normal range
- 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
- Create a class GrowthPrediction.
- Add an attribute for the current amount (double)
- Add a constructor that initializes the amount.
- Add a method with signature: public int growthCycles(double target, double rate).
- Create a test class called GrowthPredictionTest
- Right click the GrowthPrediction class and select Tools => Create JUnit Tests
- Accept all defaults
- Use JUnit 4
- In the testGrowthCycles method add a test that verifies the numbers you obtained in the previous excercise.
- Put the number of months obtained in the previous exercise in the expResult variable
- Remove the fail statement and the comment above it
- Print out a message saying how many months it would take for the number of facebook users to reach one billion
- Run the test using the top menu Run => test
- 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
- Print out the result
- Right click the GrowthPrediction class and select Tools => Create JUnit Tests
Chapter 7
Game of Craps
- Make these modifications to the Craps code (Fig 6.9):
- Comment out all printing in the Craps class
- Make the number of rolls and the result attributes instead of local variables
- Add methods
- public int getRolls();
- public boolean getResult();
- Make these modifications to the CrapsTest class.
- 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
- Print out how many games were won and lost on the first, second,… , twentieth roll and after the twentieth roll.
- Print out the percentage of games won
- Print out the average number of rolls in a game
- Run the games for a number of times passed as a command like argument
Chapter 8
Bank
Implement the Bank case study.
- Put classes in two packages
- jhtp.bank
- jhtp.bank.atm
- Start with the classes at the right bottom of Fig 8.24 and work up
- Return dummy 0 equivalents from the methods to comply with the method return types
- Add attributes for the relations in Fig 8.25
Cards
- Add two new enum classes to example 7.09:
- Face
- Suit
- Modify the example to use the enums
- Replace the decksize (52) with a number calculated from the available enums
- Run the test program and correct errors until it succeeds
Chapter 9
Bank
- Make the SavingsAccount from exercise 8.6 a subclass of the Account from the ATM case study.
- Replace the usage of the savingsBalance with getter/setter methods using the totalBalance of the Account class.
- Add the necessary support to the Account class
- Remove the savingsBalance attribute
- Test the modified savingsBalance using the SavingsAccount test and correct errors until it succeeds
Javadoc
- Comment the bank classes, methods and attributes with javadoc
- In the project browser richt click on the project and select Generate javadoc
- Review the generated javadoc, adapt and regenerate
- 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
- Add The Transaction class to the Bank exercise
CommissionEmployee
- Start from the BasePlusCommissionEmployee code in example fig09_12_14
- BasePlusCommissionEmployee inherits from CommissionEmployee. We will replace inheritance with composition.
- Rename CommissionEmployee to CommissionOnlyEmployee
- Create an interface CommissionEmployee that contains the public methods of CommissionOnlyEmployee (except toString())
- In CommissionOnlyEmployee choose Refactor => Extract Interface
- Adapt BasePlusCommissionEmployee to delegate to CommisionOnlyEmployee instead of inheriting from it
- Replace inheritance in BasePlusCommissionEmployee with inplementation of the CommissionEmployee interface.
- Add an attribute CommissionOnlyEmployee called delegate to BasePlusCommissionEmployee
- Instantiate the attribute in the constructor
- Replace all calls to super with calls to delegate
- 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:
- no command line parameter was supplied
- the command line parameter was not an integer
Chapter 19
FileMatch
- Rewrite exercise 14.8, this time loading all accounts in a Collection in memory.
- Make sure the output is still ordered by account number.
14 March 2012
NetBeans hints (edit)
Your first NetBeans project
- On the start page click the Learn & Discover tab
- Under Demo's and Tutorials select Java SE applications
- 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 EE | servlet | JSP | EL | JSTL | JSF | What’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.
| Technologies | 151 J2EE 1.4 2003 | 244 Java EE5 2006 | 316 Java EE6 2009 | 342 Java EE7 Q3 2012 |
| Java SE | 59 1.4 | 176 5 | 270 6 | 336 7 |
| EJB | 153 2.1 | 220 3.0 | 318 3.1 | 345 3.2 |
| Servlet/JSP | 2.4 | 2.5 | 3.0 | 3.1 |
| JMS | 914 1.1 | 1.1 | 1.1 | 343 2.0 |
| JTA 907 | 1.0 | 1.1 | ||
| JavaMail 919 | 1.3 | 1.4 | 1.4 | |
| Connector (JCA) | 112 1.5 | 1.5 | 322 1.6 | |
| Java Activation Framework (JAF) 925 | 1.0 | 1.1 | SE:1.1.1 | |
| Web Services 109 | 1.1 | 1.2 | 1.3 | |
| Web Services Metadata | 2.0 | SE | ||
| JAX-RPC 101 | 1.1 | 1.1 | (1.1) | x |
| JAX-WS 224 | 1.0 | 2.0 | SE:2.1 | |
| REST (JAX-RS) | 311 1.1 | 339 2.0 | ||
| JAXB 222 | 2.0 | SE:2.1 | ||
| JAXR (UDDI Registry) | 1.0 | 1.0 | (1.0) | |
| SOAP with attachments (SAAJ) 67 | 1.2 | 1.3 | SE | |
| StAX 173 | 1.0 | SE | ||
| JMX | 1.2 | SE | SE | |
| container authorisation (JACC) 115 | 1.0 | 1.1 | 1.4 | |
| container authentication (JASPIC) 196 | 1.0 | |||
| Common annotations 250 | 1.0 | 1.1 | ||
| Java Persistence (JPA) | 1.0 | 317 2.0 | 338 2.1 | |
| Bean Validation | 303 1.0 | 349 1.1 | ||
| Managed Beans | 1.0 | |||
| Interceptors | 1.1 | |||
| CDI for Java EE | 299 1.0 | 346 1.1 | ||
| DI for Java 330 | 1.0 | 1.1 | ||
| Concurrency utilities 236 | 1.0 | |||
| JCache 107 | 1.0 | |||
| State management 350 | 1.0 | |||
| Batch processing 352 | 1.0 | |||
| Servers | ||||
| Sun JSAS | 8 | 9.1 | ||
| Glassfish | 2 | 3 (12/2009) | ||
| JBoss | 4 | 5 | 7 (7/2011) | |
| IBM Websphere | 6 | 7 | 8 (6/2011) | |
| Oracle Weblogic | 9 | 10 | 12c(12/2011) | |
| Apache Geronimo | 1 | 2 | 3 (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:



