• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 9 pages
Exam (elaborations)

IST 311 Midterm Complete Solutions

Document preview thumbnail
Preview 2 out of 9 pages

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


Document information

Uploaded on
March 19, 2024
Number of pages
9
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers
$11.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
CertifiedGrades
3.9
(38)
Sold
149
Followers
61
Items
8729
Last sold
1 month ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions

Whoops! We can’t load your doc right now. Try again or contact support.