Loading presentation...

Present Remotely

Send the link below via email or IM


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.



No description

Ivan Rodriguez

on 3 October 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of JAVA


Object-oriented language
Created by James Gosling and colleagues
Sun Microsystems in the early 90s
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.
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.
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++
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).
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:

Strings and Arrays
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.
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
An expression is a construct made up of variables, operators, and method invocations.
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

{ // begin block 2

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

result = 1 + 2;
// result is now 3
if (
value1 == value2
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;

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

(int i=1; i<11; i++){
System.out.println("Count is: " + i);
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 =
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
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:


The qualified name of a method looks like this:

Full transcript