Showing posts with label OOPJava. Show all posts
Showing posts with label OOPJava. Show all posts

Introduction to UML

Introduction of Microsoft Visio.
          
Microsoft Visio is a part of the Microsoft Office Suite of products which consists of Microsoft Word, Microsoft Excel, Microsoft Visio, Microsoft Access and Microsoft Project. Microsoft Visio is a diagramming tool that can be used to visually communicate technical as well as non-technical representations of ideas, processes, concepts, structures, layouts, software models, blueprints, etc. Microsoft Visio eliminates the laborious process of creating diagrams by providing the tools to create complex diagrams in a user friendly manner. Whether you want to create an office layout, a basic flowchart or an organizational structure, you can do it with minimal effort using Microsoft Visio.

What can it do?

Visio is a user friendly tool to create diagrams; hence it can be used by everyone. You do not need to know software programming in order to use Visio. If you know how to use the computer, you can use Visio. Visio can be used in all walks of life. Using Visio, an electrician can create Electrical Diagrams, a student can create a flowchart to understand the process flow, Sales persons can create charts and graphs, Engineers can create Mechanical Engineering diagrams, Managers can create organizational charts and Software programmers can create UML Diagrams and User Interface prototypes. No matter what kind of diagram you need, you can use Visio to create a professional, impressive diagram with minimal effort. Visio can be used by a technical as well as non-technical user to easily create many different kinds of diagrams for documenting and communicating ideas, concepts, blueprints, etc. Some of the different kinds of diagrams that you can create using Visio are:
Flowcharts 
  • Block Diagrams
  • Business Process Diagrams
  • Charts and Graphs
  • Database Models
  • Data Flow Diagrams
  • Electrical Diagrams
  • Mechanical Engineering Diagrams
  • Systems and Network Architecture Diagrams
  • Organizational Charts
  • Gantt Charts
  • User Interface Prototypes
  • Sitemaps for Websites
  • UML Diagrams, etc.
Visio diagrams are compatible with all of the MS Office applications and can be used with word and html documents through the copy paste feature. They can also be used with email programs like Microsoft Outlook and Outlook Express.

2.) What is UML?
UML, or Unified Modeling Language, is a specification language that is used in the software engineering field. It can be defined as a general purpose language that uses a graphical designation which can create an abstract model. This abstract model can then be used in a system. This system is called the UML model. The Object Management group is responsible for defining UML, and they do this via the UML Meta model. XMI can be used to serialize the UML model.

The Unified Modeling Language is commonly used to visualize and construct systems which are software intensive. Because software has become much more complex in recent years, developers are finding it more challenging to build complex applications within short time periods. Even when they do, these software applications are often filled with bugs, and it can take programmers weeks to find and fix them. This is time that has been wasted, since an approach could have been used which would have reduced the number of bugs before the application was completed.

However, it should be emphasized that UML is not limited simply modeling software. It can also be used to build models for system engineering, business processes, and organization structures. A special language called Systems Modeling Language was designed to handle systems which were defined within UML 2.0. The Unified Modeling Language is important for a number of reasons. First, it has been used as a catalyst for the advancement of technologies which are model driven, and some of these include Model Driven Development and Model Driven Architecture.


Unified Modeling Language Characteristics
It must be emphasized that UML is an extensible language. It has two elements that are used for customization, and these are stereotypes and profiles. Much of the semantics for this language were greatly improved with the UML 2.0 update. In 1996, a group of developers came together to create the UML Partners.

It was this collaboration which allowed them to create the Unified Modeling Language. When it was first created, the developers offered it as the response to OMG RFP. While the semantic integration was weak when the language was first introduced it, these problems were fixed with the release of UML 2.0.

Another characteristic of UML is that is borrows many concepts from the object oriented approach. When UML was created, one of the goals of the developers was to create a language that could support every object oriented approach. Some of the features which UML supports includes time analysis, data analysis, object oriented structure design, and state charts. With all these features, UML became the program of choice for professionals who needed to solve various engineering challenges.

