Example Name: HelloUser.java
Language: Java
Version: 1.0.0
Code:
package com.oreilly.frdg;
import java.util.*;
import java.text.SimpleDateFormat;
import java.io.Serializable;
public class HelloUser implements Serializable {
public HelloUser() { //constructor
message="";
}
private String message;
public String getMessage() {
return this.message;
}
public void setMessage(String username) {
this.message = "Hello " + username + ". It is " + getTime();
}
public String getTime() {
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
Date d = new Date();
return formatter.format(d);
}
public String sayHello(String username) {
this.setMessage(username);
return this.getMessage();
}
}
Download code text
Download chapter example files