Inheritance
--inheritance is a way to form new classes (instances of which are called objects) using classes that have already been defined. Inheritance is employed to help reuse existing code with little or no modification
Super Class
-- superclass allows for a generic interface to include specialized functionality through the use of virtual functions
--a superclass, base class, or parent class is a class from which other classes are derived. The classes that are derived from a superclass are known as child classes, derived classes, or subclasses.
--The superclass mechanism is extensively used in object oriented programming due to the reusability that can be achieved: common features are encapsulated in modular objects. Subclasses that wish to implement special behavior can do so via virtual methods, without having to duplicate (reimplement) the superclass's behavior.
Subclass
--subclass is a class that inherits some properties from its superclass.
Benefits of inheritance
--1. Code reusebility.
2. Minimise the amount of duplicate code.
3. Sharing common code amongst several subclasses.
4. Smaller, simpler and better organisation of code.
5. Make application code more flexible to change.
Overriding Methods
--The ability of a subclass to override a method in its superclass allows a class to inherit from a superclass whose behavior is "close enough" and then override methods as needed.
Polymorphism
--The ability of a reference variable to change behavior according to what object it is holding.–This allows multiple objects of different subclasses to be treated as objects of a single superclass, while automatically selecting the proper methods to apply to a particular object based on the subclass it belongs to.
Abstract Classes
--a class that cannot be instantiated. –often appears at the top of an object-oriented programming class hierarchy, defining the broad types of actions possible with objects of all subclasses of the class
Interface
--is a special kind of block containing method signatures (and possibly constants) only. –defines the signatures of a set of methods, without the body. –defines a standard and public way of specifying the behavior of classes. –allows classes, regardless of their locations in the class hierarchy, to implement common behaviors. –NOTE: interfaces exhibit polymorphism as well, since program may call an interface method, and the proper version of that method will be executed depending on the type of object passed to the interface method call.
Thursday, April 22, 2010
Inheritance,Polymorphism,Interface
Posted by michael_javier at 1:53 AM 0 comments
Monday, April 19, 2010
Working with the java class
Object Oriented Programming
--A type of programming in which programmers define not only the data type of a data structure, but also the types of operations (functions) that can be applied to the data structure. In this way, the data structure becomes an object that includes both data and functions. In addition, programmers can create relationships between one object and another. For example, objects can inherit characteristics from other objects.
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.
Object-oriented programming (OOP) is a programming paradigm that uses "objects" – data structures consisting of datafields 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
Encapsulation
--In programming, the process of combining elements to create a new entity. For example, a procedure is a type of encapsulation because it combines a series of computer instructions. Likewise, a complex data type, such as a record or class, relies on encapsulation. ObjectOriented ProgrammingLanguages rely heavily on encapsulation to create high-level objects. Encapsulation is closely related to abstraction and information hiding.
Classes And Objects
Class Variables
--A class variable is the opposite of instance variable. It is a special type of class member.
In C++ and C#, class variables are declared with the storage class keyword static, and may therefore be referred to as static member variables.
The same dichotomy between instance and class members applies to methods ("member functions") as well; a class may have both instance methods and class methods. Again, C++ and C# use the keyword static to indicate that a method is a class method ("static member function").
Class instantiation
--is the creation of a real instance or particular realization of an abstraction or template such as a class of objects or a computer process. To instantiate is to create such an instance by, for example, defining one particular variation of object within a class, giving it a name, and locating it in some physical place.
In object-oriented programming with classes, a class variable is a variable defined in a class (i.e. a member variable) of which a single copy exists, regardless of how many objects of the class exist.
Method
Method Declaration
--A method's declaration provides a lot of information about the method to the compiler, the runtime system and to other classes and objects. Besides the name of the method, the method declaration carries information such as the return type of the method, the number and type of the arguments required by the method, and what other classes and objects can call the method.
While this may sound like writing a novel rather than simply declaring a method for a class, most method attributes can be declared implicitly. The only two required elements of a method declaration are the method name and the data type returned by the method. For example, the following declares a method named isEmpty() in the Stack class that returns a boolean value (true or false):
Static Methods
--use no instance variables of any object of the class they are defined in. If you define a method to be static, you will be given a rude message by the compiler if you try to access any instance variables. You can access static variables, but except for constants, this is unusual. Static methods typically take all they data from parameters and compute something from those parameters, with no reference to variables. This is typical of methods which do some kind of generic calculation
Parameter Passing
Pass by value
--- In this method value of the variable is passed. Changes made to formal will not affect the actual parameters.
- Different memory locations will be created for both variables
Pass by reference
--In Pass by reference address of the variable is passed to a function. Whatever changes made to the formal parameter will affect to the actual parameters
- Same memory location is used for both variables.(Formal and Actual)-
- it is useful when you required to return more then 1 values
Posted by michael_javier at 2:07 AM 0 comments
Wednesday, April 14, 2010
topics discussed in java1
1.topics discussed in java 1 .provide brief description per topic
-CONTROL STRUCTURES
--1.Decision control structures
-allows us to select specific section of code
--2.Repition control structures
-allow us to execute specific sections of the code a number of times
DECISION CONTROL STRUCTURES
Types:
if - boolean expression or variable
-will be executed if and only if a certain boolean statement is true
example:
- if (boolean_expression)-syntax
statement;
or
-if (boolean_expression){
statement1;
statement2;
}
if-else - used when we want to execute a certain statement if a condition is true, and a different statement if the condition is false.
example:
-if(boolean_expression){
statement1;
statement2;
}
else{
statement3;
statement4;
}
if-else-if - in the else clause of an if- else block can be another if-else structure
- this cascading of structure allows us to make more complex structures
example:
-if(boolean_expression1)
statement1;
else if(boolean_expression2)
statement2;
else
statement3;
ARRAYS- stores multiple data item of the same data type
--index/subscripts-used in access array elements
--begin with zero and progress sequentially by whole numbers to the end of array.
--declaration- int number [];
--instantiate- number = new int [3];
or - int number [] = new int [3];
Two Dimensional Array
int [][]number new int [2][5];
[2] - number of rows
[5] - number of columns
number.length = # of rows
number[0]length = # of columns
METHODS
1.concat()
2.length()
3.IndexOf()
4.LastIndexOf()
5.CharAt()
6.equals()
7.equalsIgnoreCase()
8.StartsWith()
9.endswith()
10.toUpperCase()
11.toLowerCase()
12.replace()
13.Substring()
2.Introduction to java programming
a.HISTORY
-Object Oriented Programming that is receiving wide attention from both industry and academe
-based on c and c++
-originally intended for writting programs
-james gosling at sun microsystem in california in year 1991
-original name of java is "OAK" the name oak come from a tree
b.JAVA TECHNOLOGY
-a.programming language
--can create all kinds of application,create using any conventional programming language
-b.development environment
--provides you w/ a large suite of tools
--computer,interpreter,document generator,class file packaging tool
--2 main development environment
--sdk(software development kit)-basic language,gui componet classes
--web browser-most commercial browser
-c.application environment
--general purpose programs that run at any machine program
-d.deployment environment
c.JAVA FEATURES
-a.java virtual machine
--imaginary machine that is implemented by emulating software on a real machine
-b.garbage collection
--responsible for freeing any memory that can be freed
-c.code security --special machine language that can be understood by the java virtual machine
d.PHASES OF JAVA PROGRAMS
-a.write - making a program or codes
-b.compile - compiling the program using compiler
-c.run - runs the program or debugging the program
e.difference bet. java application and java applets
JAVA APPLICATION - stand alone program that does not require a web browser
JAVA APPLETS- run w/ in a web browser and it is not stand alone
f.what makes java as a oop?
--it received wide attention from both industry and academe
Posted by michael_javier at 12:40 AM 0 comments
