OOP

Ace your homework & exams now with Quizwiz!

How do you add a new method to an existing JavaScript object?

- Add to the prototype chain or just prototype

Name the statement separators/terminators for the following languages (JavaScript, CSS, Ruby, Java, Python, and PHP)

- JavaScript: semicolon separated (but sometimes implicitly inserted on newlines) - CSS: semicolon separated - Ruby: newline terminated - Java: semicolon terminated - Python: newline terminated - PHP: semicolon terminated - Groovy: newline terminated, semicolon optional

What is SEO?

- Search Engine Optimization - the simple activity of ensuring a website can be found in search engines for words and phrases relevant to what the site is offering. In many respects it's simply quality control for websites. - for better SEO: 1.)Write content that uses words and phrases used by people who search for your product or service 2.) Earn links to your pages by having content people love/need; 10 or 15 links from quality relevant resources (pages) to your page will have a much bigger impact on how your page ranks than 1000 low value links as sold by lots of SEO companies.

What is SOA?

- Service-oriented Architecture - SOA is a new badge for some very old ideas: - Divide your code into reusable modules. - Encapsulate in a module any design decision that is likely to change. - Design your modules in such a way that they can be combined in different useful ways (sometimes called a "family" or "product line"). *These are all bedrock software-development principles, many of them first articulated by David Parnas. - What's new in SOA is - You're doing it on a network. - Modules are communicating by sending messages to each other over the network, rather than by more traditional programming-language mechanisms like procedure calls. In particular, in a service-oriented architecture the parts generally don't share mutable state (global variables in a traditional program). Or if they do share state, that state is carefully locked up in a database which is itself an agent and which can easily manage multiple concurrent clients.

What are Transient and Volatile Modifiers?

- Transient: The transient modifier applies to variables only and it is not stored as part of its object's Persistent state. This means that when you serialize an object, it will return its default value on de-serialization. Transient variables are not serialized. Short Answer: variable cannot be serialized. Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program. This means other threads can edit that particular variable. So the compiler allows access to them. Not necessary for immutable fields or single threaded fields. Short Answer: variable may be changed by other threads.

PHP: Data Structures

- included in PHP5 - maximize efficiency. - Heap: a partially sorted binary tree where a parent node must be greater or equal than both child nodes - Linked Lists: consist of a set of sequentially linked records that contain references to the next (only) node in the sequence of nodes. Traversal happens in a single direction. - Doubly Linked Lists: consists of a set of sequentially linked records called nodes. each node contains up to two fields, called links, that are references to the previous and next nodes in the sequence of nodes. Traversal can happen both ways - Vector is similar to an array but it can grow to accommodate new elements. It shrinks and grows as necessary. - Stack - vertical stack of objects that are LIFO (last in first out). - HashMap or HashTable- associative array or a set of key/value pairs

PHP: Encapsulation

- is the way we define the visibility of our properties and methods - using the keywords private and protected on a class's methods and properties helps protect them.

PHP: Interfaces

- its like a contract - it creates a shell to be filled in by child classes - interfaces cannot be instantiated - interface methods must be empty - all interface methods must be defined in child classes - classes that implement interfaces are referred to as child or concrete classes - Concrete classes must use the exact method signature as the defined interface. - A concrete class can implement one or more interfaces Example: // create interface interface animal { function breath(); function eat(); } // implement interface class dog implements animal{ function bark() { echo "yap, yap, yap ..."; }

PHP: Abstract Classes