Engineers commonly use it for single processes and systems which are distributed. However, UML is not limited to the engineering field. It is useful in any situation where developers need to map out complex systems or processes that can be understood by others.

3.) What is an Object?
            An object is a component of a program that knows how to perform certain actions and to interact with other pieces of the program. Functions have previously been described as "black boxes" that take an input and spit out an output. Objects can be thought of as "smart" black boxes. That is, objects can know how to do more than one specific task, and they can store their own set of data. Designing a program with objects allows a programmer to model the program after the real world. A program can be broken down into specific parts, and each of these parts can perform fairly simple tasks. When all of these simple pieces are meshed together into a program, it can produce a very complicated and useful application.


4.) What is a class?
            A class is an organization of data and functions which operate on them. Data structures are called data members and the functions are called member functions. The combination of data members and member functions constitute a data object or simply an object. Imagine a company that manufactures shoe boxes hires you to write a program that would help design and identify those shoe boxes. A shoe box is recognized for its dimensions (length, width, and height), color, and shoe size that a particular box can contain, etc.

5.) What are models?
When you talk about UML, it is very important to differentiate between the system diagrams and the UML model. A system diagram is a portion of a graphical symbol, and it is used to denote the system's model. The model will have what is called a semantic backplane, and this is a document that is used to deal with the diagrams and elements of a model. There are three areas of the system model that you will want to become familiar with. These are the object model, the functional model, and the dynamic model. Each model has specific roles that it must play for the proper function of the system.

6.) Define OMT.
OMT was developed as an approach to software development. A fundamental assumption of OMT is that object-oriented thinking represents a more natural and intuitive way for people to reason about reality.
The purposes of modeling are,
·       Testing physical entities before building them (simulation),
·       Communication with customers,
·       Visualization (alternative presentation of information), and
·       Reduction of complexity.
OMT proposes three main types of models:

• Object model
The object model represents the static and most stable phenomena in the modeled domain (Rum Baugh et al., 1991:21). Main concepts are classes and associations, with attributes and operations. Aggregation and generalization (with multiple inheritances) are predefined relationships.



•Dynamic model
The dynamic model represents a state/transition view on the model. Main concepts are states, transitions between states, and events to trigger transitions. Actions can be modeled as occurring within states. Generalization and aggregation (concur-rency) are predefined relationships.

•Functional model
The functional model handles the process perspective of the model, corresponding roughly to data flow diagrams. Main concepts are process, data store, data flow, and actors.

The entire OMT software development process has four phases: Analysis, system design, object design, and implementation of the software. Most of the modeling is performed in the analysis phase.


7.) Define Object Model.

            The Object model will be responsible for demonstrating the system structure and substructure, and it will do this by using relationships, attributes, and operations. Class diagrams are closely related to this model.

8.) Define Functional Model.

The functional model will demonstrate the system functionality from the view of the user. It will be directly connected to the use case diagrams. Corresponding roughly to data flow diagrams. Main concepts are process, data store, data flow, and actors.

9.) Define Dynamic Model.

The dynamic model will be responsible for demonstrating inner behavior of a system. It is directly connected to state machine diagrams, sequence diagrams, and activity diagrams.

Diffrence between c & C++ with Constructor & Destructor

Give the difference between C & C++.

           
C
C++
1. Procedure oriented language
1. Object oriented language
2. Standard library include is <stdio.h>
2. Standard library include is <iostream.h>
3. Scanf and printf are used for input and output operation.
3. cin and cout are used for input and output operation.
4. Data is not secured.
4. Data is secured.
5. Programs are divided into smaller  parts called function.
5. Programs are divided into what are known as objects.



 Give difference between Constructor & Destructor.

           
Constructor
Destructor
1. Constructor is special member function use to initialize objects.
1. Destructor is  also special member functions  use of  to release dynamic allocated memory.
2. class rectangle
{              // A simple class
   int height;
   int width;
public:
   rectangle(void);    // with a constuctor,
  };
