Pages

Sabtu, 13 Desember 2014



CARA MEMBUAT PERPADUAN LCD + BUTTON + LED PADA PROTEUS DAN PROGRAM PADA CODEVISION AVR 



BERIKUT TAMPILAN PADA PROTEUS

BERIKUT PROGRAM NYA:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 12/6/2014
Author  : jasaevanspg
Company : Usu
Comments: 


Chip type               : ATmega32
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 512
*****************************************************/

#include <mega32.h>
#include <delay.h>
int geser=1;

// Alphanumeric LCD functions
#include <alcd.h>

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTA=0x07;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTB=0x00;
DDRB=0xFF;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTD=0x00;
DDRD=0xFF;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// USART disabled
UCSRB=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;

// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTC Bit 0
// RD - PORTC Bit 1
// EN - PORTC Bit 2
// D4 - PORTC Bit 4
// D5 - PORTC Bit 5
// D6 - PORTC Bit 6
// D7 - PORTC Bit 7
// Characters/line: 8
lcd_init(16);

while (1)
      {
      // Place your code here  
      if(PINA.0==0){      
      lcd_clear();
      lcd_gotoxy(0,0);
      lcd_putsf("SELAMAT NATAL");    
      
      PORTB.0=1;         
      delay_ms(35);     
      PORTB.1=1;   
      delay_ms(35); 
      PORTB.2=1;    
      delay_ms(35); 
      PORTB.3=1;    
      delay_ms(35); 
      PORTB.4=1;    
      delay_ms(35);                    
      PORTB.5=1;    
      delay_ms(35);
      PORTB.6=1;    
      delay_ms(35);  
      PORTB.7=1;    
      delay_ms(35);   
      
      
      PORTD.7=1;    
      delay_ms(35); 
      PORTD.6=1;         
      delay_ms(35);     
      PORTD.5=1;   
      delay_ms(35); 
      PORTD.4=1;    
      delay_ms(35); 
      PORTD.3=1;    
      delay_ms(35); 
      PORTD.2=1;    
      delay_ms(35);                    
      PORTD.1=1;    
      delay_ms(35);
      PORTD.0=1;    
      delay_ms(35);  
               
      
      
      
      }      
      if(PINA.1==0){           
      lcd_clear();
      lcd_gotoxy(0,0);
      lcd_putsf("GOD BLESS US");   
      
      PORTB.0=1;         
      delay_ms(35);     
      //PORTB.1=1;   
      //delay_ms(35); 
      PORTB.2=1;    
      delay_ms(35); 
      //PORTB.3=1;    
      //delay_ms(35); 
      PORTB.4=1;    
      delay_ms(35);                    
      //PORTB.5=1;    
      //delay_ms(35);
      PORTB.6=1;    
      delay_ms(35);  
      //PORTB.7=1;    
      //delay_ms(35);   
      
      
      PORTD.7=1;    
      delay_ms(35); 
      //PORTD.6=1;         
      //delay_ms(35);     
      PORTD.5=1;   
      delay_ms(35); 
      //PORTD.4=1;    
      delay_ms(35); 
      PORTD.3=1;    
      delay_ms(35); 
      //PORTD.2=1;    
      //delay_ms(35);                    
      PORTD.1=1;    
      delay_ms(35);
      //PORTD.0=1;    
      //delay_ms(35);  
               
      }
      if(PINA.2==0){           
      lcd_clear();
      lcd_gotoxy(0,0);
      lcd_putsf("JASA EVAN SPG");         
      PORTD=0xFF;  
      delay_ms(100);    
      PORTB=0xFF;        
      delay_ms(100);          

      }
      else{
      lcd_clear();
      lcd_putsf("MARRY CHRISMAS");
      PORTD=0x00;
      PORTA=0x00;
      
        
      
                    
      
        }       
      }
}


SELAMAT MENCOBA :)

klik disini untuk download source code nya https://www.dropbox.com/sh/5c46tt7mdv6cmp1/AADhukhd-_pdevT1MxE3FQDga?dl=0
Read More

Senin, 29 April 2013

Calculator with html

Calculator from html

" Jasa Evan Sipayung's Calculator"






