THE JAVA API. Some of the Java API Packages Package Theme Some Classes Within It. Classes that provide helpful utilities

Similar documents
Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

6.1. Example: A Tip Calculator 6-1

Some Scanner Class Methods

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Basics of Java Programming Input and the Scanner class

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Fundamentals of Java Programming

Java Programming Fundamentals

Topic 11 Scanner object, conditional execution

Chapter 3. Input and output. 3.1 The System class

Install Java Development Kit (JDK) 1.8

Lecture 5: Java Fundamentals III

WHAT ARE PACKAGES? A package is a collection of related classes. This is similar to the notion that a class is a collection of related methods.

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

java Features Version April 19, 2013 by Thorsten Kracht

Building Java Programs

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Introduction to Programming

Part I. Multiple Choice Questions (2 points each):

More on Objects and Classes

Introduction to Java. CS 3: Computer Programming in Java

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

AP Computer Science Static Methods, Strings, User Input

Building Java Programs

Crash Course in Java

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

Java Interview Questions and Answers

Java Crash Course Part I

1001ICT Introduction To Programming Lecture Notes

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Arrays in Java. Working with Arrays

An Overview of Java. overview-1

Using Files as Input/Output in Java 5.0 Applications

Object-Oriented Programming in Java

AP Computer Science Java Mr. Clausen Program 9A, 9B

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Chapter 2 Introduction to Java programming

Using Two-Dimensional Arrays

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Comp 248 Introduction to Programming

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Contents. 9-1 Copyright (c) N. Afshartous

Introduction to Java

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

Classes and Objects. Agenda. Quiz 7/1/2008. The Background of the Object-Oriented Approach. Class. Object. Package and import

Week 1: Review of Java Programming Basics

Lab 5: Bank Account. Defining objects & classes

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

13 File Output and Input

Creating a Java application using Perfect Developer and the Java Develo...

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

CSC 551: Web Programming. Fall 2001

Event-Driven Programming

CS506 Web Design and Development Solved Online Quiz No. 01

CS 106 Introduction to Computer Science I

Sample CSE8A midterm Multiple Choice (circle one)

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Introduction to programming

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Building Java Programs

AP Computer Science File Input with Scanner

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Chapter 2: Elements of Java

Media Upload and Sharing Website using HBASE

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

LAB4 Making Classes and Objects

Moving from CS 61A Scheme to CS 61B Java

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Programming Languages CIS 443

Basic Object-Oriented Programming in Java

Chapter 1 Java Program Design and Development

Building Java Programs

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Programming Fundamentals I CS 110, Central Washington University. November 2015

I. INTRODUCTION. International Journal of Computer Science Trends and Technology (IJCST) Volume 3 Issue 2, Mar-Apr 2015

How to use the Eclipse IDE for Java Application Development

Chapter 2 Elementary Programming

How to create/avoid memory leak in Java and.net? Venkat Subramaniam

JAVA ARRAY EXAMPLE PDF

In this Chapter you ll learn:

Lecture 1 Introduction to Java

Installing Java (Windows) and Writing your First Program

Interactive Programs and Graphics in Java

Introduction to Object-Oriented Programming

Transcription:

THE JAVA API The Java API which stands for Application Programming Interface is a repository of prewritten classes provided by the creators of Java to enhance its usefulness. There are classes for creating windows with menus and buttons, for drawing two-dimensional figures, for downloading pages from the Internet all kinds of stuff. Classes within the API are organized into libraries called packages, each of which has a like theme. Some of the Java API Packages Package Theme Some Classes Within It java.lang java.util Classes that are considered essential to every Java program Classes that provide helpful utilities Math String Calendar Random Object System Date Scanner java.io Class that perform system input and output File PrintStream The classes in the API are already compiled and available to your Java programs. To use any class other than those in java.lang, specify its full name package name. class identifier. This allows the compiler to resolve the external reference by finding the class file in the Java library. The Scanner class is in package java.util. The following statement correctly references it. java.util.scanner input = new java.util.scanner( System.in ); The import Statement You can inform the Java compiler that you are using a class from a package by placing an import statement at the top of your Java file. The syntax is: import package name. class identifier ; Using this import statement allows you to refer to the class by its shorter class identifier. The Java API Page 1

1 2 3 4 5 6 7 8 9 10 import java.util.scanner; public static void main( String [] args ) Scanner input = new Scanner( System.in ); You can also use an asterisk (*) as a wildcard in the import statement to tell the compiler to import the whole package. The syntax is: import package name. * ; 1 2 3 4 5 6 7 8 9 10 import java.util.*; public static void main( String [] args ) Scanner input = new Scanner( System.in ); Using the wildcard to import the whole package does not reduce the run-time efficiency of your code because the import statement creates no executable operations and it doesn t add unnecessary machine code to your program. It is a compiler declaration that simply allows the compiler to refine its search pattern when resolving the external references. The only machine code added to your program is that for the classes that your program actually references. The Java API Page 2

The java.lang Package The classes in package java.lang are considered so essential that you can use their shorter class identifiers without an import statement. The Java statement: java.lang.string name = new java.lang.string( "JAVA" ); Can be replaced by the following without having to import java.lang.string: String name = new String( "JAVA" ); The import static Statement Class variables and methods can be imported so that you can use their shorter class identifiers. Use Java s import static statement. The syntax is: import static package name. class identifier. * ; Java s String class contains this static method: static String valueof( double d ) // Returns the string representation of the double argument. Without an import static statement, this method is called using: String.valueOf( d ) Or, you can import the static items in String and dispense with the qualifier: import static java.lang.string.*; valueof( d ) The Java API Page 3

Exercises For each application below, circle what's wrong and explain. Two of them are correct. 1. import Scanner; import Math; import System; Scanner in = new Scanner( System.in ); java.lang.system. area = Math.PI * Math.pow( radius, 2 ); 2. Scanner in = new Scanner( System.in ); java.lang.system. area = Math.PI * Math.pow( radius, 2 ); The Java API Page 4

3. java.util.scanner in = new java.util.scanner( System.in ); System. area = Math.PI * Math.pow( radius, 2 ); 4. import java.util.scanner; import java.lang.math; import java.lang.system; Scanner in = new Scanner( in ); The Java API Page 5

5. import java.util.scanner; import static java.lang.math; import static java.lang.system; Scanner in = new Scanner( in ); 6. import java.util.scanner; import static java.lang.math.*; import static java.lang.system.*; Scanner in = new Scanner( in ); The Java API Page 6

7. import java.util.scanner; import static java.lang.math.*; import static java.lang.system.*; Scanner input = new Scanner( in ); The Java API Page 7