OOP Principles

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Accessor Mutator

'get' methods to return value of private fields 'set' value of private fields

What ways can you overload a method?

1) Change the number of arguments in the parameter list 2) Change the data type of the arguments in the parameter list

What is method overriding used for?

1) To provide the specific implementation of a method which is already provided by its superclass 2) Achieves runtime polymorphism

Main principles of method overloading

1) Used to increase the readability of the program 2) Performed within class 3) Parameters must be different in either data type or amount 4) Is an example of compile time polymorphism 5) In Java, cannot be performed by changing return type of the method only. You must change the parameter.

Method Overriding

1) Used to provide the specific implementation of the method that is already provided by its super class 2) Occurs in two classes that have a IS-A (inheritance) relationship 3) Arguments the parameter list must be the same 4) Is an example of run time polymorphism 5) Return type must be the same or covariant in method overriding (Covariant return, means that when overriding a method, the return type of the overriding method is allowed to be a subtype of the overridden method's return type.)

What is a sub class?

A class which inherits the fields and methods of its parent class.

What is a data type?

A data type is a data storage format that can contain a specific type or range of values. Whenever you declare variables, each variable must be assigned a specific data type. Some common data types include integers, floating point, characters, and strings.

What is reusability?

A mechanism which allows you to reuse the same fields and methods already defined in an existing class when you create a new class.

What is an abstract method?

A method which is declared abstract and does not have implementation.

What is a default constructor?

A no-args constructor that the Java compiler inserts if no sufficient parameterized constructor is present;

What is Reflection?

A way to explore the structure of assemblies at run-time (discover which classes/resources/methods there are). Reflection is mechanism to load dynamically assembly at runtime and using assembly Meta data can access its namespace, class and their properties, methods and even events. Reflection is the ability to dynamically execute code without pre-linking at compile time. This may take the form of dynamic module loading and late binding, or it may take the form of real-time code construction and compilation.

Differentiate between an abstract class and an interface.

Abstract Class: 1. A class can extend only one abstract class 2. The members of abstract class can be private as well as protected. 3. Abstract classes should have sub-classes 4. Any class can extend an abstract class. 5. Methods in abstract class can be abstract as well as concrete. 6. There can be a constructor for abstract class. 7. The class extending the abstract class may or may not implement any of its method. 8. An abstract class can implement methods. Interface 1. A class can implement several interfaces 2. An interface can only have public members. 3. Interfaces must have implementations by classes 4. Only an interface can extend another interface. 5. All methods in an interface should be abstract 6. Interface does not have constructor. 7. All methods of interface need to be implemented by a class implementing that interface. 8. Interfaces cannot contain body of any of its method.

What is an array?

An array is defined as a collection of elements, stored at contiguous memory locations, which can be referred by the same variable name. All the elements of an array variable can be accessed by index values. An Index value specifies the position of a particular element in an array variable.

Define enumeration?

Enumeration is defined as a value type that consists of a set of named values. These values are constants and are called enumerators. An enumeration type is declared using the enum keyword. Each enumerator in an enumeration is associated with an underlying type that is set, by default, on the enumerator. The following is an example that creates an enumeration to store different varieties of fruits: enum Fruits {Mango, Apple, orange, Guava}; In the preceding example, an enumeration Fruits is created, where number 0 is associated with Mango, number 1 with Apple, number 2 with Orange, and number 3 with Guava. You can access the enumerators of an enumeration by these values.

§ What is the difference between a.Equals(b) a == b?

Equals checks type as well as it compares on heap to objects == doesn't, it just check value on stack. The first checks whatever the objects are equal, the second whatever they are reference-equal (the same object).

Instance variable

Every instantiated object gets its own copy and is used throughout the class Instance variables are declared inside a class but outside of a method

Discuss the differences between Mocks and Stubs

Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'. Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.

What is the difference between Finalize() and Dispose()?

Finalize() is called by the garbage collector before destroying an object, allowing it to clean up resources it may have allocated. Dispose() is a method the programmer can call on an object to force resource deallocation (and pre-empt costly finalization). Finalize called by GC Dispose called by programmer to free up resources.

What is an INSTANTION?

It uses the "new" keyword to create object (initialize the new object)

What is cyclomatic complexity and why is it important

It's a measure of the number of independent linearly executed paths through a program. It's important for judging the complexity of software and assisting in determinations of which modules should be refactored into smaller components.

What is a namespace?

Namespace is a logical grouping of class. using System; using System.Collections.Generic; using System.Windows.Forms;

Can you inherit private members of a class?

No, you cannot inherit private members of a class because private members are accessible only to that class and not outside that class.

Can a static method be overridden?

No. This is because static methods are bound with classes. Overriding a static method requires an instance method, and an instance method is bound with an object. This means you can only access the static method through a subclass However, you can hide a static method.

Can DateTimes be null?

No. They are structs, not objects. Before .net 2.0 it was not possible as datetime/integer... are struct/value types which can't be null but due to nullable types now its possible. But you can nullable dateTime

Can you declare an overridden method to be static if the original method is not static?

No. Two virtual methods must have the same signature.

Can you allow a class to be inherited, but prevent a method from being overridden in C#?

Yes. Just declare the class public and make the method sealed.

How can you prevent your class to be inherited further?

You can prevent a class from being inherited further by just declaring the class public and make the method sealed.

2 types of return values

Procedures: Void Functions: Return values

What is ABSTRACTION?

Process of hiding the implementation details from the user, only the functionality is provided. Achieved through abstract classes and Interfaces.

What is a property and the advantages that are obtained by using them in programs?

Property is a way to expose an internal data element of a class in a simple and intuitive manner. You can create a property by defining an externally available name and then writing the set and get property accessors. The get property accessor is used to return the property value. The set property accessor is used to assign a new value to the property.

What are the four pillars of OOP?

1) Inheritance 2) Polymorphism 3) Encapsulation 4) Abstraction

