This program will compute two numbers and get the sum.
a=90, c=80
program code:
import java.io.*;
public class compute
{
public static void main(String args[])
{
//Declaration of variables
int a=90;
int b=80;
int sum=0;
//compute the sum
sum=a+b;
System.out.print("The sum is" + sum);
}
}
Tuesday, June 29, 2010
Friday, June 25, 2010
Encapsulation in Java
Encapsulation - refers to the hiding of data and methods within an objects. and also protects data from corruption.
- easier to modify programs since one object type is modified at a time.
- easier to modify programs since one object type is modified at a time.
Labels:
encapsulation,
Encapsulation in java
Abstraction in java
Abstraction refers to the ability to make a class abstract in OOP.
An abstract class is one that cannot be instantiated. All other functionality of the class still exists, and its fields, methods, and constructors are all accessed in the same manner. You just cannot create an instance of the abstract class.
An abstract class is one that cannot be instantiated. All other functionality of the class still exists, and its fields, methods, and constructors are all accessed in the same manner. You just cannot create an instance of the abstract class.
Labels:
abstract in java,
Abstraction in java,
abstration
Thursday, June 24, 2010
Creating an object in java program
Creating an object in java program
class Puppy{ public Puppy(String name){ // This constructor has one parameter, name. System.out.println("Your Name is :" + name ); }
public static void main(String []args){ // Following statement would create an object myPuppy Puppy myPuppy = new Puppy( "Jaypee" ); } }
sample output:
Your Name is : Jaypee
Creating an Object in Java
Creating an Object:
As mentioned previously a class provides the blueprints for objects. So basically an object is created from a class. In java the new key word is used to create new objects.There are three steps when creating an object from a class:
- Declaration . A variable declaration with a variable name with an object type.
- Instantiation . The 'new' key word is used to create the object.
- Initialization . The 'new' keyword is followed by a call o a constructor. This call initializes the new object.
Labels:
creating object in java,
java object,
object in java
Objects and Classes in Java
Objects - represent "things: from the real world.
the objects is made up of attributes and methods.
Attributes - define the object.
methods - describes the mechanism that actually perform its tasks.
Classes - describes a group or collection of objects with common properties and also define a type of objects
Example of classes:
- employee
- car
-chair
the objects is made up of attributes and methods.
Attributes - define the object.
methods - describes the mechanism that actually perform its tasks.
Classes - describes a group or collection of objects with common properties and also define a type of objects
Example of classes:
- employee
- car
-chair
Flowcharting Problem and Solution
This is a sample flowchart and algorithm solution to the problem compute two numbers and get the sum.
this a good steps to solve the problem in programming.
this a good steps to solve the problem in programming.
Flowchart problem #1
Problem # 1: Create a flowchart and algorithm that compute two numbers and get the sum.
i will post the solution of this problem tommorow.
i will post the solution of this problem tommorow.
Labels:
Compute the sum,
create a flowchart,
flowchart
Wednesday, June 23, 2010
Programming Cycle to solve a problem
Problem Definition - specifies the what the computer to do.
Problem Analysis
-Input - specifies the input of the program
-Output - specifies the output of the program
Algorithm Development
-Process - step by step process to solve a problem
-Flowchart and Pseudocode - step by step process but we will used the symbols in flowchart
Coding and Debugging - creating a program and fixing the errors
Problem Analysis
-Input - specifies the input of the program
-Output - specifies the output of the program
Algorithm Development
-Process - step by step process to solve a problem
-Flowchart and Pseudocode - step by step process but we will used the symbols in flowchart
Coding and Debugging - creating a program and fixing the errors
Tuesday, June 22, 2010
Flowchart
Flowchart represent the algorithm or process of data, using chart or sysmbols.
There are different Flowchart symbols. the ff. are:
1. Terminal sysmbol - (oval) this symbol represent the start and end of the flowchart.
2. Initialization Symbol - (hexagon) this symbol is used in declaring or initializing variable used in the program.
3. Process Symbol (Rectangle) this symbol used in calculation, opening and closing file paths.
4. Condition Symbol (Diamond) this symbol used in condition of value in programming. this condition have a one entrance two exit which is the first exit is the "TRUE STATEMENT" and other exit is the "FALSE STATENENT".
5. Input and Output Symbol (parallelogram) this symbol used in input and output of the program. there is one entrance and one exit.
6. Connector (small Circle) it is used in connection flowchart that does not adjacent of not the same patcular area.
7. Arrow Lines (arrow) this is used to connect or the direction or flow of data.
There are different Flowchart symbols. the ff. are:
1. Terminal sysmbol - (oval) this symbol represent the start and end of the flowchart.
2. Initialization Symbol - (hexagon) this symbol is used in declaring or initializing variable used in the program.
3. Process Symbol (Rectangle) this symbol used in calculation, opening and closing file paths.
4. Condition Symbol (Diamond) this symbol used in condition of value in programming. this condition have a one entrance two exit which is the first exit is the "TRUE STATEMENT" and other exit is the "FALSE STATENENT".
5. Input and Output Symbol (parallelogram) this symbol used in input and output of the program. there is one entrance and one exit.
6. Connector (small Circle) it is used in connection flowchart that does not adjacent of not the same patcular area.
7. Arrow Lines (arrow) this is used to connect or the direction or flow of data.
Monday, June 21, 2010
Pseudocode
An outline of a program, written in a form that can easily be converted into real programming statements. For example, the pseudocode for a bubble sort routine might be written:
while not at end of list
compare adjacent elements
if second is greater than first
switch them
get next two elements
if elements were switched
repeat for entire list
Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules. It is simply one step - an important one - in producing the final code. The benefit of pseudocode is that it enables the programmer to concentrate on the algorithms without worrying about all the syntactic details of a particular programming language. In fact, you can write pseudocode without even knowing what programming language you will use for the final implementation.
while not at end of list
compare adjacent elements
if second is greater than first
switch them
get next two elements
if elements were switched
repeat for entire list
Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules. It is simply one step - an important one - in producing the final code. The benefit of pseudocode is that it enables the programmer to concentrate on the algorithms without worrying about all the syntactic details of a particular programming language. In fact, you can write pseudocode without even knowing what programming language you will use for the final implementation.
Algorithm
'algorithm' is an effective method for solving a problem expressed as a finite sequence of instructions.
step by step procedure to solve the problem.
step by step procedure to solve the problem.
Thursday, June 3, 2010
Array
Array is very important in programming to store data in array. i post the lesson next day.
Labels:
add two numbers in java,
array in java,
array-java
Subscribe to:
Posts (Atom)