<html>
  <head>
    <title> Calculator from html    </title>
  </head>
  <body>
       <script language="JavaScript">
          function satu(){
              Calc.Input.value += '1'
          }
          function dua(){
              Calc.Input.value += '2'
          }
          function tiga(){
              Calc.Input.value += '3'
          }
          function empat(){
              Calc.Input.value += '4'
          }
          function lima(){
              Calc.Input.value += '5'
          }
          function enam(){
              Calc.Input.value += '6'
          }
          function tujuh(){
              Calc.Input.value += '7'
          }
          function delapan(){
              Calc.Input.value += '8'
          }
          function sembilan(){
              Calc.Input.value += '9'
          }
          function nol(){
              Calc.Input.value += '0'
          }
          function tambah(){
              Calc.Input.value += '+'
          }
          function kurang(){
              Calc.Input.value +='-'
          }
          function kali(){
              Calc.Input.value += '*'
          }
          function bagi(){
              Calc.Input.value +='/'
          }
          function titik(){
              Calc.Input.value += '.'
          }
          function samadengan(){
              Calc.Input.value = eval(Calc.Input.value)
          }
          function bersih(){
              Calc.Input.value = ''
          }
       </script>
      <form>
          <h4><i><font>
              " Jasa Evan Sipayung's Calculator"
                  </font></i></h4>
      </form>
      <form name="Calc">
      <input type="text" name="Input" size="29">
      </form>
      <form>
          <input type="button" name="one"   value="   1   " onclick="satu()">
          <input type="button" name="one"   value="   2   " OnClick="dua()">
          <input type="button" name="one"   value="   3   " onclick="tiga()">
          <input type="button" name="one"   value="   +   " OnClick="tambah()"><br>
          <input type="button" name="one"   value="   4   " onclick="empat()">
          <input type="button" name="one"   value="   5   " OnClick="lima()">
          <input type="button" name="one"   value="   6   " onclick="enam()">
          <input type="button" name="one"   value="   -    " OnClick="kurang()"><br>
          <input type="button" name="one"   value="   7   " onclick="tujuh()">
          <input type="button" name="one"   value="   8   " OnClick="delapan()">
          <input type="button" name="one"   value="   9   " onclick="sembilan()">
          <input type="button" name="one"   value="   *   " OnClick="kali()"><br>
          <input type="button" name="."     value="   .    " OnClick="titik()">
          <input type="button" name="0"     value="   0   " OnClick="nol()">
          <input type="button" name="="     value="   =   " OnClick="samadengan()">
          <input type="button" name="one"   value="    /   " OnClick="bagi()"><br>
          <input type="button" name="one"   value="                   CLEAR                     "  OnClick="bersih()">
      </form>

  </body>
</html>
Read More →Calculator with html

Jumat, 26 Oktober 2012

Top 5 Network Technology Predictions For 2012


I believe 2012 will be a year of infrastructure simplification and greater visibility. Here I give my top 5 predictions for 2012.

1. OpenFlow networking technology

Vendors will need to have a believable OpenFlow story otherwise Enterprises will look elsewhere in 2012. OpenFlow is an open standard that allows the separation of the data switching path and the software that controls the routing of that packet flow (control path). It is now being added as a feature to commercial Ethernet switches, routers and wireless access points.
At the moment there is a lack of end to end flow visibility and the ability to easily segment and define an end to end path. OpenFlow allows the logical separation of networks thus enhancing security and allows the complete end to end visibility needed to effectively monitor and manage a large IT estate. Network architects will be looking to vendors to have a cohesive, believable story and roadmap in 2012. If they don’t, customers will look elsewhere to vendors that do.

2. Rise of Merchant Silicon

In 2012, these ’good enough’ devices will begin to be used in non-critical network points. Merchant silicon is a marketing term used to describe the use of ‘off the shelf’ chip components to create a networking product. It is changing the rules around who makes what. There will be a real shift towards start-ups and even component makers using merchant silicon to create generic ‘good enough’ switches and routers, which will also be OpenFlow enabled.
As the economic situation worsens, companies will be looking to save more money on purchases and reduce costs. These ‘good enough’ devices will move to general acceptance as the cost benefit becomes apparent. Although these devices are not as fast and feature rich as the top end big vendor routers and switches, most companies do not need either the top end speed or feature bloat that exists in most current networking products.

