Download presentation
Presentation is loading. Please wait.
1
Introducing Java
2
What is Java? Sun defines Java as a:
“…simple, object-oriented, network savvy, interpreted, robust, secure, architecture-neutral, portable, high-performance, multi-threaded, dynamic language.”
3
What is Java? Program cycle Source code is written by the programmer
.java extension Compiler converts into bytecodes .class extension Instructions for the JRE Initial class is loaded Statements are interpreted one bytecode at a time Bytecodes may be compiled into platform native instructions Additional classes are loaded as needed
4
What is Java? History of Java
First started in 1990 as Sun’s Green project Digitally controlled consumer devices identified as trend Trend did not grow as expected 1994 – WWW popularity Netscape packaged Java within browser MS Explorer followed suit Success ultimately depended on e-commerce
5
Development Tools 1995 – First JDK released by Sun (1.0)
Very limited JDK 1.1 released Limited GUI creation 1.2 released Major change – Swing components Java 2 SDK release 1.2 Better known as Java 2 Most current version: 1.5
6
Development Tools Java 2 Editions Java 2 Platform, Standard Edition
Java 2 Platform, Enterprise Edition Java 2 Platform, Micro Edition
7
Java Programs Applets Servlet Application
Java program running within client Web browser Servlet Java program running on a server Can ‘cooperate’ with applet or application Application Standalone program
8
Sample Java Program package myprojects.demo; import java.io.*;
import csci130.*; class Demo { public static void main(String args[]) { double length, width, area; System.out.println(“Rectangle Area Calculator"); System.out.println("Enter the length: "); length = KeyboardReader.readDouble(); System.out.println("Enter the width: "); width = KeyboardReader.readDouble(); area = length * width; System.out.println("The area is: " + area); }
9
Compiling your code From the command line Running javac Demo.java
Java Demo
10
Object-Oriented Programming
Java Programming Object-Oriented Programming
11
Elements of OOP Objects Classes Messages Interfaces
12
Why Objects Real world objects all share two things State Behavior
A car is Red, a convertible, 4 door Behavior Speeds up, brakes, turns, stops, crashes
13
Real objects maintain their state using variables
Color = red Type = convertible Style = 4door Real objects implement behavior thru methods. Brake Accelerate
14
What's a message? Objects interact
A car even as a very high level object does nothing until it gets a message or direction. To stop a car, the driver must give it the message to break. Another way to think of messages are method calls.
15
Classes Classes are prototypes or blueprints for objects.
Classes contain the definitions for the variables and methods common to all objects of a certain kind.
16
Objects vs Classes The code for that file goes into the java file.
car.java When compiled the template is in a class file car.class When talking about a program a class refers to a type of object. When instantiated, it becomes an object. It can become very confusing at times because the terms are often used loosely.
17
Inheritance Inheritance provides for a powerful mechanism allowing for organizing and structuring software. Inheritance provides for classes to be defined in terms of other classes The relationship between superclasses and subclasses is a “is a” relationship. Dog class Bull_Dog class --- a Bull dog “is a” dog. Subclasses inherit state (variables) and behavior (methods) from the superclass. Inheritance is hierarchical – it can be several layers
18
Inheritance Classes can inherit from only one superclass
Other languages allow for multiple inheritance Java does not Subclasses inherit everything from all superclasses The base class of all classes in Java is the Object Class, every class/ object extends from it. This class has several methods one we will get used to is called the toString(). The result is any class, no matter how many times removed will have the toString().
19
Interfaces Since Java does not allow multiple inheritance what happens when you want methods from two different classes? Java provides a device called an interface. An Interface is a system that allows entities to interact. An Interface is a collection of methods and constant declarations. When a class implements an Interface, it must write implement all the methods of the interface
20
Benefits of OOP Modularity Information hiding
Source code can be written and maintained for an object independent of the code for other objects. Information hiding An object has a public interface through which it can communitcate with other objects, but can also maintain private information that other objects cannot access. Encapsulation – allows a way to protect how things happen using several layers of access control.
21
Summary A class is a prototype for objects
Objects are created from classes An Object's class is it's type. Objects have varibles and methods as defined in the class. Classes can inherit from other classes Classes an implement interfaces allowing two classes to have similar methods.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.