Presentation is loading. Please wait.

Presentation is loading. Please wait.

Created by Ron Beglieter (based on the Java Tutorial) 1 What is Java? Java technology is both a programming language and a platform; Programming Language.

Similar presentations


Presentation on theme: "Created by Ron Beglieter (based on the Java Tutorial) 1 What is Java? Java technology is both a programming language and a platform; Programming Language."— Presentation transcript:

1 Created by Ron Beglieter (based on the Java Tutorial) 1 What is Java? Java technology is both a programming language and a platform; Programming Language : Modern high-level language (Simple, Architecture neutral, Object oriented, Portable, Distributed, High performance, Interpreted, Multithreaded, Robust, Dynamic, Secure) The Java programming language is unusual in that a program is both compiled and interpreted.

2 2 Java Programming Lang. “Write once, run anywhere” Generates byteCode Implementation of the Java Virtual Machine (JVM) Spec.

3 3 Java Platform The Java platform has two components: –The Java Virtual Machine (Java VM) –The Java Application Programming Interface (Java API)Java API

4 4 HelloWorld Application /** * The HelloWorldApp class implements an application that * simply displays "Hello World!" to the standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); }

5 5 Hello World App. (2) /** * The HelloWorldApp class implements an application that * simply displays "Hello World!" to the standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } class Bank { … } class Robber { … } Bank.javaRobber.java HelloWorldApp.java c:\app> javac HelloWorldApp.java c:\app> c:\app> javac HelloWorldApp.java c:\app> dir c:\app> javac HelloWorldApp.java c:\app> dir HelloWorldApp.java HelloWorldApp.class c:\app> javac HelloWorldApp.java c:\app> dir HelloWorldApp.java HelloWorldApp.class c:\app> java HelloWorldApp c:\app> javac HelloWorldApp.java c:\app> dir HelloWorldApp.java HelloWorldApp.class c:\app> java HelloWorldApp Hello World! c:\app>

6 6 Object Oriented Concepts What Is an Object? An object is a software bundle of related variables and methods. Software objects are often used to model real-world objects you find in everyday life. What Is a Message? Software objects interact and communicate with each other using messages. What Is a Class? A class is a blueprint or prototype that defines the variables and the methods common to all objects of a certain kind. What Is Inheritance? A class inherits state and behavior from its superclass. Inheritance provides a powerful and natural mechanism for organizing and structuring software programs. What Is an Interface? An interface is a contract in the form of a collection of method and constant declarations. When a class implements an interface, it promises to implement all of the methods declared in that interface.

7 7 An Example The following example demonstrates OOP (Object Oriented Programming) key concepts as well as the Java language basics 1.public class Spot { 2. public int size; 3. public int x, y; 4. public Spot(int intSize) { 5. size = intSize; 6. x = -1; 7. y = -1; 8. } 9.} Attributes Constructor

8 8 Example (continued) import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ClickMe extends JPanel implements MouseListener { private Spot spot = null; private static final int RADIUS = 7; public void init() { addMouseListener(this); } …. // full code is supplied “same” as #include

9 9 Example (continued) public class ClickMe extends JPanel implements MouseListener { … // the missing code is supplied public static void main(String args[]) { ClickMe clicker = new ClickMe(); clicker.init(); JFrame frame = new JFrame(); frame.getContentPane().add(clicker, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }

10 10 Example (continued) public void mousePressed(MouseEvent event) { if (spot == null) { spot = new Spot(RADIUS); } spot.x = event.getX(); spot.y = event.getY(); repaint(); }

11 11 Quiz Use the API documentation for the Java 2 Platform to answer these questions:API documentation The ClickMe application uses Color.red to set the drawing color to red. 1.What other colors can you get by name like this? 2.How would you specify other colors, like purple? Now, use what you learned from the Java API to make the following modifications to the ClickMe Program: (To compile this program, you also need the Spot.java file.) 1.Modify the application to draw a green square instead of a red spot. 2.Modify the application to display your name in purple instead of a red spot.

12 12 Summary – Java Class


Download ppt "Created by Ron Beglieter (based on the Java Tutorial) 1 What is Java? Java technology is both a programming language and a platform; Programming Language."

Similar presentations


Ads by Google