3. Simplified applications

Companies will stop paying for bloated enterprise applications and go back to basics. A large percentage of enterprise applications feature sets are simply not being used. According to client feedback, only about 10% of application features are being used in any meaningful way.
The revolution enabled by Apple with its easy to use, simple user interface will be carried in to the enterprise as people will demand the ease of use and practicality that Apple and other similar products enable. Users will get rid of larger applications in 2012 and move to simpler applications that do one or very few things simply and easily.

4.  Gamification

This will be big in 2012 as more start-ups use game theory to manipulate enterprise users into following procedure and complete repetitive tasks. Gamification is the integration of game mechanics and game-thinking in non-game environments to boost engagement, loyalty and fun. There will be a real trend towards using ‘compulsion loops’, a form of instant gratification with a move towards more ‘enterprise face’. Help desk staff will be the first ones to see and use this software.

5. Cloud monitoring

Cloud monitoring to allow production to finally move to the cloud. As increasingly more organisations move to the cloud, there will be many new players in cloud monitoring and the management of space. Application to Application data flow is increasingly being looked at to ensure good response times to customers and this trend will increase in 2012.
Simplification and visibility will be the over-arching theme in 2012. Too many companies have complicated IT infrastructures that are under-utilised, with a clear lack of IT visibility. CTOs are often making decisions without hard facts and millions of pounds are lost because IT operating and planning judgments are often taken without understanding the business impact or risk.
Read More →Top 5 Network Technology Predictions For 2012

Rabu, 24 Oktober 2012

Summary of OOP lessons on the 16th of October 2012


.Summary from OOP lessons 16 October 2012.

Some of Access Modifier
  • public : it means able be access to all package
  • private : it means only able access in the class it made before.
  • protective :extends : express the subclass  or  childclass

  • instantiation : is making variable become object with example

new name.variable();
  • inheritance : is degration from parent class to the subclass.
  • abstraction : is making a class
  • polymorphsm : is a decleration object that change or change the form.
  • when we write "public abstract class Aves" : it means can't be a object. it purposes for avoiding a mistake.
  • Constructur : is making the same method to the same class

      the example of methode overloading :  
     public Bird(int v)
       {                   
            super ();
            this.flyVelocity = 0 ; /*contoh konstruktur*/
            System.out.println("kecepatan burung = 7");
         }
     public Bird (String x)
    { super ();
      this.food = null ;
      System.out.println("makanan burung = taik ");
    }

  • its same with methode overloading : but the condition, the signature  must be diffrent. 
  • the example of signature is public (name.variabel like int or string)

   { super (); this.furColor=;
                               }
                         example : public bird (int) with public bird (string)

  • method overwrite : the same methode in the subclass or in the condition must be same
  • we use super for the parents contructur and constructur proccess when the instatiation.


Read More →Summary of OOP lessons on the 16th of October 2012

Selasa, 23 Oktober 2012

10 ways technology will change travel by 2020

The way you travel today will not be the way you travel tomorrow.

