Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

JAVA

No description
by

Ivan Rodriguez

on 3 October 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of JAVA

JAVA

HISTORY OF JAVA
Object-oriented language
Created by James Gosling and colleagues
Sun Microsystems in the early 90s
Classes
A class declaration names the class and encloses the class body between braces.
The class name can be preceded by modifiers.
The class body contains fields, methods, and constructors for the class.
Constructors that initialize a new instance of a class use the name of the class and look like methods without a return type.
Variables
The Java programming language defines the following kind of variables:
public modifier—the field is accessible from all classes.
private modifier—the field is accessible only within its own class.
Name?
Language was first named "C++ ++ --"
Later renamed as "Oak"
Temporary called "Green"
Named after the beverage Java
Aimed to be...
Familiar with C/C++ style of notation
Cleaner and more object-oriented than C++
Greater uniformity and simplicity than C/C++
Goals
Use the OOP methodology.
Allow the same program to be executed on multiple OS.
Contain built-in support for using computer networks.
Execute code from remote sources securely.
Easy to use and borrow good parts of older object-oriented languages.
Instance Variables
int speed = 0;
char capitalC = 'C';

Their values are unique to each instance of a class.
Ex. The current speed of one car is independent from the speed of another car.
Class Variables (static fields)
static int speed = 0;

A class variable is any field declared with the static modifier.
There is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated.
Local Variables
int counter = 0;

Declared the same as instance variables.
Only visible to the methods in which they are declared.
Not accessible from the rest of the class.
The only required elements of a method declaration are the method's return type, name, a pair of parentheses, (), and a body between braces, {}.
You create an object from a class by using the new operator and a constructor.

The new operator returns a reference to the object that was created.
Based on Jim Harvey's speech structures
More on Java
First public implementation as Java 1.0 in 1995.
"Write Once, Run Anywhere"
Major web browsers soon incorporated it into their standard configurations.
Java's core code became available as free-software/open-source in 2007.
Java SE 7 (Dolphin).
Parameters
public static void main(String[] args)

Parameters are variables that provide extra information to a method.
Parameters are always classified as "variables" not "fields".
Primitive Data Types
The eight primitive data types supported by the Java programming language are:


byte
short
int
long
float
double
boolean
char
Strings and Arrays
Strings
System.out.println("abc");
String cde = "cde";
System.out.println("abc" + cde);

The String class represents character strings.
Strings are constant; their values cannot be changed after they are created.
Arrays
int[] anArray;
anArray = new int[10];

An array is a container object that holds a fixed number of values of a single type.
The length of an array is established when the array is created.
After creation, its length is fixed.
Expressions, Statements, and Blocks
Expressions
An expression is a construct made up of variables, operators, and method invocations.
Statements
Blocks
class BlockDemo
{

public static void main(String[] args) {
boolean condition = true;
if (condition) { // begin block 1
System.out.println("Condition is true.");
} // end block one

else
{ // begin block 2

System.out.println("Condition is false.");
} // end block 2
}
}
int
cadence = 0;
anArray[0] = 100;
System.out.println(
"Element 1 at index 0: " + anArray[0]
);

int
result = 1 + 2;
// result is now 3
if (
value1 == value2
)
System.out.println("
value1 == value2"
);
aValue = 8933;
// assignment statement
int plus = aValue++;
// increment statement
// method invocation statement
System.out.println("Hello World!");
// object creation statement
Bicycle myBike = new Bicycle();
Control Flow Statements
class WhileDemo {
public static void main(String[] args){
int count = 1;

while
(count < 11) {
System.out.println("Count is: " + count);
count++;
}
}
}
class ForDemo {
public static void main(String[] args){

for
(int i=1; i<11; i++){
System.out.println("Count is: " + i);
}
}
}
public
class
Bicycle {
// the Bicycle class has three fields
public int cadence;
public int gear;
public int speed;
. . .
. . .
}
public class Bicycle {
. . .
. . .

// the Bicycle class has four methods
public void setCadence(int newValue) {
cadence = newValue;
}
public void setGear(int newValue) {
gear = newValue;
}
public void applyBrake(int decrement) {
speed -= decrement;
}
public void speedUp(int increment) {
speed += increment;
}
}
public class Bicycle {

// the Bicycle class has three fields
public int cadence;
public int gear;
public int speed;


// the Bicycle class has one constructor
public Bicycle(int startCadence, int startSpeed, int startGear) {
gear = startGear;
cadence = startCadence;
speed = startSpeed;
}
. . .
. . .
}
Access Modifiers
A class uses fields to contain state information and uses methods to implement behavior.
To create a new Bicycle object called myBike, a constructor is called by the new operator:

Bicycle myBike =
new
Bicycle(30, 0, 8);

new Bicycle(30, 0, 8) creates space in memory for the object and initializes its fields.
public double calculateAnswer(double wingSpan,
int numberOfEngines,
double length,
double grossTons)
{
//do the calculation here
}
Objects
Instance variables and methods that are accessible to code outside of the class that they are declared in can be referred to by using a qualified name.
The qualified name of an instance variable looks like this:

objectReference.variableName

The qualified name of a method looks like this:

objectReference.methodName(argumentList)
Full transcript