2. . class rectangle
{              // A simple class
   int height;
   int width;
public:
   ~rectangle(void);   // and a destructor
};
3. Constructor can be overloaded.
3. Destructor can  not be overloaded.
4. Constructor can not be virtual.
4. Destructor can  be virtual.
5.Constructor can have return value
5.Destructor cannot have return value


Concepts of OOP with features

1. W hat is OOP?

Object-oriented programming (OOP) is a programming paradigm that uses "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, modularity, polymorphism, and inheritance. It was not commonly used in mainstream software application development until the early 1990s.[citation needed] Many modern programming languages now support OOP.

An object-oriented program may thus be viewed as a collection of interacting objects, as opposed to the conventional model, in which a program is seen as a list of tasks (subroutines) to perform. In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects and can be viewed as an independent 'machine' with a distinct role or responsibility. The actions (or "operators") on these objects are closely associated with the object. For example, the data structures tend to 'carry their own operators around with them' (or at least "inherit" them from a similar object or class).

One of the principal advantages of object-oriented programming techniques over procedural programming techniques is that they enable programmers to create modules that do not need to be changed when a new type of object is added. A programmer can simply create a new object that inherits many of its features from existing objects. This makes object-oriented programs easier to modify.


2. Explain objects and class with an example.

Objects:
Object is the basic unit of object-oriented programming. Objects are identified by its unique name. An object represents a particular instance of a class. There can be more than one instance of an object. Each instance of an object can hold its own relevant data.
An Object is a collection of data members and associated member functions also known as methods.
Classes:
Classes are data types based on which objects are created. Objects with similar properties and methods are grouped together to form a Class. Thus a Class represents a set of individual objects. Characteristics of an object are represented in a class as Properties. The actions that can be performed by objects become functions of the class and is referred to as Methods.
For example consider we have a Class of Cars under which Santro Xing, Alto and WaganR represents individual Objects. In this context each Car Object will have its own, Model, Year of Manufacture, Colour, Top Speed, Engine Power etc., which form Properties of the Car class and the associated actions i.e., object functions like Start, Move, Stop form the Methods of Car Class.
No memory is allocated when a class is created. Memory is allocated only when an object is created, i.e., when an instance of a class is created.
Differences between struct in C and classes in C++
In C++, a structure is a class defined with the struct keyword.[1] Its members and base classes are public by default. A class defined with the class keyword has private members and base classes by default. This is the only difference between structs and classes in C++.
Classes are declared with the class or struct keyword. Declaration of members are placed within this declaration.
struct person
{
  string name;
  int age;
};
class person
{
public:
  string name;
  int age;
};

Example of class and object:-
#include <iostream>
#include <string>
class person
{
public:
  string name;
  int age;
};
 int main ()
{
  person a, b;
  a.name = "Calvin";
  b.name = "Hobbes";
  a.age = 30;
  b.age = 20;
  cout << a.name << ": " << a.age << endl;
  cout << b.name << ": " << b.age << endl;
  return 0;
}
Executing the above code will output
Calvin: 30
Hobbes: 20


3. Explain following
1.)             Encapsulation:-  Encapsulation is the process of combining data and functions into a single unit called class. Using the method of encapsulation, the programmer cannot directly access the data. Data is only accessible through the functions present inside the class. Data encapsulation led to the important concept of data hiding. Data hiding is the implementation details of a class that are hidden from the user. The concept of restricted access led programmers to write specialized functions or methods for performing the operations on hidden members of the class. Attention must be paid to ensure that the class is designed properly.

2.)             Data Hiding:-  Related to the idea of encapsulation is the concept of data hiding. Encapsulation hides the data from other classes and functions in other classes. This makes programs more reliable, since publishing a specific interface to an object prevents inadvertent access to data in ways that were not designed or accounted for. In C++, the access to an object, and its encapsulated data and functions is treated very carefully, by the use of keywords private, protected, and public.

