130 likes | 401 Views
OOP & JAVA. 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 !") ;
E N D
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
HelloWorld.java (Applet) webpage.html HelloWorldApplet.java
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). • For example, the class Dog would consist of traits shared by all dogs, for example breed, fur color, and the ability to bark.
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.
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.
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."
Definitions of OOP • Inheritance
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).
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.
JAVA basics • http://leepoint.net/notes-java/index.html
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; }