Accessors

Public -> Class and Subclass Private -> Class only Protected -> Class and Subclass

Explanation of Public, Protected, Private, Internal And Protected Internal Access Modifier In C#

Public: - Public members are accessible anywhere, inside the type (e.g. - class), outside the type, inside the assembly, outside the assembly, through the inheritance or with the type (e.g. instance of class, with type of class in case of static). Private: - Private members are only accessible within the own type (Own class). Protected: - Protected member are accessible only with its derived types whether it is inside the assembly or outside the assembly. Internal: - Internal member are accessible only within the assembly by inheritance (its derived type) or by instance of class. Protected Internal: - Protected internal is type of access modifier contains protected member properties as well as internal member properties, means protected internal member accessible inside the assembly in its derived class or with the instance of the class and accessible outside the class only in its derived class. Protected Internal Property = Protected Property (anywhere in its derived class inside or outside the assembly) + Internal (with instance of class only inside the assembly)

What are the two types of modifiers in Java?

Access modifiers and non-access modifiers

What are generics?

Generics provide the type-safety to your class at the compile time. While creating a data structure, you never need to specify the data type at the time of declaration. The System.Collections.Generic namespace contains all the generic collections.

Local variable

Variable declared inside a function, cannot be accessed outside of it

What are the advantages of OOP over Procedure Oriented Programming?

OOP makes development and maintenance easier when the code grows alongside the project size. OOP also provides data hiding whereas in a procedure-oriented programming language global data can be accessed from anywhere.

How many processes can listen on a single TCP/IP port?

one

What are the advantages of Inheritance?

1) Code re-usability. The subclass inherits all of the methods and fields of the parent class for its own use. 2) Allows for Method Overriding which a way to achieve runtime polymorphism. Minimizing duplicate code Sharing common code amongst classes Easy to find where it went wrong

What are the rules to remember while creating a constructor?

1) It's name must be the same as its class name 2) It must have no explicit return type 3) It cannot be abstract, static, or final