IT WAS 2006. I was a freshman. Facebook was huge. Full-length movies streamed instantly to my computer. My cell phone took 1.2 MP pictures.
In other words, technology had never been more advanced.
And that’s just it: by any measurement, we’re constantly living within the most advanced technological era of all time. Yet by the long list of aspirational technologies you’re about to read, you’d never know it.
To an outsider, it must seem like 21st-century humans believe they’re always living a decade or three in the past, and that the future and its inevitable entourage of flying cars, teleportation, and other really cool stuff we haven’t even thought about is as much a part of the human narrative as the fireplace, the automobile, and the internet. Because we believe that the future must bring more powerful technologies (and so far, we’ve been right), the future plays as much a role in how we understand ourselves as the past.
Some of these technologies you may have heard of. Others might seem incredibly far-fetched. But the important thing to realize here is that regardless of whether they ever come to fruition, the mere fact that many people around the world believe these things to be inevitable illustrates just how discontent technology makes us with the present — and also how much we long for constant interaction.
2012
Flying cars – Yes, as in cars…that can fly. Okay, while you might not be the one piloting (or even passengering) the flying car, the engineers at Terrafugia have long been busy perfecting their Lightweight Sport Aircraft (LSA) concept and are currently accepting buyers to the tune of $270,000.
Flying car
Photo: Terrafugia
“The whole idea is to address the gap in travel between 100 and 400 miles,” said Cliff Allen, Terrafugia’s vice president of sales. “You could leave your home or office, drive to the nearest GA [General Aviation] airport, convert over to the aviation mode, fly to the airport nearest your destination and drive the last 10 or 15 miles.”
No word currently on whether you’ll actually be able to drive/fly (I prefer “flive”) your Terrafugia Transition by year’s end, but you can certainly obtain ownership — and odds are good that you’ll be airborne within the next few years.
2013
Speech-to-speech translation – Imagine you’re in India (or, if you are in India, continue being in India). This is a place where foreign languages and dialects are constantly coming together and increasingly demand a translation service. Now imagine that when someone speaks to you in a foreign language, an audio receiver automatically picks up their speech, translates it into your language, and plays it back for you. This is already a reality.
What this means is that within a year or two, you’ll be interacting with foreign languages in an unprecedented way — as puzzles to solve rather than pictures, whole stories to understand. I’m not going to be the one to decide if seamless translation is a good thing…but I do know that no matter how good the technology may be, there will always be that person who has trouble using it.
Superspeed rail more convenient than planes – Planes travel fast. Hundreds of miles per hour. But getting there, checking in, boarding, waiting…I’m not even going to run through it all. Point is: since rail is more efficient, if you could ride an incredibly fast, comfortable train and your door-to-door time was about the same, wouldn’t you prefer it?
Spanish train
Photo: Mikelo
That’s about to be what happens when Deustche Bahn completes and begins its service from London to Germany. Currently, you either need to book a flight from England or take a zig-zagging rail route to get to Berlin. Given the amount of business traffic between London and Germany, it’s likely that other large hubs will begin to see rail as the preferred method of mass transportation — just look at what’s coming in year 2020.
2014
Solar flight – Less than 100 years ago, Charles Lindbergh captured the entire world’s imagination like never before when he completed the first non-stop transatlantic flight from New York to Paris. In two years, we’ll see the completion of the world’s first circumglobal flight powered by nothing more than energy harnessed from the sun. Will anyone notice?
I doubt it. But what happens if the technology becomes cheaper? What if at some point, you can buy your own solar-powered personal flying machine that will get you a few hundred miles for the cost of a Buick?
2015
Self-charging holographic mobile phones – That’s a mouthful. Let’s simplify: first of all, we have had, for a long time, wristwatches that power themselves by the regular motion of the wearer. Today, cell phone companies are already unveiling kinetic motion-powered cell phones…meaning the scourge of battery life may plague you no more.
As for holographic phone calls, this is something just about every major cell phone player is putting R&D money into — I guess people just love that Star Wars scene with Obi-Wan coming out of R2-D2 too much not to make it happen.
So, to recap: charger-free cellphones that project a holographic video of you and the person you’re calling. So what does that mean for travel? Well, let’s say you’re on vacation in Dubai, and your office calls and needs you in a meeting — you won’t go, but your holographic self will. The more we can connect the physical world — even if it’s just a lifelike representation — the less influence geographic boundaries have over us all.
Serious space tourism – The concept of “space tourism” is about as cutting edge as “social networking” these days — we’ve been there, talked about it. But still, we haven’t really seen it aside from Richard Branson’s crazy-billionaire aspirations of taking slightly less wealthy people into space with him.
That’s all definitely going to change, though, because Boeing — an aerospace player who doesn’t mess around — announced that it will bring passenger service into the final frontier beginning 2015.
2016
Glasses
Photo via Pocket-lint
Augmented reality everything – By the end of this year, Google will begin selling augmented reality glasses that stream information in real time onto a user’s eyeball. Which means that finally, you’ll never have to remove your eyes from your Twitter/reddit/Facebook news feed.
Assuming our appetite for more information, more often, as fast as possible doesn’t start to diminish, we can only expect that our visible realities will inevitably become subject to the changes we choose to make upon them. Probably the biggest proponent of this idea is Ray Kurzweil, who discusses how in the future our entire realities will be created through nanobots that “re-engineer” our perceptions of the world around us by communicating directly with the brain.
2017
The locationless classroom – Some of the younger readers might not fully agree with me here, but it’s true: school is awesome. However, the current model of getting dropped off at a turning circle to “learn” between the hours of 8am and 2pm is probably not the end-all-be-all of scholastic efficiency — especially when you consider that nearly 10% of all highschoolers drop out.
Given our steady progression to locationless communication, it only makes sense that we’ll eventually take our schools into the cloud and digital classrooms will be come, at least in some part, the norm. This already happens in towns like Branson, CO, where the official population is only 100 but 850 children actually attend the local school via the internet.
When you combine this idea with the aforementioned holographic cell phone technology, one can envision a future where going to school involves projecting yourself into a virtual classroom environment to study with your other holographic classmates. I’ll say that’s at least a few years down the road, though…
2018
Biometric and electronically enhanced passports – Perhaps the biggest factor keeping people where they come from is not geography, not nostalgia, nor family, but passports. Human will can overcome nearly any physical obstacle — but no amount of wanting can overcome a denied passport at a political border.
So, what will the passport of the future look like? We’ve already begun incorporating RFID chips and other technology into passports — is biometric data the next logical carrier of our identification? And as human screening becomes replaced by technology, we can expect waiting times at passport controls to become incredibly diminished.
At the same time, though, this may be a slippery slope: no data is invulnerable to hacking and manipulation, and as history has unfortunately shown us, an individual’s biological and physical makeup is often the first to become discriminated against.
2019
No driver
Photo via Mental_floss
Self-driving cars – Every time I mention this to someone, they don’t believe me. And then I show them the video of Google’s self-driving car. And mention the fact that the UK has already begun building private roads and corridors for self-driving cars.
Obviously, the main motivation here is safety. It’s the primary difference between cars of today and those of even 10-15 years ago: our cars are immensely more self-aware, and anything that can be done to reduce the more than 30,000+ deaths caused by automobiles (annually in the U.S.) will be a welcome addition to our traveling lifestyle.
2020….and beyond
London to Beijing by rail – About two years ago, China announced plans to develop a rail system to link Beijing with London — thousands and thousands of miles covered in just two days.
The elevator into space – The Japanese engineering and construction firm Obayashi announced this year that they have the ability and intention to set in motion a 36,000km elevator into space, to be completed within forty years.
Today, this sounds impossible. We have never, ever seen a 36,000km structure — manmade or otherwise. But the same was once true for so much of our world that now seems commonplace: skyscrapers, highways, hydroelectric dams. Truly, the past century and a half of unprecedented technological innovation has done more for our imagination than it has for our productivity. For the more we build and achieve, the more we feel inadequate and strive for what was impossible yesterday, but today seems all but inevitable.
Read More →10 ways technology will change travel by 2020

