Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Java API

Similar presentations


Presentation on theme: "Introduction to Java API"— Presentation transcript:

1 Introduction to Java API
ATS Application Programming: Java Programming Introduction to Java API 5.1 Introduction to Java API Java API Specifications java.lang package Object class Class class System class String and StringBuffer classes Math class java.util package © Accenture All Rights Reserved Course Code #Z16325

2 ATS Application Programming: Java Programming
Objectives 5.1 Introduction to Java API Navigate the Java API Specifications Describe the java.lang package Explore fundamental classes in java.lang package: Object Class System String StringBuffer Math Describe the java.util package © Accenture All Rights Reserved Course Code #Z16325

3 Java API Specifications
ATS Application Programming: Java Programming Java API Specifications 5.1 Introduction to Java API List of Packages List of Classes Notes: The Java Application Programming Interface (API) is prewritten code, organized into packages of similar topics Official website: Package / Class Description © Accenture All Rights Reserved Course Code #Z16325

4 ATS Application Programming: Java Programming
java.lang package 5.1 Introduction to Java API java.lang provides classes that are fundamental to the design of the Java programming language. Object class, the root of the class hierarchy. Class class, represents classes at run time. Wrapper classes represent primitive types as objects. Math class provides mathematical functions. String and StringBuffer classes provide operations on strings. System classes provide system operations. Throwable class represents errors and exceptions. java.lang is implicitly imported in every Java source file. Notes: wrapper classes: Boolean, Character, Short, Integer, Long, Float, and Double System operations classes: ClassLoader, Process, Runtime, SecurityManager, and System © Accenture All Rights Reserved Course Code #Z16325

5 ATS Application Programming: Java Programming
Object class 5.1 Introduction to Java API Declaration: public class Object Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects inherit the methods of this class. Method Summary protected  Object clone()  boolean equals(Object obj) protected  void finalize()  Class<? extends Object> getClass()  int hashCode()  void notify() notifyAll()  String toString() wait() wait(long timeout) wait(long timeout, int nanos) For the definitions of the methods, please refer to Java API Specifications © Accenture All Rights Reserved Course Code #Z16325

6 ATS Application Programming: Java Programming
Class class 5.1 Introduction to Java API Declaration: public final class Class extends Object implements Serializable, GenericDeclaration, Type, AnnotatedElement Instances of the class Class represent classes and interfaces in a running Java application. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects. Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded in the class loader. For the definitions of the methods, please refer to Java API Specifications © Accenture All Rights Reserved Course Code #Z16325

7 ATS Application Programming: Java Programming
Class class 5.1 Introduction to Java API Method Summary (Partial List) static Class forName(String className)  Class[] getClasses()  Constructor[] getConstructors()  Field[] getFields() getInterfaces()  Method[] getMethods()  int getModifiers()  String getName()  Package getPackage() getSimpleName()  Class getSuperclass()  boolean isArray() isInstance(Object obj) isInterface() isLocalClass() isMemberClass() isPrimitive() For a complete list of methods, please refer to Java API Specifications © Accenture All Rights Reserved Course Code #Z16325

8 ATS Application Programming: Java Programming
System class 5.1 Introduction to Java API Declaration: public final class System extends Object The System class contains several useful class fields and methods which are related to the following operations: standard input, standard output, and error output streams. access to externally defined properties and environment variables. a means of loading files and libraries. and a utility method for quickly copying a portion of an array. For the definitions of the methods, please refer to Java API Specifications © Accenture All Rights Reserved Course Code #Z16325

9 ATS Application Programming: Java Programming
System class 5.1 Introduction to Java API Field Summary static PrintStream err static InputStream in out Method Summary (Partial List) static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) static String clearProperty(String key) static long currentTimeMillis() exit(int status) gc() static Map<String,String> getenv() getenv(String name) static Properties getProperties() . static SecurityManager getSecurityManager() load(String filename) nanoTime() runFinalization() runFinalizersOnExit(boolean value) setErr(PrintStream err) setIn(InputStream in) setOut(PrintStream out) setProperties(Properties props) setSecurityManager(SecurityManager s) For a complete list of methods, please refer to Java API Specifications © Accenture All Rights Reserved Course Code #Z16325

10 ATS Application Programming: Java Programming
String class 5.1 Introduction to Java API Declaration: public final class String extends Object implements Serializable, Comparable<String>, CharSequence The String class represents character strings. All string literals in Java programs are implemented as instances of this class. Strings are immutable, their values cannot be changed after they are created The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. For the definitions of the methods, please refer to Java API Specifications © Accenture All Rights Reserved Course Code #Z16325

11 ATS Application Programming: Java Programming
String class 5.1 Introduction to Java API Method Summary (Partial List)  char charAt(int index)  int compareTo(String anotherString)  String concat(String str)  boolean contains(CharSequence s) endsWith(String suffix) equals(Object anObject) static String format(String format, Object... args) hashCode() indexOf(int ch) length() matches(String regex) replace(char oldChar, char newChar)  String[] split(String regex) startsWith(String prefix) substring(int beginIndex) toLowerCase() toUpperCase() trim() Talking Points: The most common constructor simply takes another string (often a literal) as its argument, as follows: String myString = new String(“My new string”); OR String myString = “My new string”; You should be aware of what happens when you use a string literal in this manner: Every string literal is represented internally by an instance of String Java classes have a pool of such strings called String Constant Pool During compilation, the compiler adds an appropriate string to the pool, unless there is one already there (the literal has already been used in the class), in which case it reuses that © Accenture All Rights Reserved Course Code #Z16325

12 ATS Application Programming: Java Programming
StringBuffer class 5.1 Introduction to Java API Declaration: public final class StringBuffer extends Object implements Serializable, CharSequence StringBuffer is a thread-safe, mutable sequence of characters. A StringBuffer is like a String, but can be modified. StringBuffer class has been supplemented with an equivalent class designed for use by a single thread, StringBuilder. The StringBuilder class should generally be used in preference to StringBuffer as it supports all of the same operations but is faster as it performs no synchronization. For the definitions of the methods, please refer to Java API Specifications © Accenture All Rights Reserved Course Code #Z16325

13 ATS Application Programming: Java Programming
StringBuffer class 5.1 Introduction to Java API Method Summary (Partial List)  StringBuffer append(String str) append(StringBuffer sb)  int capacity()  char charAt(int index) delete(int start, int end) deleteCharAt(int index) indexOf(String str) insert(int offset, String str) lastIndexOf(String str) length() replace(int start, int end, String str) reverse()  void setCharAt(int index, char ch) setLength(int newLength)  String substring(int start) substring(int start, int end) toString() trimToSize() A StringBuffer object represents a string that can be dynamically modified Its three constructors are: StringBuffer() – creates an empty buffer StringBuffer(int capacity) – creates an empty buffer of the length specified StringBuffer(String initial) – creates a buffer initially populated with the specified string One of the properties of a StringBuffer is its capacity, which is the maximum length string it can contain without needing more memory – However, it can grow beyond this capacity as and when required so it is not necessary to worry about it. Faculty Notes: StringBuffer needs more memory than String, but if many operations are being performed, StringBuffer takes less memory than the many Strings that would be the byproduct when still using String © Accenture All Rights Reserved Course Code #Z16325

14 ATS Application Programming: Java Programming
Math class 5.1 Introduction to Java API Declaration: public final class Math extends Object Math class contains methods for performing basic numeric operations such as elementary exponential, logarithm, square root, and trigonometric functions. Math class cannot be extended (it is declared final) nor instantiated (its constructor is private). Its methods are declared static and can be invoked using its class name. Faculty note: © Accenture All Rights Reserved Course Code #Z16325

15 ATS Application Programming: Java Programming
Math class 5.1 Introduction to Java API Method Summary (Partial List) static double abs(double a) ceil(double a) cos(double a) exp(double a) floor(double a) log(double a) log10(double a) log1p(double x) max(double a, double b) min(double a, double b) pow(double a, double b) random() static long round(double a) sin(double a) sqrt(double a) tan(double a) toDegrees(double angrad) toRadians(double angdeg) Field Summary static double E PI Talking Points: A StringBuffer object represents a string that can be dynamically modified Its three constructors are: StringBuffer() – creates an empty buffer StringBuffer(int capacity) – creates an empty buffer of the length specified StringBuffer(String initial) – creates a buffer initially populated with the specified string One of the properties of a StringBuffer is its capacity, which is the maximum length string it can contain without needing more memory – however, as it can grow beyond this capacity as and when required, it is not necessary to worry about it Faculty Notes: StringBuffer needs more memory than String, but if many operations are being performed, StringBuffer takes less memory than the many Strings that would be the byproduct when still using String © Accenture All Rights Reserved Course Code #Z16325

16 ATS Application Programming: Java Programming
Wrapper Classes 5.1 Introduction to Java API The wrapper classes serve two primary purposes: To provide a mechanism to "wrap" primitive values in an object so that the primitives can be included in activities reserved for objects, such as being added to collections, or returned from a method with an object return value. To provide an assortment of utility functions for primitives. Most of these functions are related to various conversions: converting primitives to and from String objects, and converting primitives and String objects to and from different bases (or radix), such as binary, octal, and hexadecimal. Faculty Notes: Describe the significance of wrapper classes, including making appropriate selections in the wrapper classes to suit specified behavior requirements, stating the result of executing a fragment of code that includes an instance of one of the wraper classes, and writing code using the following methods of wrapper classes (e.g. Integer, Double, etc.): doubleValue, floatValue, intValue, longValue, parseXxx, getXxx, toString, toHexString. © Accenture All Rights Reserved Course Code #Z16325

17 Wrapper Classes Constructors
ATS Application Programming: Java Programming Wrapper Classes Constructors 5.1 Introduction to Java API short or String Short short long or String Long long int or String Integer int float, double, or String Float float double or String Double double char Character byte of String Byte byte boolean or String or null Boolean boolean Constructor Arguments Wrapper Class Primitive Faculty Notes: Wrapper classes is one of the features of Java that complies with Object Oriented Programming. Primitive data types can be encapsulated and manipulated using these Wrapper Classes. © Accenture All Rights Reserved Course Code #Z16325

18 ATS Application Programming: Java Programming
java.util package 5.1 Introduction to Java API Contains classes related to the following: Collections framework Legacy collection classes Event model Date and time facilities Internationalization Miscellaneous utility classes StringTokenizer, random-number generator, and bit array © Accenture All Rights Reserved Course Code #Z16325

19 ATS Application Programming: Java Programming
Key Points 5.1 Introduction to Java API The Java API is prewritten code organized into packages of similar topics java.lang provides classes that are fundamental to the design of the Java programming language java.lang contains the following classes: Object, Class, Math, String, StringBuffer, Throwable,Wrapper classes and System classes java.lang package is implicitly imported in every Java source file Object is the superclass of all classes String objects are immutable java.util contains classes related to the following: Collections framework Legacy collection classes Event model Date and time facilities Internationalization Miscellaneous utility classes © Accenture All Rights Reserved Course Code #Z16325


Download ppt "Introduction to Java API"

Similar presentations


Ads by Google