A Cold Cup o' Joe, by Guy Rish
Listing 1
public class HelloWorld
{
public String greeting()
{
return(new String("Hello, World"));
}
public String greeting(String whom)
{
return(new String("Hello, " + whom));
}
}
Listing 2
public class Hello
{
public static final String DEFAULT_STYLE =
"Hello";
protected String m_style;
public Hello()
{
this(DEFAULT_STYLE);
}
public Hello(String style)
{
m_style = style;
}
public String getStyle()
{
return(m_style);
}
public void setStyle(String style)
{
m_style = style;
}
public String greeting()
{
return(new String(m_style + ", World"));
}
public String greeting(String whom)
{
return(new String(m_style + ", " + whom));
}
}
Listing 3
1. <HTML>
2. <HEAD><TITLE>Listing 5</TITLE></HEAD>
3.
4. <BODY>
5.
6. <cfscript>
7. hw1 = CreateObject("java", "Hello");
8.
9.
WriteOutput("<h2>Basic Greetings</h2>");
10.
WriteOutput(hw1.greeting());
11.
WriteOutput("<br>");
12.
WriteOutput(hw1.greeting("Mr. Rish"));
13.
14.
hw2 = CreateObject("java", "Hello");
15.
16.
WriteOutput("<h2>Displaying a static member</h2>");
17.
WriteOutput(hw2.DEFAULT_STYLE);
18.
19.
hw2.init("Yo");
20.
21.
WriteOutput("<h2>Alternate Greetings</h2>");
22.
WriteOutput(hw2.greeting());
23.
WriteOutput("<br>");
24.
WriteOutput(hw2.greeting("Dude"));
25. </cfscript>
26.
27. </BODY>
28. </HTML>