scribbledecobble
scribbledecobble.blogspot.com
Pages
Home
Contents
A
…
K
Hello, World!
README
See Also
MDN (Mozilla Developer Network)
Getting started with the web
HTML basics
CSS basics
JavaScript basics
Code
// :....1....:....2....:....3....:....4....:....5....:....6....:....7 /* HelloJava1: KISS (Keep It Simple Stupid) * * https://en.wikipedia.org/wiki/KISS_principle * https://en.wikipedia.org/wiki/%22Hello,_World!%22_program */ public class HelloJava1 { public static void main(String[] args) { System.out.print("Hello, World."); } }
public class HelloJava2 { public static void main(String[] args) { String greeting = Greeter.composeHelloWorld(); System.out.print(greeting); } } class Greeter { private static String compose(String greeting, String recipient) { return greeting + ", " + recipient; } public static String composeHello(String recipient, char endMark) { return compose("Hello", recipient) + endMark; } public static String composeHelloWorld(char endMark) { return composeHello("World", endMark); } public static String composeHelloWorld() { return composeHello("World", '.'); } }
public class HelloWorld { private static void greetUsing(OutputDevice dev) { dev.print("Hello, World."); } /* main Function */ public static void main(String[] args) { /* Variable Declaration * * Certain names will be used to refer * to values of particular types. */ OutputDevice lp0; OutputDevice lp1; OutputDevice lp2; /* Variable Initialization * * Set the initial value of a variable * equal to a value that is of a type that * corresponds to the variable's type. */ lp0 = new Printer(); lp1 = new LinePrinter(); lp2 = new LineNoPrinter(); greetUsing(lp0); greetUsing(lp1); greetUsing(lp2); greetUsing(lp2); greetUsing(lp2); } } interface OutputDevice { public void print(String text); } class Printer implements OutputDevice { public void print(String text) { System.out.print(text); } } class LinePrinter extends Printer { public void print(String text) { System.out.println(text); } } class LineNoPrinter implements OutputDevice { int lineNumber; Printer lp = new LinePrinter(); public LineNoPrinter(int start) { this.lineNumber = start; } public LineNoPrinter() { this(1); } public void print(String text) { this.printer.print(lineNumber + ": " + text); this.lineNumber++; } }
/* :....1....:....2....:....3....:....4....:....5....:....6....:....7 * * ThirdProgram: Introducing repetition. */ public class ThirdProgram { public static void main(String[] args) { OutputDevice lp0 = new Printer(); OutputDevice lp1 = new LinePrinter(); OutputDevice lp2 = new CustomPrinter('.'); OutputDevice lp3 = new CustomPrinter('!'); OutputDevice lp4 = new NewLinePrinter(); OutputDevice[] lp = { /* lp0, lp1, lp2, */ lp3 //, // lp4 }; for (OutputDevice lpr : lp) { lpr.print("Hello, World"); } int i; for (i = 0; i < lp.length; i++) { for (String name : args) { lp[i].print("Hi, " + name); } } while (i > 0) { i--; for (String name : args) { lp[i].print("Bye, " + name); } } } } interface OutputDevice { public void print(String text); } class Printer implements OutputDevice { public void print(String text) { System.out.print(text); } } class LinePrinter implements OutputDevice { public void print(String text) { System.out.println(text); } } class CustomPrinter implements OutputDevice { char lineTerminator; public CustomPrinter(char c) { this.lineTerminator = c; } public void print(String text) { System.out.print(text + lineTerminator); } } class NewLinePrinter extends CustomPrinter { public NewLinePrinter() { super('\n'); } }
/* :....1....:....2....:....3....:....4....:....5....:....6....:....7 * * FourthProgram: A real MESS! * * Mystically Evolving Scribbledecobbled Software */ public class FourthProgram { public static void main(String[] args) { System.out.print("Hello, World."); } } interface OutputDevice { public void print(String text); } class Printer implements OutputDevice { public void print(String text) { System.out.print(text); } } class LinePrinter implements OutputDevice { public void print(String text) { System.out.println(text); } } class GreetingProgram { private OutputDevice out; private String greeting; private String recipient; public GreetingProgram(String welcome, String name, OutputDevice dev) { this.out = dev; this.greeting = welcome; this.recipient = name; } public GreetingProgram(String welcome, String name) { this(welcome, name, new Printer()); } public GreetingProgram(String name) { this("Hello", name); } public GreetingProgram() { this("Hello", "World"); } public toString(char comma, char period) { return greeting + comma + " " + recipient + period; } public toString(char period) { return this.toString(',', period); } public toString() { return this.toString(',', '.'); } public void run() { this.out.print(this.toString()); } public void runWithGusto() { System.out.print(this.toString('!'); } } class HelloWorldProgram extends GreetingProgram { public HelloWorldProgram() { new HelloProgram("World"); } }
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World! in JavaScript
using window.alert
Hello, World! in JavaScript
using window.confirm
Hello, World! in JavaScript
using window.console.log
Newer Post
Older Post
Home