Programming In Any Language With “Hello, World!” Examples Dr. C. Floyd Richmond frichmond@icloud.com This presentation could be presented in an hour, or can outline an entire course on any programming language.
Elements of All Programs Variables – Declarations, Numbers, Strings, Boolean, Reserved Words Math – Operations, Comparisons Commands and Functions - Syntax, Data Structures, Input and Output Program Flow - Control Structures, Mains, Subroutines, Conditionals, Objects – buttons, text fields, images, sounds, video, menus, dialogs, alerts, draw Events – keyboard, mouse, touchpad, path hiearchy Input and Output – files, parsing data Tools - Installation, Writing Code, Loading Libraries, Compiling/Running, Debugging Errors
Variables and Reserved Words Variables are symbols (usually a letter, word, or phrase) which are assigned a value by the programmer (examples: A=4, numRight=numRight+1). They are used for saving changeable information for later use (reports, etc.). Reserved words are usually letters, words or phrases defined by the programming language, so they are not available as variables (example (in some languages): pi = 3.1416).
Variables - Declarations Some languages require the declaration of the type and value of a variable before it is used. Others create them as needed. Variables may be . . . Global (apply to the entire program – like long-term memory) or Local (apply to only portions of the program – like short term memory).
Variables - Types Numbers Strings Booleans
Variables - Numbers Categories Integers Real Numbers Precision
Variables - Strings Categories Characters Text Length
Variables - Booleans Categories True (1) False (0) In some languages may be used as numbers (as indicated above)
Variables - Arrays Some programs support arrays of variables (similar to a column in a spreadsheet), and double arrays (similar to a spreadsheet), and triple and higher arrays (like a three dimensional spreadsheet – a cube).
Variables - Arrays The data itself will suggest whether it should be organized into arrays. These operations must be mastered for effective use. Array Creation Array Assignment Array Reference Array Index
Math Operations Comparisons
Math - Operations Addition (3+4=7) Parentheses and order of operations (3+4)*5-2=? Subtraction (7-5=2) Power (2^2=4) Multiplication (3*3=9) Roots (8^(1/3)=2) Division (9/3=3) Modular math (5mod2=1) Equal (assignment) Rounding Random
Math - Comparisons Equal AND Not Equal OR Greater than NOT Less Than Is subset Is true Is false
Commands and Functions Execute instructions with given parameters May return success or failure of operation Functions Execute calculations with given parameters Returns the value of the calculation
Commands and Functions Built-in User-Defined
Program Flow Program Flow Control Structures – Main and Subroutines Conditionals (If then else, while, onErr)
Objects Links Internal External Creating, reading and setting values
Objects Buttons Creating, reading and setting values Radio Buttons Checkboxes Popup Options Creating, reading and setting values
Objects Text Boxes Creating, reading and setting values Single line Multiple line Creating, reading and setting values
Objects Menus Submenus Creating, reading and setting values
Objects Dialogs Alerts Creating, reading and setting values
Objects Types: Images, Videos, Sounds Operations: Preloading, Loading, Checking, Playing, Pausing, Stopping, Locating points, Moving to points, Replacing, Sequencing, Linking Creating, reading and setting values
Objects Drawing shapes Creating, reading and setting values
Events - Input and Output Keyboard Mouse Touchscreen
Files - Input and Output Parsing Data Text: characters, words, items, paragraphs Numbers (rounding and precision)
Files - Input and Output Saving Data Save file locally Save file on a server Upload to a service Save cookies
Tools Installation Writing Code Libraries Compiling/Running Debugging/Errors
Hello World Javascript PHP Visual Basic Python Java
Hello World - JavaScript <html><body> <script> alert( 'Hello, World!' ); </script> </body> </html> Copy and paste this text into a text editor and save it as helloworld.html. Open the saved file with a browser.
Hello World - PHP <html><body> <?php echo '<p>Hello, World!</p>'; ?> </body></html> Copy and paste this text into a text editor and save it as helloworld.html. Open the saved file with a browser.
Hello World – VisualBasic Module Hello Sub Main() MsgBox("Hello, World!") End Sub End Module Run VisualBasic in Windows. File>New Project. Copy and paste this code into the program area. Press play to run.
Hello World – Python print("Hello, World!") Run the terminal, type python, and at the prompt, type the command above and press return. Quit Python by typing quit and pressing return . . . OR . . . Copy and paste this text into a text editor and save it as helloworld.py. From the terminal, type python, then run ”helloworld.py” Quit Python by typing quit and pressing return.
Hello World – Java public class HelloWorld { } public static void main(String[] args) {System.out.println("Hello, World!"); } } Copy and paste this program into a text file, save it as helloworld.java. From the terminal, compile it by typing javac “helloworld.java” Execute it from the terminal by typing java helloworld.
Hello World – Swift (Apple iOS and OSX) labelText.text=“Hello, World!” Run Xcode and create single view application, click next, and save. Go to main.storyboard, create a label with no display name, Go to ViewController.swift, After “class ViewController: UIViewController {” . . . and before “}” . . . Control-drag from the label in the main.storyboard to the code area and name it labelText. Press return and enter the code above (labelText.text=“Hello, World!!”) Run as an iPhone or iPad app. For a similar but more sophisticated project see this link: Hello: https://youtu.be/HYQB_-YS6RE Calculator: https://youtu.be/AG2QDwmj64A Creating applications for OSX is exactly the same, but build for OSX instead.
Real World Examples By Floyd Richmond
Music Fundamentals Lessons http://floydrichmond.com/usetech/musicalflashcards/aaaindex.html
Saxophone Fingerings http://floydrichmond.com/classwork/annekramer/
Online Notation Proof of concept http://floydrichmond.com/notation
Programming In Any Language With “Hello, World!” Examples Dr. C. Floyd Richmond frichmond@icloud.com