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!
<!-- ....1....:....2....:....3....:....4....:....5....:....6....:... --> <!-- A "Hello, World!" program is a computer program that outputs or displays "Hello, World!" to a user. Being a very simple program in most programming languages, it is often used to illustrate the basic syntax of a programming language for a working program. It is often the very first program people write when they are new to a language. — https://en.wikipedia.org/wiki/%22Hello,_World!%22_program --> Hello, World!
<h1>Hello, World!</h1>
<!-- ....1....:....2....:....3....:....4....:....5....:....6....:... --> <!-- HTML (hypertext markup language) uses tags to annotate text. Typically, annotated text is surrounded by an opening tag and a closing tag, but in some cases an opening tag may appear without a corresponding closing tag. Most tags begin with a less-than character (<) and end with a greater-than character (>); in those cases, the closing tag looks just like the opening tag except for a forward slash (/) that appears immediately after the less-than character as shown, for example, in this closing h1 tag: </h1>. Comment tags are different. The text you are reading now is part of an HTML comment surrounded by comment tags. The opening HTML comment tag is a less-than symbol (<) followed by an exclamation mark (!) followed by two dashes (--). The closing HTML comment tag is two dashes (--) followed by a greater-than sign (>). The h1 tags (below) that appear in this HTML code snippet signify that the text between the opening and closing h1 tags should be treated as a level-1 heading, which is usually displayed as fairly large, bold characters. Exactly how tag are interpreted, however, may be customized, either by the author or the reader of the web page. The effect of HTML tags does not depend on whether the letters used in the tags are upper-case letters or lower-case. Most programmers who read HTML code, however, appreciate authors who always use either upper-case or lower-case letters consistently within a single HTML page or within a group of related pages. --> <h1>Hello, World!</h1>
<style> /* CSS (cascading style sheet) code appears between opening and * closing style tags. The following CSS code defines a rule that * says all text between h1 tags should be colored red. */ h1 { color: red; } </style> <h1>Hello, World!</h1>
<h1>Hello, World! in JavaScript</h1> <h2>using window.alert</h2> <script> /* JavaScript code appears between opening and closing script tags. * The following JavaScript code uses the alert method of an object * called window to display the text "Hello, World!" in a pop-up * window. */ window.alert("Hello, World!"); </script>
<h1>Hello, World! in JavaScript</h1> <h2>using window.confirm</h2> <script> /* The confirm method is very similar to alert. Can you spot some * differences? */ window.confirm("Hello, World!"); </script>
<h1>Hello, World! in JavaScript</h1> <h2>using window.console.log</h2> <script> /* In addition to the alert and confirm methods, the window object * contains another object called console, which contains a method * called log. The log method is quite a bit different from the * alert and confirm methods. Instead of displaying text in a pop-up * window, the log command writes text to special location that is * tucked away and hidden from most users. On many computers you can * find the "console" by pressing the F12 key. The appearance of the * console varies from web browser to web browser. Can you find it * on your computer? */ window.console.log("Hello, World!"); </script>
Newer Post
Older Post
Home