| Version | Name | Release | Major new features |
| 25 (LTS) | 9/2025 | simplifications: top level methods, instance main, IO package module imports | |
| 16 | 3/2021 | record | |
| 15 | 9/2020 | Text blocks | |
| 14 | 3/2020 | Switch expressions | |
| 11 (LTS) | 9/2018 | Run (single file) source code | |
| 9 | 2016 | JSR 294: modular JDK (Jigsaw) Searchable javadoc | |
| 8 (LTS) | Spider | 3/2014 | JSR 335: lambda expressions Collections Stream Framework JSR 310: Date and Time API Compact profiles JSR 308: annotations outside declarations (on usage) |
| 7 | Dolphin | 7/2011 | language (project coin): switch on strings, multi catch, try with autoclosing resources, empty generics (diamond operator), binary literal, underscores in numbers NIO.2 file handling Fork/Join concurrency JAX-WS 2.2 (SOAP 1.2, WS-I 2.0, metro 2.0) |
| 6 | Mustang | 12/2006 | JSR 223: scripting language support JSR 224: JAX-WS2.0 (metro 1.x) JSR 221: JDBC 4 (driver autoloading)) Perfomance enhancements in synchronisation and garbage collection |
| 5 | Tiger | 9/2004 | language (JSR 201): Enumerations, autoboxing, enhanced for loop, static import, vararg JSR 175: Annotations JSR 14: Generics java.util.concurrent java.util.Scanner RMI automatic stub generation |
| 1.4 | Merlin | 2/2002 | language: assert regular expressions JSR 51: NIO JSR 47: java.util.logging JSR 54: JDBC 3 (metadata API, autogenerated keys, transaction savepoints, multiple || resultsets/statement) security and cryptography |
| 1.3 | Kestrel | 5/2000 | HotSpot JVM RMI/CORBA support JNDI |
| 1.2 | Playground | 12/1998 | Collections Swing JIT compiler Browser plugin JDBC 2.1 (datasources, distributed transactions, connection pooling,RowSet, ResultSet backscrolling and updating ) |
| 1.1 | 2/1997 | AWT events reorganisation inner classes JavaBeans JDBC RMI reflection | |
| 1.0 | 1/1996 |
Showing posts with label jhtp. Show all posts
Showing posts with label jhtp. Show all posts
22 November 2025
Java SE version history (updated)
Labels:
DWS-4050-EE6,
java,
jhtp
27 April 2016
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
NetBeans 7.4 Developer Guide
If you're searching how to do someting in netbeans just type it in the ... search box, it will not only search in your project, but also in the online help.
Keyboard shortcuts
- view, search & 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:
- Go to
- to definition: CTRL click
- to implementation: CTRL ALT click
- Edit
- Code completion
- autocomplete popup (+ javadoc): CTRL SPACE
- javadoc inline popup: CTRL SHIFT SPACE
- ALT F1 to see in browse
- Netbeans bundles plenty of javadoc you can browse supplied javadoc for your project libraries from help>Javadoc references
- complete to recently typed word: CTRL k
- Add semicolon at end of line: CTRL ;
- Add new line below + go there: SHIFT ENTER
- View
- fold/unfold code: CTRL –/+
- members/herarchy of current selection: CTRL/ALT SHIFT F12
- zoom: ALT + mousewheel up/down
- editor only: CTRL SHIFT ENTER (>= 7.4)
Running code
- After you ran a program, and corrected some errors Rerun using the >> buttons.
- The lighter double arrows below allow you to rerun with different parameters. You can change the arguments you run with in the Ant properties window.
- 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.
Samples
Netbeans comes with plenty of sample projects for you to explore
HTTP Monitor
The server side monitor is enabled by default for Tomcat and can be enabled in the properties of GlassFish. You may have to undeploy/redeploy your webapp for the monitor to show up.When the server receives an HTTP request, NetBeans will show a window with all request details. It extracts all parameters and stuff for you, but does not show the raw bodies of POST requests. It does not show responses either.
There is also a client monitor. If you use the internal browser (or the NetBeans Chrome plugin) you can use Window > Web > Network Monitor (NetBeans >= 7.4). It does not show all client side traffic but is targeted at in-page initiated traffic (AJAX, websockets) and failed requests.
Labels:
DWS-4050-EE6,
FJ-310,
jhtp,
netbeans,
patternsEE6,
SL-314-EE5,
SL-314-EE6,
SL-340-EE6,
SL-351-EE5,
SL-370-EE6
4 November 2013
A JUnit 4 Test class
package infotool;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class InfoModelTest {
private InfoModel instance;
@Before
public void setUp() {
instance = new InfoModel();
}
/**
* Test of getMessage method, of class InfoModel.
*/
@Test
public void testGetMessage() {
assertEquals("welcome to mvc", instance.getMessage());
}
/**
* Test of getWeather method, of class InfoModel.
*/
@Test
public void testGetWeather() {
assertEquals("Sunny", instance.getWeather());
}
/**
* Test of setMessage method, of class InfoModel.
*/
@Test
public void testSetMessage() {
String wthString = "JUnit @Rules";
instance.setMessage(wthString);
assertEquals(wthString, instance.getMessage());
}
/**
* Test of setWeather method, of class InfoModel.
*/
@Test
public void testSetWeather() {
String wthString = "It's going to rain";
instance.setWeather(wthString);
assertEquals(wthString, instance.getWeather());
}
/**
* Test of addModelChangeListener method, of class InfoModel.
*/
@Test
public void testAddModelChangeListener() {
InfoModel instance = new InfoModel();
InfoView view = new InfoViewTestSupport(instance);
instance.addModelChangeListener(view);
instance.setMessage("From testAddModelChangeListener");
assertTrue(((InfoViewTestSupport) view).getNotification());
}
}
1 November 2013
Java programming: extra labs
Lesson 3
Extra Practice 3-2, Task 3
Step e. Add a method addEmployees that adds multiple employeesLesson 4
Extra Practice 3-2: Equals method
- Add an equals method to the employee class
- Use employee id to test equality
- Make sure that it takes into account null values and references to other classes being passed in
- You can use ALT+INSERT in NetBeans to insert a sample equals method
- Test and correct until the code succeeds
- Modify the equality test to use the social security number
- Test and correct until the code runs correctly
Lesson 5
Extra Practice: Deck
- Start from the Deck lab from Java Funcamentals
- Replace the CardNames and CardValues arrays with enums Suit and Face
- Replace the decksize (52) with a number calculated from the available enums
- hint: using the values() method on your enum, returns an array of all values
- Test and correct the code until the program runs correctly
- Extend the Suit enums with the corresponding unicode characters
SPADES('\u2660'),CLUBS('\u2663'),DIAMONDS('\u2666'),HEARTS('\u2665'); - Extend the Face enum with numbers/names
ACE("Ace"), TWO("2"), THREE("3"), FOUR("4"), FIVE("5"), SIX("6"),SEVEN("7"), EIGHT("8"), NINE("9"), TEN("10"), JACK("Jack"), QUEEN("Queen"), KING("King"); - Modify the code to display the cards using the new data
- Test and correct the code until the program runs correctly
Lesson 7
Extra Practice: Couple
- Write a generic class Couple<S,T> that stores two values each with its own generic type
- Write a constructor without parameters and a constructor with two parameters
- Write getters and setters for each of the members
- Write a test, creating a Couple <Integer,String>
- Try to call getters and setters respecting the given types
- Try to call getters and setters that do not respect the given types
Extra practice: EmployeeDAOMapImpl
- Write an EmployeeDAOMapImpl for practice 6-2 using a Map as internal storage. Start from a copy of the EmployeeDAOMemoryImpl
- Have the factory return the EmployeeDAOMapImpl
- Test and correct until the program runs well
Lesson JUnit
practice DAO
- Add a reset() method to the EmployeeDAO from practice 6-2 that clears the employee storage
- Create a JUnit 4 testcase for the EmployeeDAO
- Right click on the class and select tools > create Tests
- The testcase is created in a dedicated test directory
- in which package does the testcase reside?
- Complete the generated testcase
- In the @BeforeClass method create the DAO object and store it in a static attribute
- In the @Before method, initialise the employee table with 3 records
- Hint: to make a Date object use Calendar cal = Calendar.getInstance();
// you can reuse the same cal object for multiple dates // set the date to januari 6th 2013
cal.set(2013, 0, 6);
Date d = cal.getTime(); - Write tests for all operations
- You may add a setter method to Employee for testing the update operation
- Right click the project and select Test (or press ALT+F6)
- Test until all tests succeed
Lesson 8
Extra practice: CSV changer
Write a unit test that replaces all blanks in a file by colons. Multiple blanks should be replaced by only one colon.
Labels:
jhtp
25 September 2013
Java fundamentals: extra labs
Lesson 6
Extra practice: Extend Customer Info
- Modify lab 6.1 to ask the user to enter the attributes of the customer
- Use java.util.Scanner to read the attributes
- Take care: after reading an int, you also need to read the return (newline) to advance to the next line of input
Lesson 7
Practice 7.1:
Modify the exercise to:- Use a java.util.Scanner to read the time of the day from the user input.
- Allow the user to use the format hh:mm:
Extra practice: Seasons
- Create a class Meteo with a method public String getSeason(String month)
- Implement the method and let it return the meteorological season for the month
- (e.g. for december to february return winter)
- Create a class MeteoTest
- Write a main method that
- Creates a Meteo object
- Asks the user for the name of a month
- Uses the Meteo object to get the corresponding season
- Prints out the season
- Run the test program and correct errors until it succeeds
- Modify the program to make it work no matter which case the user uses when entering the month.
- Run the test program and correct errors until it succeeds
Lesson 8
Extra practice: Deck
- Create a class Deck
- Initialise a cardNames array with the value of all cards (ace, two, three..., jack, queen, king)
- Initilise a cardSuites array with the suites of all cards (hearts, spades, clubs, diamonds)
- Create a method called printSize, which
- prints the number of cardValues
- prints the number of cardSuites
- prints the number of cards
- Create a class DeckTest
- Write a main method that
- Creates a Deck object
- Calls printSize on it
- Run the test program and correct errors until it succeeds
- Write a method drawCard, which prints the name of a random card (e.g. jack of spades)
- Hint: use Math.random()
- Draw two cards from the main method
- Run the test program and correct errors until it succeeds
Lesson 9
Extra practice: Dice
- Create a class DiceStat with a method public void printStat ()
- The method should roll 2 dice 10.000 times (Hint: use Math.random()
- Print the number of times each number was rolled
- Create a class DiceTest
- Write a main method that
- Creates a DiceStat object
- Calls printStat
- Run the test program and correct errors until it succeeds
- For each result, express as a percentage, how often it is thrown
- Run the test program and correct errors until it succeeds
Extra practice: Factorials
A factorial (n!) is the product of all numbers less than or equal to n. Example:
3!= 3*2*1
Create an application, called factor that will print the factorial of the number given as an argument to the application:
$ java FactorTest 3
3! = 6
Lesson10
Extra practice: Quiz
- Create a class Quiz with keywords and definitions.You can find the keywords and definitions here.
- Create a method with signature public boolean askQuestion()
- The method asks the user to give the keyword that corresponds to a randomly chosen definition
- The method compares the answer with the keyword
- The method informs the user about the correctness of the result.
- If the answer was wrong, it shows the correct keyword
- The method returns if the respons is correct
- Create a class QuizTest
- Write a main method that
- Creates a Quiz object
- Calls askQuestion
- Run the test program and correct errors until it succeeds
- Add a method with this signature public int askQuestions(int number)
- The method asks multiple questions
- The method returns the number of correct answers
- Call the method from the main class
- Run the test program and correct errors until it succeeds
- Add a method with this signature
- The method prints out your score percentage.
- The method prints out whether you passed the certification or not.
- The method returns a boolean with the pass result.
- Call the certify method from the main class
- Run the test program and correct errors until it succeeds
-
public boolean certify (int numberOfQuestions, int passPercentage)
Extra practice: Hypothenuse
The hypotenuse is the longest side in a right angled triangle. Pythagore's theorem states that the length of the hyothenuse (h) relates to the two other sides (x and y) as:
Write a program, using that calculates the hypothenus, using java's Math class:
$ java HypothenuseTest 2 3
Hypothenuse = 3.6
Lesson 11
Extra practice: Unique object ID's
- Modify the Rectangle class to assign a unique ID to each object that is created.
- Start the ID's at 1 and increment for each new object
- Print the rectangle ID in the creation message from the constructor
- Run the test program and correct errors until it succeeds
Extra practice: Deck
- Add a Card class to the Deck project
- Add a suit and value attribute and methods to retrieve them
- Add a Constructor
- Add a method that returns the card name (e.g. queen of hearts) with signature
- Add a constructor to the Deck class that generates a Deck of 52 cards.
- Modify the drawCard method to return a Card
- After calling drawCard, print out the card name from the main method.
Extra practice: Dice constructor
- Add a constructor to the DiceStat class that accepts the number of dies, the number of sides each dice has and the number of throws.
- Make the Deck class generic to work with these variables.
- Run the test program and correct errors until it succeeds
Lesson 12
Extra practice: Rectangle class hierarchy
- Make a class Square, that is a subclass of the Rectangle class.
- Add a Constructor that takes the side as an aargument
- Draw a square from the RetcangleTest main method
- Run the test program and correct errors until it succeeds
- Make rectangle a subclass of Shape. Make a class Shape with an abstract draw method.
- In Rectangle you can also use Refactor => extract interface
- Make a Triangle class that extends Shape (In the interface, you can press ALT+ENTER to generate a class that implements the interface)
- This class is a right angled triangle, with equal width and height. Example: *
- Implement the necessary methods
- Draw a triangle from the RetcangleTest main method
- Run the test program and correct errors until it succeeds
- Make a Canvas class, with a method with signature public void draw (List shapes)
- In the draw method loop over the list
- Assign the objects from the list to a Shape variable
- Draw each Shape
- In the main method of TestRectangle, create a Canvas
- Add a number of rectangles, Squares and triangles to an Arraylist.
- Call the draw method on the canvas, and pass the arraylist to it.
- Run the test program and correct errors until it succeeds
- Make a Parallellogram class that extends Shape (you can make a copy of the Rectangle class and name it Parallellogram to start)
- This class draws a parallellogram with a slope that indents one character: ****
- Implement the necessary methods
- In the main method of TestRectangle, add some paralellograms to the ArrayList
- Run the test program and correct errors until it succeeds
**
***
****
****
****
16 May 2012
Java 7 (Dolphin) new features (edit)
Now that Java 7 will soon become the default Java JRE version for download, let's have a look at some new features:
String switch
You can use a String as a selector for a switch/case statement nowEnhanced try/catch
- multicatch: catch multiple exceptions in one catch statement
try { ... }catch(IOException | FileNotFoundException ex){…} - resources implementing java.lang.AutoCloseable resources (most resources in the JDK) can be automatically closed in a try-with-resources. You do not need a finally clause for this anymore.
- Java 6 code
try { Scanner input = new Scanner (new File(“client.txt”)); … } finally { input.close(); } - Java 7 code
try(Scanner input = new Scanner (new File(“client.txt”))){ … } - You can also have multiple resources in a try
try(Scanner input = new Scanner (new File(“client.txt”)); Formatter output = new Formatter (new File(“adress.txt”)){ … }
- Java 6 code
NIO.2 revamped file handling
is discussed in a separate blog entry.Small syntax enhancements
- Diamond operator When the compiler can infer a generics type in a constructor, you can leave it empty
List<Currency> currencies= new ArrayList<> ();
// binary numbers int localhost=0b1111111000000000000000000000001; //underscores (for readability) double million=2_000_000.00;
static java.util.Objects utilities
Examples:- null tolerant equals/hashCode/toString
- hash (Object... values)
CSS styled javadoc
With Java 7 Oracle is starting to modernise javadoc. In this release javadoc is restyled:I'm not a big fan of the new look because the method names do not stand out enough for easy scanning the text for the method you need. Fortunatly the pages are styled using CSS. So I went to the topdirectory of the javadoc API and appended the contents of this file to stylesheet css, et voila:
The -stylesheetfile <path> option can be used to specify a stylesheet other than the default when using the javadoc command to generate the documentation.
Fork/Join
Fork/Join is an additional concurrent ExecutorService. It allows a pool of threads to concurrently work on a task, that can dynamically be split up into parallel subtasks. A busy thread is able to chew of a part of the task he’s doing and make it available for other threads.JDK7
This is not really part of the Java language, but some tools in the JDK were upgraded.JavaDB
JavaDB was updated to a more recent version of Apache Derby (10.8). Some noteworthy new features:- SQL Sequences
- In memory databases (with disk based backup/restore)
- SSL/TLS client/server communication
- role based authorisations
- stored procedures with elevated permissions
15 April 2012
Java enum demo
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public enum EnumDemo {
// For this enum each value has an identification code
// other than the internal ordinal value
DEMANDED(10),
SPECIFIED(20),
EVALUATED(30),
DUPLICATE(33),
ESTIMATED(35),
WORKAROUND (36),
ACCEPTED(37),
PLANNED(40),
BUSY(50),
IMPLEMENTED(60),
REJECTED(100);
private int code;
/**
* @param code constructor takes code to be associated with enum
*/
EnumDemo(int code) {
this.code = code;
}
/**
* Helper map for reverse lookup in getByCode method
*/
private static Map<Integer,EnumDemo> enumByCode;
static{
enumByCode = new HashMap<Integer, EnumDemo>();
for (EnumDemo val: EnumDemo.values()) {
enumByCode.put(val.getCode(),val);
}
}
public int getCode() {
return code;
}
/**
* reverse lookup
* @param code the code of the enum
* @return the enum or null if the code does not exist
*/
public static EnumDemo getByCode(int code){
return enumByCode.get(code);
}
/**
* test if a code exists
* @param code
* @return true if the code exists
*/
public static boolean isCodeValid(int code){
return enumByCode.containsKey(code);
}
/**
* enumToString: EnumDemo.DEMANDED to "DEMANDED"
* @return enum value name as a String
*/
public String getName(){
return toString();
}
/**
* StringToEnum: " demanded" to EnumDemo.DEMANDED
* @param name case insensitive and leading and trailing spaces are ignored
* @return the enum constant
*/
public static EnumDemo getByName(String name){
return EnumDemo.valueOf(name.trim().toUpperCase());
}
/**
* convert between enum and internal ordinal number
* not recommended to expose this, just here for demo purposes
* @return internal ordinal number of the constant
*/
public int getOrdinal(){
return getOrdinal();
}
/**
* convert from ordinal number to enum. Not recommended.
* @param ordinal
* @return the enum
*/
public static EnumDemo getByOrdinal(int ordinal){
return EnumDemo.values()[ordinal];
}
// some tests and subsets
// alternate methods can be written using the codes
/**
*
* @return is this enum in a range?
*/
public boolean isOK(){
return ACCEPTED.compareTo(this) <= 0 && IMPLEMENTED.compareTo(this) >= 0;
}
/**
* @return an enum subrange
*/
public static EnumSet<EnumDemo> getOK(){
return EnumSet.range(ACCEPTED,IMPLEMENTED);
}
/**
* @return is this enum in a subset?
*/
public boolean isNOK(){
return this == DUPLICATE
|| this == WORKAROUND
|| this == REJECTED;
}
/**
*
* @return get an enum subset
*/
public static EnumSet<EnumDemo> getNOK(){
return EnumSet.of(DUPLICATE,WORKAROUND,REJECTED);
}
}
Labels:
enum,
java,
jhtp,
patternsEE6,
SL-275
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
- 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
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
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 istarget = (1 + rate)months X amountTo 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 1: Collections
- Rewrite exercise 14.8, this time loading all accounts in a Collection in memory.
- Make sure the output is still ordered by account number.
FileMatch 2: ResourceBundles
Localise the messages in the application using resource bundles.- Pass a parameter to FileMatchTest indicating the language (fr or nl)
- In the main method construct a ResourceBundle with parameters
- “errormsg” as name for the properties files
- If the language was passed, a Locale for this language
- if no language was passed, use the one parameter constructor
- Pass the ResourceBundle to the FileMatch constructor and save it in an attribute
- Print errormessages using the ResourceBundle
- Use MessageFormat to substitute parameters in the message
- In the src directory create
- errormsg.properties (english)
- errormsg_fr.properties (french)
- errormsg_nl.properties (dutch)
- Add the keys used in the FileMatch error messages to all files and add translated messages in the three languages
Chapter 23
FileMatch
In this exercise we will process multiple transaction files concurrently.- Create a class bank.TransactionProcessor that implements Runnable
- Add a constructor TransactionProcessor(Map<Integer, Account> accounts, Path transactionFile)
- store the parameters in attributes.
- Implement the run method of TransactionProcessor. Move the code from FileMatch that reads the transaction file and adds the transaction amount to the corresponding accounts here. Adapt the code to use the instance attributes.
- Add a constructor TransactionProcessor(Map<Integer, Account> accounts, Path transactionFile)
- Make about 5 copies of the trans.txt file.
- Give them similar names so you can retrieve them using a wildcard.
- Adapt the FileMatch class
- Make the Account Collection synchronised to allow concurrent access.
- Read the oldmast.txt file and store all accounts in the Account Collection
- Create an ExecutorService cached trheadpool
- For each transaction file
- create a TransactionProcessor thread. Pass the Account collection and the file Path to it.
- execute the thread
- shutdown the threadpool and awaitTermination of all threads
- Write the updated Account Collection to the newmast.txt file.
- Add some System.out.println statements throughout your code to track the processing of the files
- Run the program and verify the results.
Chapter 30
FileMatch
Write a program that replaces the blank character separators in oldmast.txt with a colon (:) separator. A sequence of blank characters should be replaces with only one colon separator.7 November 2010
Java annotations primer (updated)
Slides: an introduction to annotations in Java.
Labels:
annotations,
FJ-310,
java,
jhtp,
SL-314-EE6,
SL-351-EE5
Subscribe to:
Posts (Atom)







