SlideServe
Menu
Préférences
© SlideServe · v2026

Standard Classes

garret avatar
9 diapositives · 230 Views · Jul 22, 2014

Dive into the foundational concepts of Java programming, focusing on objects, strings, and wrapper classes. Learn about object methods like `toString()` and `equals()`, and the significance of overriding these methods to define equality based on content rather than memory location. Explore immutable string objects, string manipulation methods, and the concept of autoboxing with wrapper classes like `Integer` and `Double`. This guide will also highlight essential Java API methods for enhanced functionality. Elevate your Java skills today!

Standard Classes - slide 1
01 / 9Standard Classes
1 / 17

Télécharger la présentation

Standard Classes
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Standard Classes

  2. Classes we will discuss • Object • String • Wrapper Classes • Double • Integer • Math

  3. 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

  4. 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”;

  5. 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()

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

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

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

  9. 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!!!!