standard classes n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Standard Classes PowerPoint Presentation
Download Presentation
Standard Classes

Loading in 2 Seconds...

play fullscreen
1 / 9

Standard Classes - PowerPoint PPT Presentation


  • 98 Views
  • Uploaded on

Standard Classes. Classes we will discuss. Object String Wrapper Classes Double Integer Math. Object. Superclass to all other classes Methods toString () equals()

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Standard Classes' - garret


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
classes we will discuss
Classes we will discuss
  • Object
  • String
  • Wrapper Classes
    • Double
    • Integer
  • Math
object
Object
  • Superclass to all other classes
  • Methods
    • toString()
    • equals()
      • Unless overridden, returns true if this object and other object are same object, false otherwise. By “same” here, we mean same memory location
      • What if we want two objects to be considered equal if their contents are the same? Let’s override! POLYMORPHISM – WOOT WOOT
      • Note:
        • default .equals() is same as ==
        • <, >, etc are not overridden in java. Must use .equals() and/or .compareTo() (Comparable interface, we’ll discuss more soon)
    • BankAccount.java
    • OrderedPair.java
  • Classes to write: BankAccount.java, OrderedPair.java, Client.java
string
String
  • A sequence of characters
  • Immutable objects – there are no methods to change them after they’ve been constructed
    • you can however create a new String which is a mutated version of an existing String
    • You can also reassign a String variable
      • String word = “abracadabra”;

word = “supercalifragilisticexpealidocious”;

string methods and operators
String methods and operators
  • Constructors
    • String name = “Mike”;
    • String name = new String(“Mike”);
  • Concatenation
    • String + String
    • String + primitive type
  • compareTo()
    • Compared lexicographically (think dictionary, or how files are sorted alphabetically)
    • Return value
  • int length()
  • String substring(intstartIndex)
  • String substring(intstartIndex, intendIndex)
  • intindexOf(String str)
  • intindexOf(char ch)
  • char charAt(int index)
  • boolean equals(Object o)
    • Look at ==
  • booleanequalsIgnoreCase(String s)
  • String[] split(String delim)
  • String toUpperCase()
  • String toLowerCase()
wrapper classes
Wrapper Classes
  • Takes existing object or primitive type and “wraps” or “boxes” it in an object
    • Provides new set of methods
  • Autoboxing – automatic conversion between primitive and corresponding reference type
  • Allows:
    • Construction of an object from a single value (wrapping/boxing)
    • Retrieval of primitive value (unwrapping/unboxing)
wrapper classes1
Wrapper Classes

Integer

Double

Double(double value)

double doubleValue()

intcompareTo(Object o)

boolean equals(Object o)

String toString()

  • Integer(int value) – boxing
  • intintValue() – unboxing
  • intcompareTo(Object o)
  • boolean equals(Object o)
    • Overrides Object’s equals method
    • Throws ClassCastException if o is not an Integer
  • String toString()
    • Returns String representation of the Integer
slide8
Math
  • static int abs(int x)
  • static double abs(double x)
  • static double pow(double base, double exp)
  • static double sqrt(double x)
  • static double random()
  • static double floor(double x)
  • static double ceil(double x)
  • static long round(double x)
slide9
Note
  • There are MANY other methods in the classes we discuss that may be of use to you. Feel free to explore these in the Java API!!!!