Kamis, 11 Oktober 2012


Chapter 2
The Essence of Objects

So, what exactly is Object Orientation? It is a problem solving technique used to develop software systems. Object orientation is the culmination of years of experience in finding an effective way to develop software, and is certainly the dominant method used to develop major software systems today. Object  orientation is a technique of modeling a real-world system in software based on objects. The object is the core concept. An object is a software model of a real-world entity or concept. Almost anything can be modeled as an object in software. For example, you could model a temperature sensor as an object. Or, in a more abstract system, you could model color as an object. Even something as basic as a number can be considered an object that has a value and a type. Typically, each object has an associated set of attributes such as value, state, or whatever else is needed to model the object. Sensor attributes might include a state such as active or inactive, an attribute indicating its current value, and information about its physical location. Objects usually provide the ability to modify their state as well. In addition to keeping track of the current temperature, for example, a temperature sensor object might provide
a way to turn the sensor on or off. The attributes, or data, used inside an object are really only a tiny part of what an object is and does. An object also has a set of. responsibilities that it carries out by providing services to other
While a program is running, individual objects usually don't stand alone. They belong to a collection of other similar objects that all are members of the same group, or class. A program will be made up of many different classes, each class made up of similar objects.

class A class is a description of a set of objects. The set of objects share common attributes and common behavior. Class is similar in concept to abstract data types found in non- OO programming languages, but is more comprehensive in that it includes both structure and behavior. A class definition describes all the attributes of member objects of that class, as well as the class methods that implement the behavior of member objects.

