• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 9 páginas
Examen

IST 311 Midterm Complete Solutions

Document preview thumbnail
Vista previa 2 fuera de 9 páginas

IST 311 Midterm Complete Solutions Why Should You "Format" Your Code? ️•Readability -Makes it much easier to determine what the code is doing •Finding typos -Missing characters like { ; and ( can cause formatting misalignments •Conformity and Consistency -Programming teams should agree on what type of formatting Class names ️•Class names should be PascalCased (aka, MixedCase) •First character upper-case •All "words" in the class name should begin with upper-case •No underscores •They should be "singular", not "plural" •Good class names: -Person, FootballGame, Invoice, Cart, Order, CollegeCourse •Bad class names: -person, Football_Game, Invoices, collegeCourse Field & Variable Naming Conventions ️•Use camelCasing when naming fields & variables -First letter lower-case; each following word capital -No underscores or abbreviations •Good Java variable names: -netPrice, mothersMaidenName •Bad Java variable names: -NetPrice, mothers_maiden_name Constants ️•Constants should be all uppercase •With underscore (_) between words •e.g., public static final int MAX_CONNECTIONS = 5; public static final String COMPANY = "Acme"; Single-letter names: ️Don't use them (except for loop iterators and Exception) method/field/variable names ️must be meaningful Block Comments ️you can't nest block comments block comments vs line comments ️/* */ - block comments // - line comments The key to OOP (object oriented programming) ️grouping of data & functions together In OOP "data" is also called ️"fields" or "states" In OOP "functions" are also called ️"methods" or "behaviors" Four Pillars of OOP ️•Encapsulation -Surrounding & protecting fields & methods •Inheritance -Creating a new class, by way of an existing class •Polymorphism -Related-but-different objects treated similarly •Abstraction -Generalizing, simplifying -Not to be confused with "abstract" Java class, which is something different Java allows for encapsulation.... ️via data hiding (getters/setters) the keyword that Java uses to engage inheritance ️extends What is polymorphism? ️•Greek for "many forms" •Using different types of objects in the same context •They must have a common ancestor -Base class or -Interface (we'll talk about that later) •That's actually called Subtype Polymorphism -There are other kinds, but that's what most people mean for "polymorphism" example: public class Main { public static void displayVoice(Animal animal) { Sln(()); } public static void main() { Dog dog = new Dog(); Cat cat = new Cat(); displayVoice(dog); displayVoice(cat); } } Abstraction ️•Creating a representation of something, but only include characteristics relevant for its usage • When talking about classes, that means to include only fields and methods relevant to its use -Know that unlike the other 3 pillars, "abstraction" more of adesign idea, than programming A class.... ️must implement all the methods named in the interface How to recognize a concrete method and abstract method ️abstract methods do not have {} that the names of the parameters in the interface... ️do not need tomatch the implementing classes' paremeter names Interface ️Remember that a class is a blueprint for an object? •Well, an interface is a set of rules for creating a class -Sometimes compared to a real-life contract •Typically, its name begins with a capital I -ISerializeable, IDisposeable, etc... •An interface may contain abstract methods •An interface may also contain constants -e.g., public static final int MAX_COUNT = 100; int MAX_COUNT = 100; // Same as above because you have no choice in the matter •You are not able to instantiate an interface ISerializeable ser = new ISerializeable(); •You can only instantiate the class that implements that interface •A class may implement more than one interface abstract methods in an interface... ️are public that an implemented method must match... ️the signature in the interface The Point ️The interface doesn't care how you implement the class. It only cares that you have methods with the required signatures. that abstract classes can contain... ️abstract methods thatneed to be implemented that abstract classes can also... ️contain concrete methods how is the "abstract" keyword used. ️public abstract class Vehicle { private static int TANK_MAX = 12; private int tank = 0; that a class that extends an abstract class must.... ️implementall the abstract methods Limitations of Abstract Classes ️•Just like an interface, you cannot instantiate an abstract class -It can only be used as a parent class • A class can extend only one abstract class - Java does not support multiple inheritance of classes - Although you can implement multiple interfaces when to use standalone, interface, or abstract ️•Standalone class -Simple assignments/projects •Unless your teacher tells you to use interface or abstract -Only if your class is used by a very few other classes •Interface -For classes that can be implemented many different ways -You don't want to know how the methods are implemented


Información del documento

Subido en
19 de marzo de 2024
Número de páginas
9
Escrito en
2023/2024
Tipo
Examen
Contiene
Preguntas y respuestas
$11.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

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.
CertifiedGrades
3.9
(38)
Vendido
149
Seguidores
61
Artículos
8729
Última venta
1 mes hace



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

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