Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java 3 More Java Then Java. Libraries & Packages Java standard class library is composed of useful classes that help us to achieve our programming goals.

Similar presentations


Presentation on theme: "Java 3 More Java Then Java. Libraries & Packages Java standard class library is composed of useful classes that help us to achieve our programming goals."— Presentation transcript:

1 Java 3 More Java Then Java

2 Libraries & Packages Java standard class library is composed of useful classes that help us to achieve our programming goals but are not a part of the Java language Java packages are groups of classes that we can call by a single name…the String class is part of the java.lang package. Some packages are listed on p. 94

3 Class Libraries “Set of classes that supports the development of programs.” Included with compiler or available from 3 rd party vendors. Provide common methods programmers come to depend on.

4 Packages Groups of related packages. String class is part of the java.lang package. Some packages contain many classes so be careful when using “*” imports.

5 Importing Classes Java.lang packages are automatically available to every program we write. To access other packages we must use a fully qualified reference to the package or import it. import java.util.*; import cs1.Keyboard;

6 Class Methods Also called static methods. Invoked through the class name. Examples: Math.pow(2,8); Keyboard.readInt();

7 Applets Java programs intended to be run using a Web browser. Can also be viewed using Sun’s appletviewer. Applets don’t have a “main” method. Graphical applets need to import… java.applet.Applet java.awt.*

8 Applets Cont’d. Classes that define applets inherit from the master Applet class. In Java terms, they EXTEND the Applet class. Applet classes must be public (more on this later) Must be bytecode before being downloaded by the browser ( a.class file)

9 Applets Cont’d. Applets are embedded in HTML pages using the tag.

10 Basic Conditional Statements if (this > that) { this++; } else { that++; }

11 Basic Conditional Statements // single line shortcut if (this > that) this++; else that++;

12 Basic Conditional Statements Equality Operators… == equal to !=not equal to greater than >=greater than or equal to

13 More Conditionals if (this > that) this++; else if that++; else if theotherthing++; else nothing++;

14 Logical Operators Logical Operators… ! not &&and ||or

15 More Operators Increment and Decrement ++Increment I = I + 1 --Decrement I = I - 1

16 Switch Statements switch(something) case ‘y’: this++; break; case ‘n’: that++; break;

17 Comparing Strings Don’t use ==, we’ll discuss that later. Do use objname.equals(otherobj); objname.compareTo(otherobj);

18 Comparing Floats Watch your precision. “==“ compares ONLY the underlying binary representations and it is unlikely they will match. Do use the absolute value of the difference of 2 numbers and compare to a pre-set value. final float TOLERANCE =.01; if(Math.abs(fl1 – fl2) < TOLERANCE) System.out.println(“Equal enough”);


Download ppt "Java 3 More Java Then Java. Libraries & Packages Java standard class library is composed of useful classes that help us to achieve our programming goals."

Similar presentations


Ads by Google