Showing posts with label bads. Show all posts
Showing posts with label bads. Show all posts

Monday, September 12, 2011

Encapsulation in Detail

What is Encapsulation:
Standard definitions says that it a process of wrapping up of data members and methods inside a class with the help of some access specifiers..

private,public and protected.

Private is a type of an access specifier which can be applied to a class, data member,method.
If given to a class then the data members,methods in that class can only access the class which is given as private.

public is type of an access specifier which can again be applied to a class, data members, methods and can be accessed from anywhere in the program.

protected is an other type of access specifier which can again be applied to a class,data members and methods and only the derived classes of that base class can be accessed to the base class which is protected.

Saturday, May 14, 2011

Encapsultaion in General

What is Encapsulation:
Standard definitions says that it a process of wrapping up of data members and methods inside a class with the help of some access specifiers..

private,public and protected.

Private is a type of an access specifier which can be applied to a class, data member,method.
If given to a class then the data members,methods in that class can only access the class which is given as private.

public is type of an access specifier which can again be applied to a class, data members, methods and can be accessed from anywhere in the program.

protected is an other type of access specifier which can again be applied to a class,data members and methods and only the derived classes of that base class can be accessed to the base class which is protected.

Friday, April 29, 2011

A View On C++

C++ is the first OOPs(Object Oriented Programming Language) which was introduced in the Programming world to make the Programming system more easy and understandable.

Object Oriented Programming is an approach to program organization and development that attempts to eliminate some of the pitfalls of conventional programming(C language).

Anyways lets go with some of the concepts of OOPs.
1) Class.
2)Object.
3)Data Abstraction and Encapsulation.
4)Inheritance.
5)Polymorphism
6)Dynamic Binding
7)Message Passing

All the concepts defined above contribute a lot to the object oriented paradigm.
Now lets explain each of the concept in detail..

1.)Class: Class is a reference type or a user defined datatype which refers to a memory location and consists of functions(C++)/methods(JAVA) and data members which are packed inside like a tiffin box :) ...A real time example of a class is just a class in your college where madam/sir are methods and students are data members who act accordingly to the method calls.

2.)Object:Object is an instance of a class(standard definition in any text book :) )...But many of us are confused with this definition...As said earlier Classes contain data members and methods...and we have said that classes are just reference types..Then you may get a doubt that how is memory allocated to this class and how are these data members are manipulated?
Instance is nothing but Space (or) memory.So object can now be defined as "memory allocated for a class" is an object..With the help of this object we are going to manipulate the data members present inside the class.

3.)DataAbstraction and Data Encapsulation: Abstraction refers to the act of representing essential features without including the background details or explanation..In many programs we can see that business logics contain many variables and values assigned to those variables.So after the end of the program a user can only view the UserInterface runnig in different Stages..
But user doest know how that process is implemented..A desktop application is implemented in c++ then when we run that software it only shows the output how we have implemented.But not the code that is written in the back-end.

Data encapsulation works through access specifiers like
Private
Public
Protected
Lets go with these access specifiers in the next tutorial...

SEE YA :)

Thursday, April 21, 2011

Learn "Index" with Example

Index in 7 points :
  1. Index is used for faster retrieval of rows from a table. 
  2. An index can be created explicitly by using the CREATE INDEX statement or implicitly by Oracle.
    The oracle server uses the index to search for a row rather than scanning through the entire table. 
  3. Indexing reduces search time and disk input/output.
  4. Creating and removing an index does not affect the table at all.
  5. When a table is dropped,all indexes based on that table are also removed.
  6. Implicit indexes are created when the primary key or unique constraint is defined. Such indexes get the name of the constraint .
  7. User can create explicit indexes based on non-primary key or non unique columns or on any combination of columns for faster table access.
The general syntax is : 
CREATE INDEX indexname ON tablename(columnname1,columnname1);

By using the above syntax the columns can hold duplicate values. To create unique index,the keyword UNIQUE should be included : 

CREATE UNIQUE INDEX indexname ON tablename(columnname1,columnname1);

