Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week1 Using the Library (the Java API) Classes are grouped together in packages –To use a class you have to know which package it is in –Every package.

Similar presentations


Presentation on theme: "Week1 Using the Library (the Java API) Classes are grouped together in packages –To use a class you have to know which package it is in –Every package."— Presentation transcript:

1 Week1 Using the Library (the Java API) Classes are grouped together in packages –To use a class you have to know which package it is in –Every package has a name (ArrayList is in the package java.util – which has a lot of utility classes) You have to use the full name of the class you will use in your code –import java.util.ArrayList; //now you can use it –java.util.ArrayList myList; //can use the full name as the datatype You’ve already used classes from the java.lang package… –System and Math are both classes –java.lang classes are sort of pre-imported (because they are so fundamental)

2 Week2 import The packages organize the classes to make them easier to find Can import complete packages with: –import package-name.*; –Ex: import java.util.*; //everything in util package Or can import just the class you will be using –import java.util.Random; –This way clearly shows which classes are used in the code (which makes it easier to document) java.lang classes are used so frequently, they are automatically imported

3 Week3 Java API It is essential for a good Java programmer to be able to work with the Java library and to make informed choices about which classes to use –Quickly enables you to perform many tasks more easily than you would otherwise have been able to do Know some of the most important classes from the library by name and how to find out about other classes and look up details

4 Week4 Reading the API Let’s look at the String class and some other classes –What is the structure of the class documentation? –Which sections are common to all class descriptions? What is their purpose? –Look up the startsWith method – what does it do? –Is there a method that tests whether a string ends with a certain suffix? –Is there a method that returns the number of characters in the string?


Download ppt "Week1 Using the Library (the Java API) Classes are grouped together in packages –To use a class you have to know which package it is in –Every package."

Similar presentations


Ads by Google