object The basic unit of object orientation. An object is an entity that has attributes, behavior, and identity. Objects are members of a class, and the attributes and behavior of an object are defined by the class definition.

Classes and objects are closely related, but are not the same thing. A class is a description or definition of the characteristics of objects that belong to that class. An object is a single instance or member of a class that is created and exists while the program is running. A class may have just a single object or any number of member objects existing at any given time. All members of a class have similar behavior. For example, consider a software system used to monitor various sensors in a factory. One obvious kind of object present is such a system is a sensor. A class called Sensor would be defined and used to model physical sensors. The class would define the basic characteristics of any Sensor, such as its location, value, and identification number, as well as a set of services used to carry out its responsibilities.


What Is an Object-Oriented System?

Just what is an object-oriented system? What makes an OO system different than other software systems? One way to define an objectoriented system is to use a list of properties that characterize objectoriented systems. A non-object-oriented system might share some properties such as using abstraction or encapsulation, but will not be built using objects or classes. It is also possible to use an objectoriented language to implement a system using classes or objects, but the system must have all the following properties to be considered a true object-oriented system.

Any object-oriented software system will have the following
properties:
1. Abstraction with objects
2. Encapsulated classes
3. Communication via messages
4. Object lifetime
5. Class hierarchies
6. Polymorphism

The next section gives a brief overview of each of these properties, while the following sections give more detailed explanations of each.

object orientation A method of developing software that uses abstraction with objects, encapsulated classes, communication via messages, object lifetime, class hierarchies, and polymorphism.


Fundamental Properties of an Object-Oriented System

Abstraction with objects

An abstraction is a mechanism that allows a complex, real-world situation to be represented using a simplified model. Object orientation abstracts the real world based on objects and their interactions with other objects. For example, one possible abstraction of a color is the RGB model.

abstraction A model of a real-world object or concept.

Encapsulated classes

The abstractions of related ideas are encapsulated into a single unit. The states and behaviors of the abstraction are incorporated into an encapsulated whole, called a class. The actual internal implementation of the states and behaviors is hidden from the rest of the system. While this not a new programming technique, in OO the encapsulation is an inherent and integral part of the system and design. Earlier, we described a Color class that provided a way to change it red, green, or blue values. In fact, as long as the outside world continues to see and use a Color object in a consistent way, it wouldn't matter just how color is represented internally by the Color object. It could use either the HSV (hue, saturation, value) color model or the RGB model internally, and the outside world would be unaffected. The state and behavior of objects are controlled by welldefined and restricted interfaces to the object. Encapsulation ensures that the internal details of an object are hidden from the rest of the world, that each object maintains its own unique identity and state, and that the state can only be changed by well-defined messages.


encapsulation The process of hiding all the internal details of an object from the outside world. In Java, encapsulation is enforced by having the definitions for attributes and methods inside a class definition.

Interaction via messages

In order to accomplish useful tasks, objects need to interact with other objects. The interaction can be between objects of the same class, or objects of different classes. This interaction is handled by sending messages (in Java, this is done by calling methods) to other objects to pass information or request action. For example, when a user selects a command button in a dialog box on the screen by clicking the mouse, a message is sent to the dialog object notifying it that the command button was pressed. Messages can be used to change the state of an object or to request an action by the object.

Object lifetime

All objects have a lifetime. They are created and initialized as they are needed during program execution, exist and carry out their functions, and are eventually destroyed. While objects exist, they maintain their own identity and state. Many objects that are instances of the same class can exist at any given time. Each object has a unique identity, and will have attributes that are different from other instances of objects in the same class.

Class hierarchies