3.)             Data Abstraction:- Data abstraction is the result of defining classes with emphasis on the similarities of its objects and ignoring their differences. A good abstraction is one that emphasizes details that are significant to us and suppresses details that are not important. A class is an abstraction. Thus, an abstraction focuses on the outside view of the object and clearly separates its essential behavior from the internal implementation details.

1.Emphasizes similarity of objects and ignore their differences
2.Good abstraction emphasizes significant details and ignores unimportant details.
3.Class is abstraction
4. Focuses on outside view of object only.


4.)             Reusability :-      This term refers to the ability for multiple programmers to use the same written and debugged existing class of data. This is a time saving device and adds code efficiency to the language. Additionally, the programmer can incorporate new features to the existing class, further developing the application and allowing users to achieve increased performance. This time saving feature optimizes code, helps in gaining secured applications and facilitates easier maintenance on the application.

The implementation of each of the above object-oriented programming features for C++ will be highlighted in later sections.

5.)             Dynamic Binding :- Binding refers to the linking of a function call to the code to be executed in response to the call. Dynamic Binding means that the code associated with the given function call is not known until the time of call at runtime. A Function call associated with a polymorphic reference depends on dynamic type of that reference. Dynamic binding has two forms, static and dynamic.  Statically-typed dynamic binding is found in languages such as C++ (virtual functions) .  It is not known which function will be called for a virtual function at run-time because a derived class may override the function, in which case the overriding function must be called.  Statically determining all possibilities of usage is undecidable.  When the complete program is compiled, all such functions are resolved (statically) for actual objects.

4. What is inheritance? Explain with example.
Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived class.

For example, a programmer can create a base class named fruit and define derived classes as mango, orange, banana, etc. Each of these derived classes, (mango, orange, banana, etc.) has all the features of the base class (fruit) with additional attributes or features specific to these newly created derived classes. Mango would have its own defined features, orange would have its own defined features, banana would have its own defined features, etc.



#include <iostream.h>
class fruit
{
   public:
  void fruit_color(char *color)
{
     Cout<<”Fruit color is:”<<color;
}    
};
class mango : public fruit
{
};
int main()
{
   Clrscr();
   mango obj;
   obj.fruit_color(“yellow”);
   getch();
}
This concept of Inheritance leads to the concept of polymorphism.
Features or Advantages of Inheritance:
·       Reusability
·       Saves Time and Effort
·       Increases Program Structure which results in greater reliability. Polymorphism 
5. What is Polymorphism? Explain Operator Overloading and function overloading.
            Polymorphism:-  Polymorphism is the ability to use an operator or function in different ways. Polymorphism gives different meanings or functions to the operators or functions. Poly, referring to many, signifies the many uses of these operators and functions. A single function usage or an operator functioning in many ways can be called polymorphism. Polymorphism refers to codes, operations or objects that behave differently in different contexts.
Features and Advantages of the concept of Polymorphism:
·       Applications are Easily Extendable
·       Helps in reusability of code.
·       Provides easier maintenance of applications.
·       Helps in achieving robustness in applications.
Types of Polymorphism:
C++ provides three different types of polymorphism.
·       Virtual functions
·       Function name overloading
·       Operator overloading

Operator Overloading:-      One of the nice features of C++ is that you can give special meanings to operators, when they are used with user-defined classes. This is called operator overloading. You can implement C++ operator overloads by providing special member-functions on your classes that follow a particular naming convention. For example, to overload the + operator for your class, you would provide a member-function named operator+ on your class.
            The following set of operators is commonly overloaded for user-defined classes:
·       = (assignment operator)
·       + - * (binary arithmetic operators)
·       += -= *= (compound assignment operators)
·       == != (comparison operators)

