Download presentation
Presentation is loading. Please wait.
1
OOP & JAVA
2
HelloWorld.java /** * The HelloWorld class is an application that * displays "Hello World!" to the standard output. */ public class HelloWorld { // Display "Hello World!" public static void main(String args[]) { System.out.println("Hello World!"); } Compile: C:\> javac HelloWorld.java Create java bytecode HelloWorld.class Run: C:\> java HelloWorld
3
HelloWorld.java (Applet) webpage.html HelloWorldApplet.java import java.applet.Applet; import java.awt.Graphics; /** * The HelloWorldApplet class demonstrates * compiling and running an applet within AppletViewer * or a Web browser * * Displays "Hello World!" */ public class HelloWorldApplet extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 50, 50); }
4
Definitions of OOP Class A class defines the abstract characteristics of a thing (object), including the thing's characteristics (its attributes or properties) and the things it can do (its behaviors or methods or features).methods For example, the class Dog would consist of traits shared by all dogs, for example breed, fur color, and the ability to bark.
5
Definitions of OOP Object The class of Dog defines all possible dogs by listing the characteristics that they can have; the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has brown-and-white fur. In programmer jargon, the object Lassie is an instance of the Dog class. The set of values of the attributes of a particular object is called its state. state
6
Definitions of OOP Method An object's abilities. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods. She may have other methods as well, for example sit() or eat(). Within the program, using a method should only affect one particular object; all Dogs can bark, but you need one particular dog to do the barking.
7
Definitions of OOP Message passing "The process by which an object sends data to another object or asks the other object to invoke a method."
8
Definitions of OOP Inheritance
9
Definitions of OOP Encapsulation Conceals the exact details of how a particular class works from objects that use its code or send messages to it. So, for example, the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume).
10
Definitions of OOP Polymorphism is the ability of behavior to vary based on the conditions in which the behavior is invoked, that is, two or more methods, as well as operators (such as +, -, *, among others) can fit to many different conditions. Ex. method signatures would be, respectively, very similar to add(int a, int b) and add(String a, String b). This is an example of Parametric Polymorphism. The returned type and used modifiers, of course, depend on the programmer interests and intentions.
11
JAVA basics http://leepoint.net/notes-java/index.html
12
Java’s Scope Scope is a term used to define where a variable is defined. EX. Function eat(){ int money=100; Print money; } Function buy(){ int money=200; Print money; } main(){ int money=0; eat(); buy(); Print money; }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.