Download presentation
Presentation is loading. Please wait.
Published byCynthia Mosley Modified over 6 years ago
1
A Java Program: // Fig. 2.1: Welcome1.java // Text-printing program.
public class Welcome1 { // main method begins execution of Java application public static void main( String args[] ) { System.out.print ("Hello " ); System.out.println(" World! "); System.out.println( "Welcome to Java Programming!" ); } // end method main } // end class Welcome1 /********************************************************* *(C) Copyright by Deitel & Associates, Inc. and * * Prentice Hall. All Rights Reserved * **********************************************************/
2
Escape sequence: // Escape sequence public class Welcome1 {
// main method begins execution of Java application public static void main( String args[] ) { System.out.print ("Hello World!\nWelcome "); System.out.print ( "to Java Programming!\n" ); } // end method main } // end class Welcome1 /********************************************************* \n \t \\ \“ \r **********************************************************/
3
Package: collection of classes
// Java API: Java Application Programming Interface // (java., javax.) // GUI: Graphical User Interface // // using swing package, JOptionPane class // showMessageDialog method import javax.swing.JOptionPane; public class TestPane{ public static void main(String args[]){ JOptionPane.showMessageDialog( null, "Welcome\nTo\nswing\nPackage"); System.exit(0); }
4
A Java program package classes methods arguments Variable declaration
import javax.swing.JOptionPane; public class time{ public static void main(String args[]){ int x,y,z; String X,Y; X = JOptionPane.showInputDialog("Input x"); Y = JOptionPane.showInputDialog("Input y"); x = Integer.parseInt(X); y = Integer.parseInt(Y); z = x*y; JOptionPane.showMessageDialog( null, x + " * " + y + " = " + z, "The product of " + x + " and " + y, JOptionPane.PLAIN_MESSAGE ); System.exit(0); } Variable declaration classes methods arguments
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.