Function Overloading: In function overloading, the function is said to be overloaded when same name is given to different functions. However, the functions will differ at least in any one of the these. The number of parameters, the data type of parameters, the order of appearance these three together are referred to as the function signature. While overloading a function, the return types of the function need not differ.
6.Give the benefits of Object Oriented Programming.
1.     Testability/Increased Quality (automated testing can increase speed of testing and increase quality)
2.     Code re-use (Polymorphism, Generics, Interfaces)
3.     Code extensibility
4.     Catch errors at compile time rather than at runtime.
5.     Maintainability: If designed correctly, any tier of the application can be replaced by another that implements the correct interface(s), and the application will still work (can use multiple user interfaces, can swap out data providers, etc.).
6.     Reduces large problems to smaller, more manageable ones.
7.     Fits the way the real world works. It is easy to map a real world problem to a solution in OO code.
7.Give the features of Object Oriented Programming language.
·       Data encapsulation
·       Data abstraction
·       Inheritance
·       Polymorphism
·       Dynamic or runtime binding
·       Reusability
·       Information hiding.


Write a program to input the no. dynamically and sort the array.

class Sorting
{
            int temp=0,i,j;
            int a[]=new int[15];
            void process()
            {
                        for(i=0;i<5;i++)
                        {
                                    for(j=i+1;j<5;j++)
                                    {
                                                if(a[i]>a[j])
                                                {
                                                            temp=a[i];
                                                            a[i]=a[j];
                                                            a[j]=temp;
                                                }
                                    }                                  
                        }
                        for(i=0;i<5;i++)
                        {
                                    System.out.println(a[i]);
                        }
            }
            public static void main(String arg[])
            {
                        Sorting s=new Sorting();
                        int k;
                        for(k=0;k<5;k++)
                        {
                                    s.a[k] = Integer.parseInt(arg[k]);
                        }
                        s.process();    

            }

Write a program to display prime no. between given two no.

public class Prime
{
            public static void main(String arg[])
            {
                        int n,i,c=0;
                        int a =Integer.parseInt(arg[0]);
                        int b =Integer.parseInt(arg[1]);
                        for(int k =a;k<=b;k++)
                        {
                                    c =0;
                                    for(i=1;i<=k;i++)
                                    {
                                                n=k%i;
                                                if(n==0)
                                                {
                                                            c++;
                                                }
                                    }
                                    if(c == 2)
                                    {
                                                System.out.println(k);
                                    }
                        }
                                               
            }
}





Write a program to make calculator using switch case.

public class Calculator
{
    public static void main(String arg[])
   {
            int n1 =Integer.parseInt(arg[0]);
            int n2 =Integer.parseInt(arg[1]);
            int c =Integer.parseInt(arg[2]);
            switch(c)
            {
                  case 1:  System.out.println("Answer is: "+(n1+n2));
                                    break;
                  case 2:  System.out.println("Answer is: "+(n1-n2));
                                    break;
                  case 3:  System.out.println("Answer is: "+(n1*n2));
                                    break;
                  case 4:  if(n2==0)
                                      {
                                         System.out.println("This value is not allowed.");
                                       }
                                       else
                                      {
                                        System.out.println("Answer is: "+(n1/n2));
                                      }
                                        break;                     
                 default:  {
                                       System.out.println("Invalid entry..");
                                    }                      
                  }
            }
}



Write a program to calculate average of three subject marks and print the grade.

public class Avg
 {
    public static void main(String args[])
     {
                 int avg=0;
                 int mrk1=Integer.parseInt(args[0]);
                 int mrk2=Integer.parseInt(args[1]);
                 int mrk3=Integer.parseInt(args[2]);
                 avg=(mrk1+mrk2+mrk3)/3;
                 System.out.println("the avg of marks are ="+avg);
        if(avg>=90)
                   System.out.println("grade of the student is AA");        
         if(avg>=80)                    
                         System.out.println("grade of the student is AB");  
         if(avg>=70)
                     System.out.println("grade of the student is BB");                  
         if(avg>=60)
                  System.out.println("grade of the student is BC");
         if(avg>=50)
                  System.out.println("grade of the student is CC") ;
         if(avg>=40)
                       System.out.println("grade of the student is CD");                            
         if(avg>=30)
                  System.out.println("grade of the student is DD");         
         if(avg<=29)
                  System.out.println("grade of the student is fail");        
            } 
                       

}