In an OO design, classes of objects are arranged into hierarchies that model and describe relationships among the classes. The simplest relationship is an association. For example, there could be an employment association between a person and a company. These simple associations exist between different classes.
A second way to use a hierarchy is to define more specialized classes based on a pre-existing generalized class. For example, a dialog class can be considered a specialized case of a more general window class. The more specialized class will automatically share the attributes of the more general class (e.g., size and screen position), and will probably add new attributes and behaviors to the generalized class (e.g., associated control objects). This kind of hierarchy is called inheritance.




Polymorphism

Polymorphism is the final fundamental characteristic of objectoriented systems. When inheritance is used to extend a generalized class to a more specialized class, it will usually include extending some of the behaviors of the generalized class. The specialized class will often implement a behavior that is somewhat different than the generalized class, but the name used to define the behavior will be the same. It is important that a given instance of an object use the correct behavior, and the property of polymorphism allows this to happen automatically and seamlessly. Polymorphism is actually easier to use than it is to explain.

Abstraction with Objects

Abstraction is one of the basic tools of all programming, not just OO programming. When trying to write a program to solve some real world problem, abstraction serves as a way model the real world problem. For example, if you were trying to write an address book program, you would use abstractions such as names, addresses, phone numbers, alphabetical order, and other concepts associated with an address book.

Encapsulated Classes

Encapsulation is one of the most important aspects of OO. It is what allows each object to be independent. The exact implementation of attributes and of object behavior is hidden from the rest of the world through encapsulation. The class definition is the main programming tool that is used to implement encapsulation. A class is a description of a collection of objects with common attributes, behavior, and responsibilities. The definition or specification of a class includes the definitions of the attributes comprising the state, the methods that carry out the responsibilities of the class by implementing the behavior, and how to set the initial attribute state of an object. A class is identified by a name.

As long as you maintain a well-defined interface to the rest of the world, you can easily modify your class definition without breaking the rest of the system.

attribute Used to hold state information of an object. An attribute might be as simple as an on or off boolean variable, or it might be a complex structure such as another object. A class definition describes the attributes and operations (methods) of a class.
behavior The activity of an object that is visible to the outside world. Includes how an object responds to messages by changing its internal state or returning state information to other objects.

method An operation or service performed upon an object, defined as part of the declaration of a class. Methods are used to implement object behavior. Synonyms for method include member function, operation, and service.

state State reflects the current values of all the attributes of a given object, and is the result of the behavior of an object over time.

Java programs are defined as collections of classes. Normally each Java class is defined in a separate file. The attributes of a class are defined by the declaration of variables of various types such as int or boolean. A Java class includes the definitions of the methods used to implement the behaviors of the class. The method definitions are integral parts of the class definition.

Communication via messages

