Download Chapter 2: Programs, Data, Variables, and Calculations

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Chapter 1: Introducing JAVA
Introduction
•
•
•
•
•
Why JAVA
Applets and web applications
Very rich GUI libraries
Portability (machine independence)
A real Object Oriented Language
Support International character sets
(Unicode)
2
Program Development
• Editing (any text editor or IDE)
• Compiling (javac)  Java Object (byte)
code
• JVM interprets that code and translates it
to machine language code
• Try installing SDK 1.4.2 then use a simple
editor edit, compile and run a simple
program. See on-line hand out. Do it for
the applet too.
3
OOP in JAVA
• What is an object? Any thing around us
• A class is a convenient way to group things
• It defines a set of variables called class data
members (attributes) and a number of functions
operating on these attributes (methods)
• Example: CowboyHat, hatOn=false, putHatOn(),
takeHatOff()
• Encapsulation: Hiding implementation
• Advantages: less error-prone, easier to maintain
4
JAVA’s Class Library
• Very very rich Library:
– Java.lang, java.io, java.util, javax.swing,
java.awt, java.awt.event, etc.
• To include a library in your program you
use the import statement (import java.io.*;)
• Every Java application contains at least
one class that defines the main function,
the starting execution point. Its form:
(public static void main (String [] args) { })
5