0% found this document useful (0 votes)
50 views14 pages

What Is An Object?

Object-oriented programming uses objects to model real-world items that have state and behavior. An object's state is represented by its properties and an object's behavior is represented by its methods. Classes define the blueprint for objects with similar state and behavior. Inheritance allows subclasses to extend existing classes, reusing their implementation and adding more specific features. Interfaces define common behaviors without providing implementation.

Uploaded by

nds9111992
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views14 pages

What Is An Object?

Object-oriented programming uses objects to model real-world items that have state and behavior. An object's state is represented by its properties and an object's behavior is represented by its methods. Classes define the blueprint for objects with similar state and behavior. Inheritance allows subclasses to extend existing classes, reusing their implementation and adding more specific features. Interfaces define common behaviors without providing implementation.

Uploaded by

nds9111992
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

What Is an Object?

Objects are key to understanding object-oriented technology. Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle. Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming. Take a minute right now to observe the real-world objects that are in your immediate area. For each object that you see, ask yourself two questions: "What possible states can this object be in?" and "What possible behavior can this object perform?". Make sure to write down your observations. As you do, you'll notice that real-world objects vary in complexity; your desktop lamp may have only two possible states (on and off) and two possible behaviors (turn on, turn off), but your desktop radio might have additional states (on, off, current volume, current station) and behavior (turn on, turn off, increase volume, decrease volume, seek, scan, and tune). You may also notice that some objects, in turn, will also contain other objects. These real-world observations all translate into the world of objectoriented programming.

What Is a Package?
A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages.

The Java platform provides an enormous class library (a set of packages) suitable for use in your own applications. This library is known as the "Application Programming Interface", or "API" for short. Its packages represent the tasks most commonly associated with general-purpose programming. For example, a String object contains state and behavior for character strings; a File object allows a programmer to easily create, delete, inspect, compare, or modify a file on the filesystem; a Socket object allows for the creation and use of network sockets; various GUI objects control buttons and checkboxes and anything else related to graphical user interfaces. There are literally thousands of classes to choose from. This allows you, the programmer, to focus on the design of your particular application, rather than the infrastructure required to make it work. The Java Platform API Specification contains the complete listing for all packages, interfaces, classes, fields, and methods supplied by the Java SE platform. Load the page in your browser and bookmark it. As a programmer, it will become your single most important piece of reference documentation.

What Is a Class?
In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created. The following Bicycle class is one possible implementation of a bicycle:
class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changeCadence(int newValue) { cadence = newValue; } void changeGear(int newValue) { gear = newValue; } void speedUp(int increment) {

speed = speed + increment; } void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { System.out.println("cadence:" + cadence + " speed:" + speed + " gear:" + gear); } }

The syntax of the Java programming language will look new to you, but the design of this class is based on the previous discussion of bicycle objects. The fields cadence,speed, and gear represent the object's state, and the methods (changeCadence, changeGear, speedUp etc.) define its interaction with the outside world. You may have noticed tha

