Flashcards
Object Oriented Programming
Cards in this deck (22)
- 1OBJECT ORIENTED PROGRAMMING (OOP)Type of programming, driven by modeling code around building units called objects
- 2OBJECT.Hold data( fields) that describe itself
.Performing action(methods)
-> Object is an enhanced data type that can be designed-> make code more meaningful, organized/ easy to understand-> easy to maintain - 3FIELDS (attributes, member variable)Fields of object are data variables that make up object.
Fields are made up of primitive types, objects. example:
book object contains:
String title; String author;
->to access field: book.title - 4METHODS (functions)Functions that belong to a particular object
examples: for a book object
void setBookmark(int pageNum);
book.setBookmark(12); - 5INTEGRATED DEVELOPMENT ENVIRONMENT (IDE)Combines:
Text editor(with highlight keywords, auto completes code)
Compiler(convert Java code into computer code(byte code))
Intellij, NetBeans, Eclipse, Android Studio - 6CLASSextension: .java
A Data type
Blueprint for Objects ->Defines the structure
Objects are to Classes what variables are to Data types - 7Nested ClassesNested classes are divided into two categories: static and non-static. Nested classes that are declared static are called static nested classes. Non-static nested classes are called inner classes.Compelling reasons for using nested classes include the following:
It is a way of logically grouping classes that are only used in one place: If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such "helper classes" makes their package more streamlined.
It increases encapsulation: Consider two top-level classes, A and B, where B needs access to members of A that would otherwise be declared private. By hiding class B within class A, A's members can be declared private and B can access them. In addition, B itself can be hidden from the outside world.
It can lead to more readable and maintainable code: Nesting small classes within top-level classes places the code closer to where it is used. - 8StringsString is in fact a class and not a primitive type
A String variable(object) is made up of an array of characters as its field. Being an object also means it has some methods (length() or equals()...) - 9Class Primitive type Integer int Long long Double double Character char String char[]Classes that wrap around the primitive types.
Offer some functionality through their methods - 10The main methodThe starting point for any Java Program.
Inside it you can create objects and call methods to run other parts of your code. And then when the main method ends the program terminates.
The main method can belong to any class, or you can create a specific class just for that main method which is what most people do. - 11ConstructorConstructors are special types of methods that are responsible for creating and initializing an object of that class.
A Default constructor is one that doesn't take any input parameters at all.
Creating a constructor is very much like creating a method, except that:
.Constructors don't have any return types.
.Constructors have the same name as the class itself.
Constructors can take input parameters like a normal method, and you are allowed to create multiple constructors with different input parameters. - 12Setterspublic method that sets each private field, this way you will know when you are changing a field.
- 13Getterspublic method that returns each private field, so you can read the value without mistakenly changing it.
- 14helper methodsPrivate methods
they can only be seen and called by the same class, they are usually there to organize your code and keep it simple and more readable. - 15public methodsactual actions that the class can perform and are pretty much what the rest of the program can see and call.
- 16It's recommended toSet all your classes to public
Set all your fields to private
Set any of your methods to public that are considered actions
Set any of your methods to private that are considered helper methods - 17import java.util.Scanner;Point program to the java.util library that include the Scanner class.
... and create a new scanner object:
Scanner scanner = new Scanner(System.in); - 18Command-Line ArgumentsJava application can accept any number of arguments from the command line. This allows the user to specify configuration information when the application is launched.
example:
instead of: Java Weather
we can customize: Java Weather Florida - 19ExceptionsA Formal definition of a potential problem
- 20Syntax ErrorsViolation of Java's grammatical rules
Java code wont even compile - 21Runtime ErrorsHappens while the program is running
Might cause the program to crash - 22Bugs (logic errors)Program just doesn't do what you'd except
Information
- Description
- Computer Science Flashcards on Object Oriented Programming, created by Gia Do on 01/08/2018.
- Created by
- Gia Do
- Views
- 1
- Rating