Messages are how objects communicate with each other. Any object may send a message to other objects, and it may receive messages from other objects. In practical programming terms, sending a message is accomplished by invoking or calling some class method, and receiving a message is accomplished by having a class method called by a different object. Usually, a message is sent by a method call as a normal part of the execution of the program logic of an object. However, messages may also originate from the operating system interface or language runtime system. Consider an object that implements a dialog interface with a user. When the user clicks on a button, a message is sent to the dialog object or button handler telling it that a specific button has been pressed (the implementation specifics aren't important).

Object orientation is a natural for this kind of programming. In an OO program, what you often end up with is a set of objects that can respond to a set of messages originating from a variety of sources such as a mouse click, a sensor value change, or a data base transaction. Individual encapsulated objects can respond to messages and send their own messages to others objects in response. Objects in the system interact via well-defined messages with other objects in the system.

Object Lifetime

Objects are dynamic entities. They are created on an as-needed basis during program execution. When an object is created, it is instantiated, or bound to the class definition. An instantiated member of a class is called an object, or equivalently an instance. When a new object first comes into existence, a special method called the constructor is automatically invoked by the run-time system. The constructor is responsible for giving an instance its initial state. Once an object has been created, it can receive and send messages. To get an idea of object lifetime, consider graphical user interface (GUI) classes such as the Swing library provided with Java. One type of object included in a GUI is a dialog interface. Upon some action by the user, say selecting a menu item, a given dialog object will be created. As part of the creation process, its constructor will be called.

When the user closes the dialog, the dialog object will no longer be needed. Once it no longer has any references to it, it can be garbage collected by the Java run-time.

constructor An operation that creates an object and defines its initial state. For complex objects, construction can be a significant activity, and cause the constructors of other objects to be invoked as well.
garbage collection The automatic detection and freeing of memory that is no longer in use. An object becomes available for garbage collection when it is no longer referred to by any other object. Java uses garbage collection rather than explicit destructors found in other OO languages such as C++.
reference A data element whose value is an address. In Java, all objects are accessed by reference. Any object variable will be a reference to an actual object, and not the object itself.
identity The characteristics or state of an object that allows it to be distinguished from other objects.
instance A specific object that is an instantiation of a class. An instance has specific attributes and behaviors, and a unique identity. Instance and object are often used interchangeably.
instantiation Creating an instance of an object of a given class. Instantiating an instance brings it into existence.
object lifetime The time an object exists - from its instantiation in its constructor until the object no longer exists and has been finalized by the Java garbage collector. The creation point of an object is under program control, but the exact moment when an object ceases to exist cannot be determined because of the way the Java garbage collector works. Basic UML Class Notation The basic UML notation for a class is a rectangle with three horizontal parts. The top part is used to hold the name of the class.  Associations are shown by lines between classes, and are usually labeled with the name of the association. Inheritance is shown by a line with a triangular arrow pointing to the more general class (the superclass). Aggregation is shown by a line with a hollow diamond pointing to the whole class, while composition uses a solid diamond instead.


Figure 2-4.
An animal Generalization/Specialization Hierarchy

Note that the UML uses an open arrowhead pointing to the more general class to show inheritance. Thus, in Figure 2-4 of the animal hierarchy, a Mammal inherits from Animal, and so on.

UML: You can show more or less detail in UML diagrams depending which information you want to concentrate on. For example, since Figure 2-4 is mainly focused on the inheritance relationships, and it doesn't show the attribute or operation boxes. We will use this same diagram in Figure 2-5, but show more detail, including some selected operations.

Many discussions of object orientation will give special emphasis to programming with inheritance, but in fact, both aggregation and inheritance are important parts of object-oriented programming. Both kinds of hierarchies are used to design programs that reflect the characteristics of the problem being modeled. Any class can be defined using a combination of both kinds of hierarchy.

default behaviors In an inheritance hierarchy, the class behaviors defined by superclasses that will be used by default unless they are overridden by some subclass.

derived In an inheritance hierarchy, a subclass is derived from a superclass. The derived subclass inherits the attributes and methods of the parent superclass.

generalization/specialization An inheritance hierarchy. Each subclass is a specialization of a more generalized superclass.

implements In Java, a specification that the class will implement the code required by an interface.

inheritance A mechanism that allows one class (subclass) to share the attributes and behaviors of another class (superclass). Inheritance defines an is-a relationship between classes. The subclass or derived class inherits the attributes and behaviors of the superclass, and will usually extend or modify those attributes and behaviors.

interface In Java, an interface is a specification of methods a class using the interface must implement. An interface is a specification, and does not define any code. It provides an alternative to multiple inheritance.

is-a A term used in inheritance hierarchies. In general, a
subclass is-a specialized kind of a more general superclass.
Primate
 
Rodent
 
Carnivore
 
Mammal
 

is-a test A simple test to check for proper inheritance design. If
you cannot say a subclass is-a kind of the superclass, then
inheritance is probably not appropriate.

















multiple inheritance When a subclass is derived from multiple superclasses, it is said to have single inheritance. Java does not allow multiple inheritance, but provides interfaces as an alternative.

overriding When a subclass specifies an alternative definition for an attribute or method of its superclass, it is overriding the definition in the superclass. Also called overloading. Java can only overload methods.

root class The top most or most generalized user class of an inheritance hierarchy. In Java, all classes are at least implicitly derived from the Java Object class, which make it the most primitive root class. Most applications will have many hierarchies with different non-Object root classes.

single inheritance When a subclass is derived from a single superclass, it is said to have single inheritance.

subclass In an inheritance hierarchy, a subclass is derived from an associated superclass. A subclass is a specialization of the generalized superclass.

superclass In an inheritance hierarchy, a superclass is a more generalized class. A subclass will be derived from a superclass. (A superclass is also known as a parent class or a base class.)


Read More