What are the rules for method overriding?

1) The method have the same name as in the parent class 2) The method must have the same parameters as in the parent class 3) There must be an IS-A relationship (inheritance)

What ways can you achieve abstraction?

1) Using abstract classes 2) Using interfaces

Why is catch(Exception) almost always a bad idea?

1. Since there is no variable defined you can't read the exception 2. Generally its bad to use exception when you have known exception types. Because it swallows an exception without doing anything with it. The only time this should really be used is when trying risky casts that you expect to have a reasonable likelihood of failure, but always of a very specific type.

What is a parameterized constructor?

A constructor with parameters used to provide values to the distinct objects. You can have any number of parameters in the constructor.

What is an abstract class?

An abstract class is a class that cannot be instantiated and is always used as a base class. The basic purpose of an abstract class is to provide a common definition of the base class that multiple derived classes can share.

What is a delegate?

A delegate is similar to a class that is used for storing the reference to a method and invoking that method at runtime, as required. A delegate can hold the reference of only those methods whose signatures are same as that of the delegate. Some of the examples of delegates are type-safe functions, pointers, or callbacks.

What is Object-Oriented Programming?

A pattern of programming where the solution to a problem is found by using objects and classes. It is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object is created in the program to represent a class, therefore, an object encapsulates all the features, such as data and behavior that are associated to a class. OOP allows developers to develop modular programs and assemble them as software. Objects are used to access data and behaviors of different software modules, such as classes, namespaces, and shareable assemblies. .NET Framework supports only OOP languages, such as Visual Basic .NET, Visual C#

What are access modifiers?

Access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control: At the top level—public, or default (package-private) A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes — you will learn about them in a later lesson.) At the member level—public, protected, default (package-private), private At the member level, you can also use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning. For members, there are two additional access modifiers: private and protected. The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.

What is an interface?

An interface is a template that contains only the signature of methods. The signature of a method consists of the numbers of parameters, the type of parameter (value, reference, or output), and the order of parameters. An interface has no implementation on its own because it contains only the definition of methods without any method body. An interface is defined using the interface keyword and cannot be instantiated

What is the difference between arrays and collection?

Array: 1. You need to specify the size of an array at the time of its declaration. It cannot be resized dynamically. 2. The members of an array should be of the same data type. Collection: 1. The size of a collection can be adjusted dynamically, as per the user's requirement. It does not have fixed size. 2. Collection can have elements of different types.

Difference between IEnumerable and List.

Besides one being an interface and the other being a concrete classs, IEnumerable is read-only and List is not read-only If you need the ability to make permanent changes of any kind to your collection (add & remove), you'll need List. If you just need to read, sort and/or filter your collection, IEnumerable is sufficient for that purpose. If you wanted to add the four strings one at a time, you'd need List. If you were instantiating your collection all at once, you could use IEnumerable. IEnumerable firstFourLettersOfAlphabet = new[]{"a","b","c","d"}; You could then use LINQ to filter or sort the list however you wanted.

What are the advantages of Encapsulation?

By providing only a setter or getter method, you can make the class read-only or write-only. It provides you the control over the data. (e.g. write whatever logic you want in the setter methods to restrict data inputs) It is a way to achieve data hiding in Java because other classes will not be able to access the private data members Encapsulated classes are easy to test. (i.e. better for unit testing) Modifies our implemented code without breaking the code of others using our code Maintainability Flexibility Extensibility Data hiding and security

Is it possible for a class to inherit the constructor of its base class?

Class CANNOT inherit the constructor of its base class.

What is the difference between a class and a structure?

Class: 1. A class is a reference type. 2. While instantiating a class, CLR allocates memory for its instance in heap. 3. Classes support inheritance. 4. Variables of a class can be assigned as null. 5. Class can contain constructor/destructor. Structure: 1. A structure is a value type. 2. In structure, memory is allocated on stack. 3. Structures do not support inheritance. 4. Structure members cannot have null values. 5. Structure does not require constructor/destructor and members can be initialized automatically.

