Sample Code from "Java How to Program, Fifth Edition" from Deitel and Deitel.
The following code gives to an example of a simple Java program.
Notice that the whole thing is a class, within it is a main function
Be sure to name your file the same as the class name
Welcome1.javaCompile with "javac Wecome1.java"
Run with "java Welcome1"
Another simple printing program with "print"
Welcome2.javaCompile and run as above except use "Welcome2"
Using "\n"
Welcome3.javaGraphical User Interface (GUI) example
Notice that we are making use of a predefined java class "JOptionPane", therefore, we "import javax.swing.JOptionPane"
Welcome4.javaGraphical User Interface (GUI) getting user input (showInputDialog) and printing out a message (showMessageDialog).
Addition.javaComparisons in Java
Comparison.javaBasic "Welcome to Java Applet". Notice:
Also need an html file:
WelcomeApplet.html (after clicking of this link "View" the "Source")Compile with "javac WelcomeApplet.java"
Run by opening .html file in browser or
"appletviewer WelcomeApplet.html
Drawing two strings at different locations.
x and y coordinates are (0,0) in the upper left-hand corner
WelcomeApplet2.java WelcomeApplet2.htmlDrawing lines
WelcomeLines.java WelcomeLines.htmlDrawing rectangles and getting input from user. Notice overriding "init" function. This does the initialization of two numbers.
"paint" draws the results.
AdditionApplet.java AdditionApplet.html