100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4.2 TrustPilot
logo-home
Resumen

Summary CS114 - 2.2 Libraries and Clients

Puntuación
-
Vendido
-
Páginas
7
Subido en
24-06-2021
Escrito en
2021/2022

Summaries from the "Introduction to Programming in Java" textbook to assist in quick studying and revision for tests and exams. Be sure to look at the bundles to buy several chapters at a much lower price. Please note these notes only include summaries for Chapter 2.2 and further summaries will be uploaded soon.

Mostrar más Leer menos
Institución
Grado









Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Libro relacionado

Escuela, estudio y materia

Institución
Grado

Información del documento

¿Un libro?
No
¿Qué capítulos están resumidos?
Chapter 2.2 (libraries and clients)
Subido en
24 de junio de 2021
Número de páginas
7
Escrito en
2021/2022
Tipo
Resumen

Temas

Vista previa del contenido

Introduction
• Referring to a method from another Java file is easy
• Benefits of having methods in different files
o Enables us to reuse code
o Enables modular programming → can develop libraries of static methods for use by any other
program; can independently develop, compile & debug parts of big programs one piece at a time


Using static methods in other programs
• To refer to static method in one class that’s defined in another
o Make both classes accessible to Java (e.g. in same directory in your computer)
o To call a method → prepend its class name & a period separator
• Modular programming = independently develop & debug methods for an application, and use them at any
later time

The public keyword Compile when necessary
• Identifies method as available for use by any • When compiling a program, Java compiles
other program with access to the file everything that needs to be compiled in order to
• Can also identify a method as private (but no run that program
reason to do so at this point) • Useful because all classes that call methods
will use the new version of your code if you fix
Each module is a class any bugs etc.

• Module = all code we keep in a single file
• Each module is a Java class that is kept in a file Multiple main() methods
with the same name as the file but has a .java • More than one class might have a main()
extension method
• For now → each class is a set of static methods • When you type java followed by a class name,
Java transfers control to the machine code
The .class file corresponding to the main() method defined in
that class
• When compiling a program, Java compiler
• Usually have a main() method in every class to
makes a file with the class name + a .class
test & debug its methods
extension that has the program’s code in a
language more suited to the computer Tips
• If you have a .class file, you can use the
• Think of each program you write as
module’s methods in another program without
something you might want to use later
having the source code in the corresponding
• Will allow you to have multiple tools to
.java file (but will be tricky if you find a bug)
use later & save time




1

, Libraries
• Module whose methods are mainly intended for use by many other
programs
• Important characteristic of Java → thousands of libraries have been
predefined for your use
• User-defined libraries = classes that contain a set of related methods for
use by other programs
• No Java library can contain all the methods we might need for a given
computation, so being able to build our own libraries is crucial to
address complex programs


Clients
• Program that calls a given library method
• When a class contains a method that is a client of a method in another
class → first class is a client of the second class


APIs
• Programmers think in terms of a contract between the client & the
implementation that’s a clear specification of what the method is to do
• When writing both clients & implementations, you are making contracts
with yourself → helpful when you are debugging & can reuse code
• API = Application Programming Interface
o Programs written that are clients of built-in Java classes
o Precise specification of signatures of methods available for use


Implementations
• Java code that implements the methods in an API, kept by
convention in a file with the library name & a .java extension
• Every Java program is an implementation of some API (no API is
of use without some implementation)
• Goal when developing an implementation → honour the terms of
the contract
• Separating client code from implementation code gives us
freedom to substitute new & improved implementations
• Limits to the amount of info we can productively include in an API
→ provide to client programmers the info they need & no more
• Implementations change quite frequently



Random numbers
• Code uses particular idioms that convert the random
double values between 0 and 1 that Math.random()
provides to the type of random numbers that we want to
use
• To effectively reuse code that implements these idioms,
we’ll now use the StdRandom library
• Summarize the methods in the StdRandom library with
an API
• Collecting methods with Math.random() to get random
numbers of different types in 1 file → focus on
generating random numbers to this one file instead of
spreading through all programs that use these methods
2
$3.07
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada


Documento también disponible en un lote

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
notesfromaCSmajor Stellenbosch University
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
351
Miembro desde
6 año
Número de seguidores
278
Documentos
0
Última venta
1 mes hace
Summaries for Grades 10 - 12 (various subjects)

I am an A-aggregate student, and making summaries is one of my favourite studying techniques. Stuvia gives me the opportunity to share my notes with other learners who may need them!

4.3

68 reseñas

5
34
4
25
3
6
2
2
1
1

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes