Computer Science Review PDF

Summary

This document provides an overview of various computer science concepts, particularly in object-oriented programming (OOP) with an emphasis on Java programming language. It covers topics such as strings, functions, classes, constructors, and static members, along with the concept of polymorphism and abstract classes.

Full Transcript

Unit_1: Programming Concepts & Skills ​ Working with Strings ○​ A string is nothing more than a sequence of characters that is terminated by the null character, to denote that the string has indeed been terminated. Table: String Functions Function...

Unit_1: Programming Concepts & Skills ​ Working with Strings ○​ A string is nothing more than a sequence of characters that is terminated by the null character, to denote that the string has indeed been terminated. Table: String Functions Function Description length() This is used to return the length of the string toLowerCase() This functions returns the string in lower case toUpperCase() This functions returns the string in upper case contains() This is used to check the existence of another string endsWith() This is used to check if the string ends with a particular string value indexOf() This is used to get the index value of a character in the string replace() This is used to replace a character in the original string substring() This is used to return a substring from the original string compareTo() This compares an instance with a specified string and indicates whether this instance precedes follow or appears in the same position in the sort order as the specified string. Unit_2: Programming Concepts & Skills ​ Member Function ○​ Member functions can be used to add additional functionality. They can be used to output the values of the properties. Meaning that you won't have to add code every time you want to display the values. ○​ // Member function to display car information public void displayInfo() { System.out.println("Model: " + model); System.out.println("Year: " + year); System.out.println("Price: $" + price); } ​ Class Modifiers ○​ Class modifiers can be used to define the visibility of properties and methods in a class. ​ Private - with this modifier, the properties and methods are available to the class itself. ​ Protected - with this modifier, the properties and methods are only available to the class itself and subclasses derived from the class ​ Public - properties and methods are available to all classes ​ Constructors ○​ Constructors are special methods that are called when an object of the class is created public void Input(int id, String name){ this.studentid = id; This.studentname = name; } ​ Parameterized Constructors ○​ Parameterized constructor is a constructor that allows you to pass arguments (parameters) when creating an object. ​ Static Members ○​ A static member in Java refers to a variable or method that is shared by all instances (objects) of that class, rather than having a separate copy for each object.. Unit_3: Designing Modular Programs ​ Polymorphism ○​ uses the same method names to indicate different implementations of an object in which the base (parent) and derived classes (child) have the same functions. Recalls that when you create a subclass, it inherits all the instance variables and methods of that superclass. Sometimes, however, you may want your methods to perform or do something slightly different. The process of redefining methods that a subclass would otherwise inherit is called overriding methods. The rule that the compiler follows if the function exists in both the child class and the ✅ parent class is: If the function is invoked from an object of the subclass class, then the ✅ function in the subclass is executed. If the function is invoked from an object of the superclass then the superclass method is invoked. ✅ Methods That Cannot be Overridden ✅ Private ✅ Static ✅ Final methods Methods with final classes (classes that cannot have subclasses). ​ Abstract Classes ○​ You can create only with the intention to extend from, but not to instantiate (create objects) from, are abstract classes. ○​ An abstract class is one from which you cannot create any concrete objects, but from which you can inherit. ○​ You use the keyword ‘abstract’ when you declare an abstract class. If you attempt to instantiate an object from an abstract class, you will receive an error message that you have committed an InstantiationError Features of Abstract Classes Abstract classes are like regular classes because they have data and methods. The only difference lies in the fact that you cannot create instances of abstract classes by using the ‘new’ keyword. It is only created simply so that it can provide a superclass from which other objects may inherit. Abstract methods contain abstract methods. An abstract method is basically a method with no method statements. Abstract methods can only be declared in abstract classes The Concept of Dynamic Building When creating a superclass and one or more subclasses, each object of the subclass is a superclass object. Superclass objects are not members of any of their subclasses. When a superclass is abstract, you cannot create objects of the superclass, but whether or not a superclass is abstract, you can create a reference to the superclass. When creating a reference, you DON’T use the keyboard ‘new’ to create a concrete object. Instead, you create a variable in which you can hold the memory address of a subclass concrete object that is a superclass member. Dynamic Building: another implementation of the concept of Polymorphism because you create the objects of the base class but create it with different child classes. Unit_4: Designing Modular Programs ​ Java Recursions ○​ Recursion is a method of making a function call itself. This means to break down complicated problems into simpler problems ​ Insertion Sort ○​ It is a simple sorting algorithm that works by iteratively inserting each element of an unsorted list into its correct position in a sorted portion of the list. public static void insertSort( double[] list) { for (int top = 1; top < list.length; top++) { double item = list[top]; // temporary storage of item int i = top; while (i > 0 && item < list[i-1]) { list[i] = list[i-1]; // shift larger items to the right by one i--; // prepare to check the next item to the left } list[i] = item; // put sorted item in open location } }

Use Quizgecko on...
Browser
Browser