1 / 23

Introduction to Java

Some Programming Languages Procedural - procedures produce a result from a set of inputs Object-Oriented - manipulates objects, provides graphical user interfaces ( GUIs) Java -1991- James Gosling (Sun Microsystems) Applications - stand alone programs

tanith
Download Presentation

Introduction to Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Some Programming Languages Procedural - procedures produce a result from a set of inputs Object-Oriented - manipulates objects, provides graphical user interfaces ( GUIs) Java -1991- James Gosling (Sun Microsystems) Applications - stand alone programs Applets - small program embedded in a web page Introduction to Java

  2. Figure 1.2: The Two Distinct Java Environments

  3. Figure 1.4:Flowchart Symbols

  4. Figure 1.5:Flowchart for Calculating the Average of Three Numbers

  5. Figure 1.8: The Traditional Translation Process Program Translation

  6. Figure 1.9:Compiling and Executing a Java Program Written by programmer

  7. Modular programs are easier to design, understand, debug and modify Modules are small segments or Java classes Classes are units that contain data structures and methods A Method contains a sequence of instructions (and in Java is constructed inside a class). Constructing a Java Program

  8. Figure 1.11: A Well-Designed ProgramIs Built Using Modules

  9. Give it a meaningful name or identifier or mnemonic. Java identifiers can be letters, digits, underscores(_), or $, but the first character must be a letter. A identifier cannot be a reserved (key) word. Method names begin with a lowercase letter. Class names always begin with a capital letter. Designing Methods

  10. Every Java program must have at least one class Class header contains: key word public or private key word class name of the class Body of the class is enclosed in { } JAVA Classes

  11. Header public static void main(String [ ] args) { “ body” } public - specifies scope static - specifies how the method is created and stored void - will not return any data arguments - type of data sent into the method Main Method

  12. These methods print data or arguments given to them on the screen or standard output device System.out is the standard output object System.out.println(“Hello world!”); print( ) - no new line println( ) - new line \n - escape sequence for new line The print() and println() methods

  13. A VERY Simple Java Program // This program prints a message to the user public class Hello { public static void main(String[ ] args) { System.out.print(“ Hello World!”); } //end of main method } //end of class

  14. Syntax - set of rules for grammatically correct statements Style- indentation, separate lines for different statements, comments, etc. Line comments //This is a comment Block comments /* This comment extends over several lines and gives the purpose of a method or program. */ Programming Syntax and Style

  15. Dialog Boxes • Java provides graphical components in the Swing package, known as javax.swing • Dialog boxes present a user with information and require a response ( such as clicking OK) • Modal box- user must respond and close it before continuing • Modeless- can continue without closing • JOptionPane.showMessageDialog(null, message, title, icon-type); • ( notice capitalization) • JOptionPane.showMessageDialog(null, “Hello World”, SAMPLE, JOptionPane.WARNING_MESSAGE);

  16. Figure 1.16a: showMessageDialog() Dialog Box:WARNING_MESSAGE

  17. Figure 1.16b:showMessageDialog() Dialog Box:QUESTION_MESSAGE

  18. Figure 1.16c:showMessageDialog() Dialog Box:INFORMATION_MESSAGE

  19. Figure 1.16d:showMessageDialog() Dialog Box:ERROR_MESSAGE

  20. Figure 1.16e:showMessageDialog() Dialog Box:PLAIN_MESSAGE

  21. Figure 1.17: The Dialog Produced by Program 1.5

  22. An Interactive Java Program import javax.swing.*; // used for graphics public class LuckyOne { public static void main(String[ ] args) { String s1, outMessage; double firstnum, secnum; s1 = JOptionPane.showInputDialog("Enter a number:"); firstnum = Double.parseDouble(s1); System.out.println(“ That’s my Lucky Number! \n”); } //end main System.exit(0); // closes program } //end class LuckyOne

  23. Must save program with same file name as class name Omitting braces and semicolons Misspelling Forgetting to close braces, parenthesis, quotes Common Programming Errors

More Related