What is a class?

Classes are like blueprints used to create objects that defines the properties, states, and behaviors that are common to a number of objects. Classes are templates for the objects Classes are declared by using the class keyword. public class Customer { //Fields, properties, methods and events go here... }

Method

Collection of statements that are grouped together to perform an operation

What are collections?

Collections can be defined as a group of related items that can be referred to as a single unit. The System.Collections namespace provides you with many classes and interfaces. Some of them are: ArrayList, List, Stack, ICollection, IEnumerable, IDictionary

What is concurrency

Concurrency is the ability of a database to allow multiple users to affect multiple transactions. It is the tendency for things to happen at the same time in a system. When dealing with concurrency issues in software systems, there are generally two aspects that are important: being able to detect and respond to external events occurring in a random order, and ensuring that these events are responded to in some minimum required interval. Traditionally, computer programs use a "list of instructions" style for representing what will happen. Instructions happen one after another, in a specific order. This makes it relatively easy to predict what will happen when you have the computer perform your instructions.

What's the difference between asynchrony and concurrency?

Concurrency means multiple tasks which start, run, and complete in overlapping time periods, in no specific order. Parallelism is when multiple tasks OR several part of a unique task literally run at the same time, e.g. on a multi-core processor. - Asynchronous : Tasks may or may not started to execute at the same time (i.e. there is no synchronization between them). - Concurrent : Tasks started executing at the same time. - Parallel : Tasks execution may or may not initiated at same time but working independent of each other.

What is a constant?

Constants must be initialized at the same time they are declared and cannot be changed. You can declare constants by using the following syntax: const int interestRate = 10;

What is a constructor?

Constructor is a special method of a class, which is called automatically when the instance of a class is created. Constructor is used to initialize objects. Constructor is created with the same name as the class and initializes all class members, whenever you access the class. Main features of a constructor are as follows: ● Constructors do not have a return type ● Constructors are always public ● It is not mandatory to declare a constructor; it is invoked automatically by .NET Framework ● Class can have more than one constructor

What is constructor overloading?

Constructor overloading occurs when you have more than one constructor with each having different parameters. This allows each constructor to perform a different task and whichever one is used depends on what parameters are passed by the user.

Constructor vs Method

Constructor: -Used to initialize state of an object -Does not have a return type -Is invoked implicitly -Compiler provides a default constructor if the class has none -The name must be the same as the class name Method: -Used to expose the behavior of an object -Must have a return type -Is invoked explicitly -The method is not provided by the compiler in any case -The name may or may not be the same as the class name

Advantages of the constructor

Constructors enable the programmer to set default values, limit instantiation, and write code that is flexible and easy to read.

Concept of convention over configuration

Convention over Configuration (aka Coding by convention) is a software design paradigm which seeks to decrease the number of decisions that developers need to make, gaining simplicity, but not necessarily losing flexibility. The phrase essentially means a developer only needs to specify unconventional aspects of the application. For example, if there's a class Sale in the model, the corresponding table in the database is called sales by default. It is only if one deviates from this convention, such as calling the table "products sold" that one needs to write code regarding these names. When the convention implemented by the tool you are using matches your desired behavior, you enjoy the benefits without having to write configuration files. When your desired behavior deviates from the implemented convention, then you configure your desired behavior.

What is specialization?

Creating new subclasses from an existing class. If it turns out that certain attributes, associations, or methods only apply to some of the objects of the class, a subclass can be created.

Dependency Injection Principle

DI is a software design pattern that allow us to develop loosely coupled code. It is a great way to reduce tight coupling between software components. DI also enables us to better manage future changes and other complexity in our software. The purpose of DI is to make code maintainable. The Dependency Injection pattern uses a builder object to initialize objects and provide the required dependencies to the object means it allows you to "inject" a dependency from outside the class. Dependency Injection is mainly for injecting the concrete implementation into a class that is using abstraction i.e. interface inside. The main idea of dependency injection is to reduce the coupling between classes and move the binding of abstraction and concrete implementation out of the dependent class. Dependency injection can be done in three ways: Constructor injection Method injection Property injection

Parameter variable

Declared inside the brackets of a method, only existing in that method

What are the two types of constructors?

Default and Parameterized

What is a multicast delegate?

Each delegate object holds reference to a single method. However, it is possible for a delegate object to hold references of and invoke multiple methods. Such delegate objects are called multicast delegates or combinable delegates.

Advantages of Polymorphism

Easier for you to write code and for others to understand Programmer only needs to remember one method name Extensible as new sub-classes would be able to work with them

What is ENCAPSULATION?

Encapsulation is the process of wrapping data and methods together into a single unit. Encapsulation is a protective shield that prevents the data from being accessed by the code outside this shield. Encapsulation can be achieved by: Declaring all the variables in the class as private and writing public methods in the class to set and get the values of variables.

What is garbage collection?

Garbage collection prevents memory leaks during execution of programs. Garbage collector is a low-priority process that manages the allocation and deallocation of memory for your application. It checks for the unreferenced variables and objects. If GC finds any object that is no longer used by the application, it frees up the memory from that object.

Library

Group of classes organized together

What is a hashtable?

Hashtable is a data structure that implements the IDictionary interface. It is used to store multiple items and each of these items is associated with a unique string key. Each item can be accessed using the key associated with it. In short, hashtable is an object holding the key-value pairs.

What are the modifiers in C#?

In c# there are five type of access modifiers Public Private Protected Internal Protected Internal

Explain different types of inheritance.

Inheritance in OOP is of four types: ● Single inheritance - Contains one base class and one derived class ● Hierarchical inheritance - Contains one base class and multiple derived classes of the same base class ● Multilevel inheritance - Contains a class derived from a derived class ● Multiple inheritance - Contains several base classes and a derived class All .NET languages support single, hierarchical, and multilevel inheritance. They do not support multiple inheritance because in these languages, a derived class cannot have more than one base class. However, you can implement multiple inheritance in.NET through interfaces.

What is an object?

Is an instance of a class. They have two main properties: - state - behavior The state is stored in fields (variables) and the behavior is defined by methods. Objects can be created by using the new keyword followed by the name of the class that the object will be based on: Customer newCustomer = new Customer(); Objects can communicate to other objects without knowing the details of each other's data/code. Ex: A dog -States: Color, name, breed -Behavior-Wagging tail, fetching a stick

What is lazy initialization?

Lazy initialization is a process by which an object is not initialized until it is first called in your code. The .NET 4.0 introduces a new wrapper class, System.Lazy<T>, for executing the lazy initialization in your application. Lazy initialization helps you to reduce the wastage of resources and memory requirements to improve performance. It also supports thread-safety.

Disadvantages of inheritance

Logically inconsistent - may not be the same case across inheriting classes Data duplication leading to waste of memory space Changes in one class may not apply to all inheriting classes

What is Managed and Unmanaged Code?

Managed code is code managed through the CLR module. It handles garbage collection, type-safety, and platform-independence behavior. Unmanaged code is code that run outside the CLR, such as an ActiveX control.

How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?

Object life time divides into three different generations, 1 short term and 2 long terms so manage accordingly. Non deterministic finalization means GC calls finalize method of object not right after object goes out of scope rather when GC got idle time to prioritize it.

What is method overloading?

Occurs when a class has multiple methods with the same name but different parameter lists. Method overloading gives you compile time polymorphism. Same method with different parameters Having methods with the same name can increase the readability of the program. (Compile Time Polymorphism):: Functions with same name and different parameters. public class test { public void getStuff(int id){} public void getStuff(string name) {} }

What's the difference between Locking and Lockless (Optimistic and Pessimistic) concurrency models?

Optimistic Locking is a strategy where you read a record, take note of a version number (other methods to do this involve dates, timestamps or checksums/hashes) and check that the version hasn't changed before you write the record back. When you write the record back you filter the update on the version to make sure it's atomic. (i.e. hasn't been updated between when you check the version and write the record to the disk) and update the version in one hit. If the record is dirty (i.e. different version to yours) you abort the transaction and the user can re-start it. Optimistic assumes that nothing's going to change while you're reading it. This strategy is most applicable to high-volume systems and three-tier architectures where you do not necessarily maintain a connection to the database for your session. In this situation the client cannot actually maintain database locks as the connections are taken from a pool and you may not be using the same connection from one access to the next. Pessimistic Locking is when you lock the record for your exclusive use until you have finished with it. It has much better integrity than optimistic locking but requires you to be careful with your application design to avoid Deadlocks. To use pessimistic locking you need either a direct connection to the database (as would typically be the case in a two tier client server application) or an externally available transaction ID that can be used independently of the connection. In the latter case you open the transaction with the TxID and then reconnect using that ID. The DBMS maintains the locks and allows you to pick the session back up through the TxID. This is how distributed transactions using two-phase commit protocols (such as XA or COM+ Transactions) work.

What rule(s) are there for overriding methods?

Overriding methods cannot be more restrictive than the overridden method in the superclass.

§ What is a PID? How is it useful when troubleshooting a system?

PID is Process ID which is unique to identify any process within a system. Whilst troubleshooting we can kill process through its PID.

What is the difference between Procedural and OOP?

Procedural programming is based upon the modular approach in which the larger programs are broken into procedures. Each procedure is a set of instructions that are executed one after another. Access modifiers are not used in procedural programming, which implies that the entire data can be accessed freely anywhere in the program

Disadvantages of OOP

Size - Increased complexity & more memory required to store Speed - Only good for long projects, not short term ones Larger size of program = coders spent more time on it Effort - Not suitable for all scenarios Uses a lot of system resources

What are some of the non-access modifiers?

Static, abstract, synchronized, native, volatile, transient, etc.

What is strong-typing versus weak-typing? Which is preferred? Why?

Strong type is checking the types of variables as soon as possible, usually at compile time. All variables (or data types) are known at compile time There is strict enforcement of typing rules (a String can't be used where an Integer would be expected) All exceptions to typing rules results in a compile time error Weak typing is delaying checking the types of the system as late as possible, usually to run-time. Which is preferred depends on what you want. For scripts & quick stuff you'll usually want weak typing, because you want to write as less code as possible. In big programs, strong typing can reduce errors at compile time.

The abstraction of a thread of control can be implemented in a number of ways by hardware and software.

The most common mechanisms are variations of one of the following: · Multiprocessing — multiple CPUs executing concurrently · Multitasking — the operating systems simulates concurrency on a single CPU byinterleaving the execution of different tasks · Application-based solutions — the application software takes responsibility forswitching between different branches of code at appropriate times

What is the GAC? What problem does it solve?

The Global Assembly Cache. It stores strongly-named assemblies in a single location, allowing for verification of code library uniqueness when executing. Shareable/public assemblies (DLL) stored to be used by multiple programs. It gives a shared platform for programs to use single assembly and can store same assembly (of same name) with different versions and can help to solve DLL HELL.

What is POLYMORPHISM?

The ability of an object to take on many forms. The most common occurrence is when a parent class reference is used to refer to a child class object. Different forms of the same method Any Java object that can pass more than one IS-A test is polymorphic.

What is generalization?

The process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass.

What is a super class?

The class of which a subclass inherits its fields and methods. It is also called a base class or parent class.

What is the difference between an EXE and a DLL?

The difference is that an EXE has an entry point, a "main" method that will run on execution. The code within a DLL needs to be called from another application. A Dynamic-link library (DLL) is a library and therefore can not be executed directly. If you try to run it you will get an error about a missing entry point. It needs an entry point (main function) to get executed, that entry point can be any application or exe. DLL binding occurs at run-time. That is why its called "Dynamic Link" library. An Executable (EXE) is a program that can be executed. It has its own entry point. A flag inside the PE header indicates which type of file it is (irrelevant of file extension). The PE header has a field where the entry point for the program resides. In DLLs it isn't used (or at least not as an entry point). Exe assemblies are known as in-process components which were capable of running on their own as well as provide the support for others to execute. When we work with project templates like Windows Forms Applications, Console Applications, WPF Applications and Windows Services they generate an exe assembly when compiled. .exe Has Main Function Dll assemblies are known as out-process components which were not capable of running on their own they can only support others to execute. When we work with project templates like Class Library and Windows Forms Control Library they generate a dll assembly when compiled.

How many types of data types are there in .NET?

The following are the two types of data types available in .NET: ● Value type - Refers to the data type that contains the data. In other words, the exact value or the data is directly stored in this data type. It means that when you assign a value type variable to another variable, then it copies the value rather than copying the reference of that variable. When you create a value type variable, a single space in memory is allocated to store the value (stack memory). Primitive data types, such as int, float, and char are examples of value type variables. ● Reference type - Refers to a data type that can access data by reference. Reference is a value or an address that accesses a particular data by address, which is stored elsewhere in memory (heap memory). You can say that reference is the physical address of data, where the data is stored in memory or in the storage device. Some built-in reference types variables in .Net are string, array, and object.

What does the static keyword mean?

The static keyword is used to define a field or method that will not change across all instances of that class - it defines a class level element that can be accessed without instantiating an object of that class

Explain the characteristics of reference-type variables that are supported in the C# programming language.

The variables that are based on reference types store references to the actual data. The keywords that are used to declare reference types are: 1. Class - Refers to the primary building block for the programs, which is used to encapsulate variables and methods into a single unit. 2. Interface - Contains only the signatures of methods, properties, events, or indexers. 3. Delegate - Refers to a reference type that is used to encapsulate a named or anonymous method.

Why is the virtual keyword used in code?

The virtual keyword is used while defining a class to specify that the methods and the properties of that class can be overridden in derived classes.

Differentiate between Boxing and Unboxing.

When a value type is converted to an object type, the process is known as boxing; When an object type is converted to a value type, the process is known as unboxing. Boxing and unboxing enable value types to be treated as objects. Boxing a value type packages it inside an instance of the Object reference type. This allows the value type to be stored on the garbage collected heap. Unboxing extracts the value type from the object. In this example, the integer variable i is boxed and assigned to object obj. Example: int i = 123; object obj = i; /* This line boxes i. */ /* The object obj can then be unboxed and assigned to integer variable i: */ i = (int)obj; // unboxing

Explain what is meant by a sandbox, why you would use one?

This definition of sandboxing basically means having test environments (developer integration, quality assurance, stage, etc). These test environments mimic production, but they do not share any of the production resources. They have completely separate servers, queues, databases, and other resources. More commonly, I've seen sandboxing refer to something like a virtual machine -- isolating some running code on a machine so that it can't affect the base system.

Advantages of libraries

Time saving Re-usable algorithms (like complex algorithms) Programmers reliant on libraries Reliable as they've been tested frequently Time saving (libraries - algorithms) - Sorting algorithms (Don't have to be reinvented) - Complex algorithms (Processed and reused)

Why is multiple inheritance not supported in Java?

To reduce complexity and simplify the language. If a sub class inherits from two other super classes, and both super classes have the same method and the sub class child object calls that method, then there will be ambiguity between which super class method to call. Since compile-time errors are better than runtime errors, Java renders compile-time error if you inherit 2 classes.

SET NOCOUNT ON statement in SQL

To reduce the amount of network data for each statement that occurs within your stored procedures. Every time a SQL statement is executed it returns the number of rows that were affected. By using "SET NOCOUNT ON" within your stored procedure you can shut off these messages and reduce some of the traffic.

Explain the use of virtual, sealed, override, and abstract.

Virtual keyword, we enforce programmer of derive class to override this function. Sealed make sure that class won't be able to inherit and through. Abstract class, we are able to define methods as abstract to make them must overrideable by child classes and don't let anyone to instantiate it. Virtual - a method that can be overriden in an inheriting class, and the invoked method will be the derived class one. Sealed - means that you can't inherit from a class, often annoying when it's on the BCL. Override - a marker that verify that you indeed override a method and no just create a method with the same name & parameters by mistake Abstract - a method that are not implemented, abstract methods are virtual, and abstract classes are explained above.

What is method overriding?

When a subclass has the same method as declared in the subclass and it provides the specific implementation of the method. Same method with different functionality in another class (Run Time Polymorphism):: Functions with same name and same parameters public class fruit { public virtual getStuff(int id) { //Get stuff default location } } public class apple: fruit { public override getStuff(int id) { //base.getStuff(id); //or - Get stuff new location } }

What is a Windows Service and how does its lifecycle differ from a "standard" EXE?

Windows service is windows-based background process which has no user interface like any other service (aka daemon in UNIX based environment). Windows service needs to be installed before executing unlike EXE. Windows service used to perform such tasks which doesn't required user interaction but system status-based events like performing tasks at specific intervals or at different state of system like alarm user when disk is about to get full to clean up. Windows service is controlled by Service control manager (SCM) and it started automatically even user didn't login to his/her windows account (as SCM already has account credentials so SCM knows if system start which service needs to start and by which account), whereas EXE is controlled by OS and runs only when user get login using windows account. A windows service always runs once the computer starts up (as long as it's so configured). A standard EXE only runs when a user is logged in and will stop if the user logs out.

What is INHERITANCE?

You can create new classes built upon existing classes. When a class inherits from an existing class, it can use the methods and fields from the subclass. An object inherits the properties (states and behaviors) of another. Inheritance represents the IS-A relationship, known as the parent-child relationship. Class is declared by using a base class from which it inherits data and behavior, derived class inherits from the base class. public class Manager : Employee { // Employee fields, properties, methods and events are inherited // New Manager fields, properties, methods and events go here... }

What is the Syntax for inheritance?

class Subclass-name extends Superclass-name { //methods and fields added here } The extends keyword indicates that you are making a new class that derives from an existing class. "Extends" means to increase the functionality.

What is keyword this? Can this be used within a static method?

this keyword points to current object and as static methods can't be invoked through object so The "this" reference refers to the current object context. Static methods have no context, so it is not valid.

Explain the differences between stateless and stateful systems, and impacts of state on parallelism

· A RESTifarian architect thinks in terms of stateless. Their argument is that this is how we find the web world that we live in i.e. HTML lense itself to a stateless solution. Stateful is an attempt to make the smart client paradigm work on the web. I'm guessing that stateless more easily allows for parallelism. A stateful server keeps state between connections. A stateless server does not. So, when you send a request to a stateful server, it may create some kind of connection object that tracks what information you request. When you send another request, that request operates on the state from the previous request. So you can send a request to "open" something. And then you can send a request to "close" it later. In-between the two requests, that thing is "open" on the server. When you send a request to a stateless server, it does not create any objects that track information regarding your requests. If you "open" something on the server, the server retains no information at all that you have something open. A "close" operation would make no sense, since there would be nothing to close. HTTP and NFS are stateless protocols

What are the distinct characteristics of an abstract class?

● You cannot instantiate an abstract class directly. This implies that you cannot create an object of the abstract class; it must be inherited. It can only be extended. ● You can have abstract as well as non-abstract members in an abstract class. ● You must declare at least one abstract method in the abstract class. ● An abstract class is always public. ● An abstract class is declared using the abstract keyword.


Kaugnay na mga set ng pag-aaral

What are the Advantages and Disadvantages of a Command Economy?

View Set

System Analysis and Design - Chapter 10

View Set

Peds - Ch. 50: Alteration in Behavior, Cognition, Development or Mental Health/Cognitive Disorder

View Set

Biologie Chapitre photosynthèse

View Set