- never instantiated - extended keyword is used - must contain one or more abstract method - all abstract method bodies must be left blank - classes that inherit abstract classes are referred to as child or concrete classes - a child class of an abstract class must define all abstract functions - abstract functions defined in the child class must have the same or lower visibility as the function in the parent class - non-abstract functions can be overridden as well - non-abstract functions do not have to be defined in the child class - only abstract classes can hold abstract functions - abstract keyword comes before the visibility keyword (e.g. abstract protected function foo(); - a child class can only extend one class, including abstract classes EXAMPLE: // create abstract class abstract class Animal { public $name; public $age; public function Describe() { return $this->name . ", " . $this->age . " years old"; } abstract public function Greet(); } // create class that is an extension of the abstract class class Dog extends Animal { public function Greet() { return "Woof!"; } public function Describe() { return parent::Describe() . ", and I'm a dog!"; } }

What are inner class and anonymous class?

-Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Useful if you don't need access to local variables or method parameters. -Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.

What is method overloading and method overriding?

-Method Overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Occurs at compile time. Overloading Conditions: 1.) The number of parameters are different 2.) The parameter types are different - Method Overloading (PHP): by default, PHP does not support method overloading. instead, a function can have a varying number of parameters by setting them to null. ex: myFunc($name = null, $title = null). Alternately the magic method "__call" can be used to emulate method overloading. -Method Overriding : When a subclass/childclass redefines a method that would otherwise have been inherited from it's superclass/parentclass. The method name, number/types of parameters and return type must remain the same. Occurs at run time. - Method Overloading (PHP): works the same in PHP as other languages. a method of the same name with different parameters types/# of parameters can be declared by the child class to 'override' the parent class's method with the same name.

What is an I/O filter?

An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.

What is an abstract class?

An abstract class is a class that can't be instantiated. Other classes extend them. An abstract class contains one or more abstract method that are undefined. For a subclass to instantiate, it must first define non-abstract version of each abstract method.

What is the difference between Array and vector?

Array is a set of related data type and static whereas vector is a growable array of objects and dynamic.

ArrayList vs LinkedList

Both implement the list interface and their results are almost identical. - ArrayLists maintain an index based so searching is quick but inserting or deleting anywhere expect the very end of the array will be slow because all elements must be shifted (removing the first is super slow because every subsequent element must be moved) - Linkedlists implement doubly linked list so searching can be slow because it has to traverse through all elements but inserting and deleting only require pointers to be updated so it is faster.

What is casting?

Casting is used to convert the value of one type to another.

What are Class, Constructor and Primitive data types?

Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.

What are Encapsulation, Inheritance and Polymorphism?

Encapsulation is the packing of data and functions into a single component and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the ability of objects taking on many forms and is a feature that allows one interface to be used for general class actions.

What is ETL and when should it be used?

Extract, Transform, Load; commonly used in data warehousing

GET vs POST

GET requests can be cached GET requests remain in the browser history GET requests can be bookmarked GET requests should never be used when dealing with sensitive data GET requests have length restrictions GET requests should be used only to retrieve data POST requests are never cached POST requests do not remain in the browser history POST requests cannot be bookmarked POST requests have no restrictions on data length

What is meant by Inheritance and what are its advantages?

Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.

Markup Languages vs Programming Languages

Markup Language: A language designed to format text. It does the transition of raw text into structured documents by using markup tags into the raw text. The text given inside the tags are structured by the browsers depending on the markup. Programming languages are compiled. But in markup language is just interpreted by the browser. Few Markup Languages are HTML.XML,XHTML and MML Programming language: It is an set of instructions to the computer to perform. It is coded, compiled and interpreted before it gets executed. Some languages require compiler and some others require interpreter and the rest requires both. The source code converted into machine readable form and then executed. The computer hardware is responsible to execute an programming language and browser is needed for an markup language.

What are methods and how are they defined?

Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method's signature is a combination of the first three parts mentioned above.

What is an Object and how do you allocate memory to it?

Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.

What is OOPs?

Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.

What is the difference between process and thread?

Process is a program in execution whereas thread is a separate path of execution in a program.

Server Side Programming vs Client Side Programming

Server-side Programming: Server-side programming, is the general name for the kinds of programs which are run on the Server. Uses Process user input. Display pages. Structure web applications. Interact with permanent storage (SQL, files). Example Languages PHP ASP.Net in C#, C++, or Visual Basic. Nearly any language (C++, C#, Java). These were not designed specifically for the task, but are now often used for application-level web services. Client-side programming: Much like the server-side, Client-side programming is the name for all of the programs which are run on the Client. Uses Make interactive webpages. Make stuff happen dynamically on the web page. Interact with temporary storage, and local storage (Cookies, localStorage). Send requests to the server, and retrieve data from it. Provide a remote service for client-side applications, such as software registration, content delivery, or remote multi-player gaming. Example languages JavaScript (primarily) HTML* CSS* Any language running on a client device that interacts with a remote service is a client-side language.

