1 / 12

OOP & JAVA

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 !") ;

lizina
Télécharger la présentation

OOP & 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. 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

  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). • 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.

  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; }

More Related