EXAMPLE :

CREATE INDEX stu_idx ON student(last,first);
Now suppose we want to see the index for table student :
SELECT index_name, table_name, FROM user_indexes WHERE table_name =
'student';
Exercise :
Create an index to search students faster based on their ID.

CREATE INDEX index02 ON employee24(fname,lname);


Learn "Joins" with Examples(Answers)

create table contact_details02(code_no varchar(30) references emp_master02(emp_no),phone_no number(10),address varchar(30))

emp_master02

branch_master02


1)List the employee details along with branch names to which they belong..

   select * from emp_master02 e inner join branch_master02 b on e.branchno=b.branchno

2)List the employee details of only those employees who belong to the Administration department along with branch names to which they belong.

  select * from emp_master02 e inner join branch_master02 b on e.branchno=b.branchno where e.dept='software'

3)List the employee details along with the contact details using Right outer join.

  select * from contact_details02 c right outer join emp_master02 e on e.emp_no= c.code_no

4)List the employee details along with the contact details using Left outer join.

  select * from contact_details02 c left outer join emp_master02 e on e.emp_no= c.code_no

Learn "JOINS" with Examples(Questions)

EMP_MASTER :

EMP_NO FNAME MNAME LNAME DEPT DESIG BRANCH_NO
BRANCH_MASTER :
NAME BRANCH_NO
CONTACT_DETAIL:
CODE_NO PHONE_NUMBER ADDRESS
  1. List the employee details along with branch names to which they belong..
  2. List the employee details of only those employees who belong to the Administration department along with branch names to which they belong. 
  3. List the employee details along with the contact details using Right outer join. 
  4. List the employee details along with the contact details using Left outer join.

Tuesday, April 12, 2011

Practice -3 (continued)

Simple Example Program on PL/SQL

5) Using Loop

  set serveroutput on
  DECLARE
  v_count number(2);
  v_sum number(2) :=0;
  v_avg number(3,1);
  BEGIN
  v_count := 1;
  loop
  v_sum :=v_sum+v_count;
  v_count :=v_count+1;
  dbms_output.put_line('v_count is'||v_count);
  exit when v_count>10;
  end loop;
  v_avg :=v_sum/10;
  dbms_output.put_line('average is'||v_avg);
  end;

  Output:

   v_count is2
   v_count is3
   v_count is4
   v_count is5
   v_count is6
   v_count is7
   v_count is8
   v_count is9
   v_count is10
   v_count is11
   average is5.5
   PL/SQL procedure successfully completed



6) Cursor
  set serveroutput on
  DECLARE
  v_first employee.fname%type;
  v_lname employee.lname%type;
  v_role employee.role%type;
  cursor employee_cur is
  select fname,lname,role from employee where employee_id='ADM001';
  BEGIN
  if not employee_cur%isopen then
  open employee_cur;
  end if;
  loop
  fetch employee_cur into v_first,v_lname,v_role;
  exit when not employee_cur%found;
  dbms_output.put_line('firstname' || v_first || 'lastname' ||v_lname || 'role' || v_role);
  end loop;
  end;

  Output:

Here we use the same table we have created earlier (employee24)

   fnameAdam lnameEve roleClient
   PL/SQL procedure successfully completed

 
7) Creating a procedure
  create procedure sw_emp9(emp_id in employee.employee_id%type,o_first out employee.fname %type,o_last out employee.lname%type)
  is
  begin
  select fname,lname into o_first,o_last from employee where employee_id=emp_id;
  end;

  Output:

8) Calling a procedure
  declare
  v_fname employee.fname%type;
  v_lname employee.lname%type;
  v_id employee.employee_id%type := '&emp_id';
  begin
  search_emp(v_id,v_fname,v_lname);
  dbms_output.put_line('firstname' || v_fname || 'lastname' ||v_lname);
  end;

  Output:


  old 4: v_id employee24.emp_id%type := '&employee_id';
  new 4: v_id employee24.emp_id%type := 'ADM001';
 