Define Polymorphism and give an example.

When the decision to invoke a function call is made by inspecting the object at runtime. Functions are redefined by derived classes that 'implement' a base class. So, you can call methods of a class without knowing the exact type of the class. Example: inheritance, abstract classes, interfaces

What is the difference between an argument and a parameter?

While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

Can you have an inner class inside a method and what variables can you access?

Yes, we can have an inner class inside a method and final variables can be accessed.

What is difference between overloading and overriding?

a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method. b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass. c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass. d) Overloading must have different method signatures whereas overriding must have same signature. e) Overloading happens at compile time, Overriding happens at run time

What is the difference between procedural and object-oriented programs?

a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, the unit of program is an object, which is nothing but combination of data and code. b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible within the object and which in-turn assures the security of the code.

What is final, finalize() and finally?

final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can't be overridden. A final variable can't change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.

What is finalize() method?

finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.

What modifiers may be used with top-level class?

public, abstract and final can be used for top-level class.

What are different types of access modifiers?

public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can't be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.

What are some approaches to guard against cross site scripting? SQL Injection?

- Cross site scripting - encode output, datatypes - SQL Injection - bind variables, datatypes, reserved words

What is instanciation? Initialization?

- Instantiation is creating an 'instance' of a class - Initialisation is giving an initial value to a variable or object.

Difference between a class and an object in the context of Object Oriented Programming

- a class is what you use to define the properties, methods, and behavior of objects - an object is an instance of a class (e.g. think of a class as a blueprint and an object as the actual building you build by following the blueprint)

How are constructs different from functions?

- die and echo do not need parentheses contructs: print() unset() isset() empty() include() require() echo() or echo die() or die

What is a PHP constructor?

- if the child class has a constructor you must explicitly call parent::__construct() within a child's constructor to include it - if the child class doesn't have a constructor then it may inherit from the parent class (if the parent class constructor isn't private)

PHP: inheritance

- one object acquires the properties of another - a child class inherits all of the public and protected methods from a parent class

Forward vs Redirect

- redirect sets the response status to 302, and the new url in a Location header, and sends the response to the browser. Then the browser, according to the http specification, makes another request to the new url - forward happens entirely on the server. The servlet container just forwards the same request to the target url, without the browser knowing about that. Hence you can use the same request attributes and the same request parameters when handling the new url. And the browser won't know the url has changed (because it has happened entirely on the server)

In JavaScript, how do you declare and assign a variable without adding to the global scope?

- self calling anonymous function

How does google search work?

1.) Google performs web crawling (using Googlebots) - meaning links are followed from page to page 2.) Pages are then sorted by their content and other factors and indexed 3.) Algorithms are working as you are typing to find clues to what you are really looking for 4.) Relevant documents are pulled from the index 5.) Results are ranked using over 200 factors (e.g. type/quality/freshness of content, legitimacy of the site, name/address of site, # of link pointing to the website, etc.) and spam is filtered 6.) Final results are returned to the browser

How does a page request work?

1.) In a browser a user types in a URL or clicks a link. 2.) DNS associates the address with an IP 3.) The IP address is sent back to your browser 4.) The browser sends the request to that IP and awaits a response 5.) If all goes well then a 200 response message in the HTTP header and the page content is sent back; If not a 404 page not found error will typically be returned

What is a package?

A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.

How many ways can an argument be passed to a subroutine and explain them?

An argument can be passed in two ways. They are passing by value and passing by reference. Passing by value: This method copies the value of an argument into the formal parameter of the subroutine. Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.

What is the difference between Assignment and Initialization?

Assignment can be done as many times as desired whereas initialization can be done only once.

What is the difference between constructor and method?

Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.

What is Inet address?

Every computer connected to a network has an IP address. An IP address is a number that uniquely identifies each computer on the Net. An IP address is a 32-bit number.