t the Bicycle class does not contain a main method. That's because it's not a complete application; it's just the blueprint for bicycles that might beused in an application. The responsibility of creating and using new Bicycle objects belongs to some other class in your application. Here's a BicycleDemo class that creates two separate Bicycle objects and invokes their methods:
class BicycleDemo { public static void main(String[] args) { // Create two different // Bicycle objects Bicycle bike1 = new Bicycle(); Bicycle bike2 = new Bicycle(); // Invoke methods on // those objects bike1.changeCadence(50); bike1.speedUp(10); bike1.changeGear(2); bike1.printStates(); bike2.changeCadence(50); bike2.speedUp(10); bike2.changeGear(2); bike2.changeCadence(40); bike2.speedUp(10); bike2.changeGear(3); bike2.printStates(); } }

The output of this test prints the ending pedal cadence, speed, and gear for the two bicycles:
cadence:50 speed:10 gear:2 cadence:40 speed:20 gear:3

What Is Inheritance?
Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles

have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass ofMountainBike, RoadBike, and TandemBike. In the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses:

A hierarchy of bicycle classes.

The syntax for creating a subclass is simple. At the beginning of your class declaration, use the extends keyword, followed by the name of the class to inherit from:
class MountainBike extends Bicycle { // new fields and methods defining // a mountain bike would go here }

This gives MountainBike all the same fields and methods as Bicycle, yet allows its code to focus exclusively on the features that make it unique. This makes code for your subclasses easy to read. However, you must take care to properly document the state and behavior that each superclass defines, since that code will not appear in the source file of each subclass.

What Is Inheritance?

Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass ofMountainBike, RoadBike, and TandemBike. In the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses:

A hierarchy of bicycle classes.

The syntax for creating a subclass is simple. At the beginning of your class declaration, use the extends keyword, followed by the name of the class to inherit from:
class MountainBike extends Bicycle { // new fields and methods defining // a mountain bike would go here }

This gives MountainBike all the same fields and methods as Bicycle, yet allows its code to focus exclusively on the features that make it unique. This makes code for your subclasses easy to read. However, you must take care to properly document

the state and behavior that each superclass defines, since that code will not appear in the source file of each subclass.

What Is an Interface?
As you've already learned, objects define their interaction with the outside world through the methods that they expose. Methods form the object's interface with the outside world; the buttons on the front of your television set, for example, are the interface between you and the electrical wiring on the other side of its plastic casing. You press the "power" button to turn the television on and off. In its most common form, an interface is a group of related methods with empty bodies. A bicycle's behavior, if specified as an interface, might appear as follows:
interface Bicycle { // wheel revolutions per minute void changeCadence(int newValue); void changeGear(int newValue); void speedUp(int increment); void applyBrakes(int decrement); }

To implement this interface, the name of your class would change (to a particular brand of bicycle, for example, such as ACMEBicycle), and you'd use the implementskeyword in the class declaration:
class ACMEBicycle implements Bicycle { // remainder of this class // implemented as before }

Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile. Note: To actually compile the ACMEBicycle class, you'll need to add the public keyword to the beginning of the implemented interface methods. You'll

learn the reasons for this later in the lessons on Classes and Objects and Interfaces and Inheritance.

C++, as the name suggests, is a superset of C. As a matter of fact, C++ can run most of C code while C cannot run C++ code. Here are the 10 major differences between C++ & C 1. C follows the procedural programming paradigm while C++ is a multiparadigmlanguage(procedural as well as object oriented) In case of C, importance is given to the steps or procedure of the program while C++ focuses on the data rather than the process. Also, it is easier to implement/edit the code in case of C++ for the same reason. 2. In case of C, the data is not secured while the data is secured(hidden) in C++ This difference is due to specific OOP features like Data Hiding which are not present in C. 3. C is a low-level language while C++ is a middle-level language (Relatively, Please see the discussion at the end of the post) C is regarded as a low-level language(difficult interpretation & less user friendly) while C++ has features of both low-level(concentration on whats going on in the machine hardware) & high-level languages(concentration on the program itself) & hence is regarded as a middle-level language. 4. C uses the top-down approach while C++ uses the bottom-up approach In case of C, the program is formulated step by step, each step is processed into detail while in C++, the base elements are first formulated which then are linked together to give rise to larger systems. 5. C is function-driven while C++ is object-driven Functions are the building blocks of a C program while objects are building blocks of a C++ program. 6. C++ supports function overloading while C does not Overloading means two functions having the same name in the same program. This can be done only in C++ with the help of Polymorphism(an OOP feature) 7. We can use functions inside structures in C++ but not in C. In case of C++, functions can be used inside a structure while structures cannot contain functions in C.

8. The NAMESPACE feature in C++ is absent in case of C C++ uses NAMESPACE which avoid name collisions. For instance, two students enrolled in the same university cannot have the same roll number while two students in different universities might have the same roll number. The universities are two different namespace & hence contain the same roll number(identifier) but the same university(one namespace) cannot have two students with the same roll number(identifier) 9. The standard input & output functions differ in the two languages C uses scanf & printf while C++ uses cin>> & cout<< as their respective input & output functions 10. C++ allows the use of reference variables while C does not Reference variables allow two variable names to point to the same memory location. We cannot use these variables in C programming. MORE 11. C++ supports Exception Handling while C does not. C does not support it formally but it can always be implemented by other methods. Though you dont have the framework to throw & catch exceptions as in C++.

Here are the major differences between C And JAVA. 1. JAVA is Object-Oriented while C is procedural. Different Paradigms, that is. Most differences between the features of the two languages arise due to the use of different programming paradigms. C breaks down to functions while JAVA breaks down to Objects. C is more procedure-oriented while JAVA is data-oriented. 2. Java is an Interpreted language while C is a compiled language. We all know what a compiler does. It takes your code & translates it into something the machine can understand-that is to say-0s & 1s-the machine-level code. Thats exactly what happens with our C code-it gets compiled. While with JAVA, the code is first transformed to what is called the bytecode. This bytecode is then executed by the JVM(Java Virtual Machine). For the same reason, JAVA code is more portable. 3. C is a low-level language while JAVA is a high-level language. C is a low-level language(difficult interpretation for the user, closer significance to the machine-level code) while JAVA is a high-level lagunage(abstracted from the machinelevel details, closer significance to the program itself).

4. C uses the top-down {sharp & smooth} approach while JAVA uses the bottom-up {on the rocks} approach. In C, formulating the program begins by defining the whole and then splitting them into smaller elements. JAVA(and C++ and other OOP languages) follows the bottom-up approach where the smaller elements combine together to form the whole. 5. Pointer go backstage in JAVA while C requires explicit handling of pointers. When it comes to JAVA, we dont need the *s & &s to deal with pointers & their addressing. More formally, there is no pointer syntax required in JAVA. It does what it needs to do. While in JAVA, we do create references for objects. 6. The Behind-the-scenes Memory Management with JAVA & The User-Based Memory Management in C. Remember malloc & free? Those are the library calls used in C to allocate & free chunks of memory for specific data(specified using the keyword sizeof). Hence in C, the memory is managed by the user while JAVA uses a garbage collector that deletes the objects that no longer have any references to them. 7. JAVA supports Method Overloading while C does not support overloading at all. JAVA supports function or method overloading-that is we can have two or more functions with the same name(with certain varying parameters like return types to allow the machine to differentiate between them). That it to say, we can overload methods with the same name having different method signatures. JAVA(unlike C++), does not support Operator Overloading while C does not allow overloading at all. 8. Unlike C, JAVA does not support Preprocessors, & does not really them. The preprocessor directives like #include & #define, etc are considered one of the most essential elements of C programming. However, there are no preprocessors in JAVA. JAVA uses other alternatives for the preprocessors. For instance, public static final is used instead of the #define preprocessor. Java maps class names to a directory and file structure instead of the #include used to include files in C. 9. The standard Input & Output Functions. Although this difference might not hold any conceptual(intuitive) significance, but its maybe just the tradition. C uses the printf & scanf functions as its standard input & output while JAVA uses the System.out.print & System.in.read functions. 10. Exception Handling in JAVA And the errors & crashes in C. When an error occurs in a Java program it results in an exception being thrown. It can then be handled using various exception handling techniques. While in C, if theres an error, there IS an error.

Advantages of Java
Java has significant advantages over other languages and environments that make it suitable for just about any programming task. The advantages of Java are as follows: Java is easy to learn. Java was designed to be easy to use and is therefore easy to write, compile, debug, and learn than other programming languages. Java is object-oriented. This allows you to create modular programs and reusable code. Java is platform-independent. One of the most significant advantages of Java is its ability to move easily from one computer system to another. The ability to run the same program on many different systems is crucial to World Wide Web software, and Java succeeds at this by being platform-independent at both the source and binary levels. Because of Java's robustness, ease of use, cross-platform capabilities and security features, it has become a language of choice for providing worldwide Internet solutions.

Router Support for Fine-Grained Latency Measurements projects 2012


June 30, 2012 admin No comments

projects 2012 Router Support for Fine-Grained Latency Measurements projects 2012 Projects 2012 Java Networking Technology Used: Java ABSTRACT An increasing number of datacenter network applications, including automated trading and high-performance computing, have stringent end-to-end latency requirements where even microsecond variations may be intolerable. The resulting finegrained measurement demands cannot be met effectively by existing technologies, such as SNMP, NetFlow, or active probing. Instrumenting routers with a hash-based primitive has been proposed that called as Lossy Difference Aggregator

(LDA) to measure latencies down to tens of microseconds even in the presence of packet loss. Because LDA does not modify or encapsulate the packet, it can be deployed incrementally without changes along the forwarding path. When compared to Poisson-spaced active probing with similar overheads, LDA mechanism delivers orders of magnitude smaller relative error. Although ubiquitous deployment is ultimately desired, it may be hard to achieve in the shorter term. AIM To measure the latency accurately, to propose a method, LDA (Lossy Difference Aggregator), which accurately measures loss and delay over short timescales while providing strong bounds. EXISTING SYSTEM v v Current routers typically support two distinct accounting mechanisms: SNMP and NetFlow. Operators of latency-critical networks are forced to use external monitoring mechanisms in order to collect a sufficient

number of samples to compute accurate estimates. The simplest technique is to send end-to-end probes across the network. v v Latency estimates computed in this fashion, however, can be grossly inaccurate in practice. Unfortunately, placing hardware monitors between every pair of input and output ports is cost-prohibitive in many

instances. Disadvantages v v v SNMP and NetFlow are not up to the task. SNMP provides only cumulative counters that, while useful to estimate load, cannot provide latency estimates. NetFlow, on the other hand, samples and timestamps a subset of all received packets; calculating latency requires

coordinating samples at multiple routers (e.g., trajectory sampling). v In NetFlow, Samples and their timestamps have to be communicated to a measurement processor that subtracts the sent

timestamp from the receive timestamp of each successfully delivered packet in order to estimate the average, a procedure with fundamentally high space complexity. v High NetFlow sampling rates significantly impact routers forwarding performa nce and are frequently incompatible

with operational throughput demands. PROPOSED SYSTEM v Lossy Difference Aggregator (LDA), fine-grain latency and loss measurement that can be cheaply incorporated within

routers. v LDA accurately measures loss and delay over short timescales while providing strong bounds on its estimates, enabling

operators to detect short-term deviations from long-term means within arbitrary confidence levels. Active probing requires 5060 times as much bandwidth to deliver similar levels of accuracy. v Operators can use a classifier to configure an LDA to measure the delay of particular traffic classes to differing levels of

precision, independent of others.

Advantages v v A low-overhead mechanism Fine-granularity measurement

Posted in: Networking

You might also like