



































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




































classes formatting output enumerated types [skip] wrapper classes graphical components and containers labels and images
new^ operator to create an object^ title^ =^ new^ String
(“Intro^ to^ Computing"); This calls the Stringconstructor, which is a special method that sets up the object
-^ Creating an object is called
instantiation
-^ An object is an^ instance
of a particular class
dot operator^ to invoke its methods (e.g. the Scanner object)^ count = title.length(); • A method may^ return a value
, which can be used in an assignment or expression • A method invocation can be thought of asasking an object to perform a service (or, insome cases, tell us about itself)
(^38) num1 (^) Before: (^96) num2 (^) num2 = num1;^38 num1 (^) After:^38 num
"Steve^ Jobs" "Steve^ Wozniak" name1 name After:
"Steve^ Jobs"
String^ class is^ immutable • However, several methods of the
String^ class return new^ String^ objects that are modifiedversions of the original • See the list of^ String
methods on page 119 and in Appendix M
, the character^ 'H'^ is at index 0 and the^ 'o'^ is at index 4 • See^ StringExample1.java
is part of any Java development environment • Its classes are not part of the Java languageper se, but we rely on them heavily • Various classes we've already used (
System, Scanner,^ String) are part of the Javastandard class library • Other class libraries can be obtained throughthird party vendors, or you can create themyourself
packages
-^ Some of the packages in the standard classlibrary are:^ Package^ java.lang^ java.applet^ java.awt^ javax.swing^ java.net^ java.util^ javax.xml.parsers
Purpose General support Creating applets for the web Graphics and graphical user interfaces Additional graphics capabilities Network communication Utilities XML document processing
-^ See jGRASP “Help” – “Java API”
package are imported automatically into all programs • It's as if all programs contain the followingline:^ import java.lang.*; • That's why we didn't have to import the System^ or^ String^ classes explicitly in earlierprograms • The^ Scanner^ class, on the other hand, is partof the^ java.util^ package, and therefore mustbe imported
java.util package • It provides methods that generatepseudorandom numbers • A^ Random^ object performs complicatedcalculations based on a
seed value^ to produce a stream of seemingly random values • See^ RandomNumbersExample.java