9) Creating a trigger
  create trigger employee_insert_before
  before insert on employee
  for each row
  begin
  dbms_output.put_line('before insert of ');
  end;

  Output:  Trigger created

Practice - 3

Simple Example Program on PL/SQL

1) Simple program

   set serveroutput on
   DECLARE
   num1 number;
   num2 number;
   BEGIN
   num1 := 5;
   num2 :=num1*2;
   dbms_output.put_line('double of num1 is'||num2);
   end;

  Output:  double of num1 is10

2) Calculating the area
   set serveroutput on
  DECLARE
  area number;
  radius number;
  pi constant number := 3.14;
  BEGIN
  radius := 5;
  area := pi*radius*radius;
  dbms_output.put_line('area is'||area);
  end;

  Output:  area is  78.5
 
3) Using IF
  set serveroutput on
  DECLARE
  v_day varchar2(10) :='&day';
  BEGIN
  if(v_day='sunday') then
  dbms_output.put_line('sunday is a holiday');
  else
  dbms_output.put_line('another day');
  end if;
  end;

  Output:
  
old 2: v_day varchar2(10) :='&day'; 
  new 2: v_day varchar2(10) :='mon'; 
  another day 
  PL/SQL procedure successfully completed.

4) Using SELECT
  set serveroutput on
  DECLARE
  v_first employee.fname%type;
  v_lname employee.lname%type;
  v_role employee.role%type;
  BEGIN
  select fname,lname,role into v_first,v_lname,v_role from employee where
  employee_id='ADM001';
 dbms_output.put_line('firstname'||v_first||'lastname'||v_lname||'role'||v_role);
  end;

  Output:
 
To get the output we now first create and insert data into table.
Here we are creating employee24

create table employee24
(
emp_id varchar(20),
fname char(20),
lname char(20),
role char(20)
);

insert into employee24
values
(
'&emp_id',
'&fname',
'&lname',
'&role'
);

select * from employee24

Final Output:

firstnameAdam lastnameEve roleClient
PL/SQL procedure successfully completed.


Practice - 2

1) Create a Pl/SQL block to declare a cursor to select last name,first name,salary and hire date from the Employee table. Retrieve each row from the cursor and print the employee's information if the employee's salary is greater than $50,000 and the hire date is before 31-DEC-1997.
 

Declare
  Cursor cur1 Is
Select lastname,firstname,salary,hiredate;
From emp_tbl02;
Begin
If emp.sal>50000 and hire date<31-dec-1997;
emp_rec  emp_cur1%rowtype;
begin
open emp_cur1;
loop
fetch emp_cur1 into emp_rec;
exit when emp_cur1%notfound;
dbms_output.put_line(emp_rec.firstname||' '||emp_rec.lastname||' '||emp_rec.salary||' '||emp_rec.hiredate);
end loop;
end;

End;


2) Create a cursor named as emp_cur that contains employee's last name,first name,salary and commission. Use the while loop to work with one row at a time. Within the while loop,employee's salary and commission are added together to find the total income. Print the total company wages (the total of all employee salaries and commissions).

declare
cursor emp_cur is
select f_name,l_name,emp_sal,commision from emp_tabl;
emp_rec emp_cur%rowtype;
emp_income number(20);
v_counter number := 1;
cmp_wages number(20) := 0;
begin
open emp_cur;
while(v_counter <= 3) loop
fetch emp_cur into emp_rec;
emp_income := emp_rec.emp_sal + emp_rec.commision;
cmp_wages := cmp_wages + emp_income;
v_counter := v_counter + 1;
end loop;
dbms_output.put_line('cmpny wages are '||cmp_wages);
end;

Wednesday, March 16, 2011

How Open Source works

Going deep into open source now we need to know what is the difference between open source and freeware then we can easily understand how does it work
so, Open source is not necessarily free, and freeware is not necessarily open source: the terms are not, in fact, mutually exchangeable. However, there's a good deal of overlap between the two, and that which is freeware may also happen to be open source.