The Great Symbian

Anything under the sun goes here!

Showing posts with label IT 231. Show all posts
Showing posts with label IT 231. Show all posts

INHERITANCE
–As the name inheritance suggests an object is able to inherit characteristics from another object. In more concrete terms, an object is able to pass on its state and behaviors to its children. For inheritance to work the objects need to have characteristics in common with each other.

In Java, all classes, including the classes that make up the Java API, are subclassed from the Object superclass.

● Superclass
– Any class above a specific class in the class hierarchy.

● Subclass
– Any class below a specific class in the class hierarchy.

● Benefits of Inheritance in OOP : Reusability
– Once a behavior (method) is defined in a superclass, that behavior is automatically inherited by all subclasses.

– Thus, you can encode a method only once and they can be used by all subclasses.

– A subclass only needs to implement the differences between itself and the parent.

● Overriding Methods
– If for some reason a derived class needs to have a different implementation of a certain method from that of the superclass, overriding methods could prove to be very useful.

– A subclass can override a method defined in its superclass by providing a new implementation for that method.


●Final Classes
– Classes that cannot be extended
– To declare final classes,

we write,

public final ClassName{
. . .

}
● Final Methods
– Methods that cannot be overridden
– To declare final methods,
we write,

public final [returnType] [methodName]([parameters])
{
. . .
}
– Static methods are automatically final.
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 Class
– 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.






A. PRIMITIVE DATA TYPES
- Integral Data Types (byte, short, int long)
- Floating Point (float, double)
- Characters (char, string)
- Boolean (true, false)



B. VARIABLES
A variable is an item of data used to store state of objects.

1. Declaring and Initializing Variables
To declare a variable is as follows,
[=initial value];

2. Outputting Variable Data
In order to output the value of a certain variable, we can use the following commands,
System.out.println()
System.out.print()



C. OPERATORS

1 Arithmetic operators
+, *, /, %, -

2 Increment and Decrement operators
++, --

3 Relational operators

Relational operators compare two values and determines the relationship between those
values. The output of evaluation are the boolean values true or false.
>, >=, <, <=, ==, != 4 Logical operators
Logical operators have one or two boolean operands that yield a boolean result. There
are six logical operators: && (logical AND), & (boolean logical AND), (logical OR),
(boolean logical inclusive OR), ^ (boolean logical exclusive OR), and ! (logical NOT).



D. GETTING INPUT FROM THE KEYBOARD

1. Using buffered reader
·Add this at the top of your code:

import java.io.*;

·Add this statement:

BufferedReader dataIn = new BufferedReader(
new InputStreamReader( System.in) );

· Declare a temporary String variable to get the input, and invoke the readLine()
method to get input from the keyboard. You have to type it inside a try-catch block.

try{
String temp = dataIn.readLine();
}
catch( IOException e ){
System.out.println(“Error in getting input”);
}



2. Using JOptionPane

import javax.swing.JOptionPane;
indicates that we want to import the class JOptionPane from the javax.swing package.
We can also write this as,
import javax.swing.*;
The statement,
name = JOptionPane.showInputDialog("Please enter your name");
creates a JOptionPane input dialog, which will display a dialog with a message, a
textfield and an OK button as shown in the figure. This returns a String which we will
save in the name variable.



E. CONTROL STRUCTURES

1. Decision Control Structures
Decision control structures are Java statements that allows us to select and execute
specific blocks of code while skipping other sections.

· if statement
if( boolean_expression )
statement;

· if-else statement
if( boolean_expression )
statement;
else
statement;

· if-else-if statement
if( boolean_expression1 )
statement1;
else if( boolean_expression2 )
statement2;
else
statement3;

· switch statement
switch( switch_expression ){
case case_selector1:
statement1; //
statement2; //block 1
. . .
//
break;
case case_selector2:
statement1; //
statement2; //block 2
. . .
//
break;
. . .
default:
statement1; //
statement2; //block n
. . .
//
break;
}

2. Repetition Control Structures
Repetition control structures are Java statements that allows us to execute specific
blocks of code a number of times. There are three types of repetition control structures,
the while, do-while and for loops.

·while loop

The while statement has the form,
while( boolean_expression ){
statement1;
statement2;
. . .
}

· do-while loop
The do-while statement has the form,
do{
statement1;
statement2;
. . .
}while( boolean_expression );


· for loop
The for loop has the form,
for (InitializationExpression; LoopCondition; StepExpression){
statement1;
statement2;
. . .
}




F. Java Arrays

1. Declaring Arrays

Arrays must be declared like all variables. When declaring an array, you list the data
type, followed by a set of square brackets[], followed by the identifier name. For
example,
int []ages;
or you can place the brackets after the identifier. For example,
int ages[];
After declaring, we must create the array and specify its length with a constructor
statement. This process in Java is called instantiation (the Java word for creates). In
order to instantiate an object, we need to use a constructor for this. We will cover more
about instantiating objects and constructors later. Take note, that the size of an array
cannot be changed once you've initialized it. For example,
//declaration
int ages[];
//instantiate object
ages = new int[100];
or, can also be written as,
//declare and instantiate
object
int ages[] = new
int[100];

2. Accessing an array element
To access an array element, or a part of the array, you use a number called an index or
a subscript.

3. Array length
In order to get the number of elements in an array, you can use the length field of an
array. The length field of an array returns the size of the array. It can be used by writing,
arrayName.length

4. Multidimensional Arrays
Multidimensional arrays are implemented as arrays of arrays. Multidimensional arrays
are declared by appending the appropriate number of bracket pairs after the array name.



G. JAVA APPLETS

· Life cycle of an applet
-init()
-start()
-stop()
-destroy()

· drawing strings
drawString();
· drawing ovals
drawOval();
· drawing polygons
drawPolygon();
· drawing rectangles
drawRect();
· drawing lines
drawLine();
· changing font color, size, type, and styles






I. FILE HANDLING

· Reading inputs from a text file

· Writing outputs in a text file

FEEDS

Add to Google Reader or Homepage

Click2Sell

Buy

How To Learn Photoshop in Just 2 Hrs

Chatbox

Click Here

About this blog