What is interface and its use?

Interface is similar to a class which may contain method's signature only but not bodies and it is a formal set of method and constant declarations that must be defined by the class that implements it. Interfaces are useful for: a)Declaring methods that one or more classes are expected to implement b)Capturing similarities between unrelated classes without forcing a class relationship. c)Determining an object's programming interface without revealing the actual body of the class.

What is a cloneable interface and how many methods does it contain?

It is not having any method because it is a TAGGED or MARKER interface.

What is Domain Naming Service(DNS)?

It is very difficult to remember a set of numbers(IP address) to connect to the Internet. The Domain Naming Service(DNS) is used to overcome this problem. It maps one particular IP address to a string of characters. For example, www. mascom. com implies com is the domain name reserved for US commercial sites, moscom is the name of the company and www is the name of the specific computer, which is mascom's server.

What is serialization and deserialization?

Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects.

What is the difference between set and list?

Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an ordered way but may contain duplicate elements.

What is the difference between TCP/IP and UDP?

TCP/IP is a two-way communication between the client and the server and it is a reliable and there is a confirmation regarding reaching the message to the destination. It is like a phone call. UDP is a one-way communication only between the client and the server and it is not a reliable and there is no confirmation regarding reaching the message to the destination. It is like a postal mail.

Page Request Example

The User opens his web browser (the Client). The User browses to http://google.com. The Client (on the behalf of the User), sends a request to http://google.com (the Server), for their home page. The Server then acknowledges the request, and replies the client with some meta-data (called headers), followed by the page's source. The Client then receives the page's source, and renders it into a human viewable website. The User types Stack Overflow into the search bar, and presses Enter The Client submits that data to the Server. The Server processes that data, and replies with a page matching the search results. The Client, once again, renders that page for the User to view.

What is the difference between exception and error?

The exception class defines mild error conditions that your program encounters. Exceptions can occur when trying to open the file, which does not exist, the network connection is disrupted, operands being manipulated are out of prescribed ranges, the class file you are interested in loading is missing. The error class defines serious error conditions that you should not attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.

What are the states associated in the thread?

Thread contains ready, running, waiting and dead states.

What is URL?

URL stands for Uniform Resource Locator and it points to resource files on the Internet. http://video.google.co.uk:80/videoplay?docid=-7246927612831078230&hl=en#00h02m30s http - protocol video.google.co.uk - host or hostname video - subdomain google.co.uk - domain name uk - top level domain (TLD); tells what type of webpage (e.g. com, org, edu, net, mil, gove, us, uk); in this case its a country code co.uk - second level domain (SLD) 80 - port (default for web servers) videoplay - path (file location) ? - followed by parameters; indicate a dynamic url docid/hl = parameters #00h02m30s - fragment or named anchor; usually refers to internal section of the web document; this one skips to 2 mins 30 secs into the video;

What is UNICODE?

Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.

What are Vector, Hashtable, LinkedList and Enumeration?

Vector : The Vector class provides the capability to implement a growable array of objects. Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object's keys. Hash codes are integer values that identify objects. LinkedList: Removing or inserting elements in the middle of an array can be done using LinkedList. A LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations. Enumeration: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements() and nextElement(). HasMoreElemnts() tests if this enumeration has more elements and nextElement method returns successive elements of the series.

What is the difference between abstract class and interface?

a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract. b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can't have subclasses.

Define authentication and authorization and the tools that are used to support them in enterprise deployments.

authentication - verifies the users identity and provides reusable credentials; digital signatures and certificates; SSL Client Authentication; TLS (Transport layer security) authorization - stores information about user access levels

What is a SAN, and how is it used?

storage area network; it is a LAN designed to handle large data transfers. it is used for data storage, retrieval and replication, backup and restore, archiving, data migration


Related study sets

Palo Alto PSE Strata Professional

View Set

Moon phases and tides test part a

View Set

ap psych sensation and perception test

View Set

OB - Chapter 9 Violence and Abuse

View Set

Chapter 10 - Group Accident & Health Insurance

View Set