Download OO Programming in Java Intro to the Java Language

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

Pwn2Own wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Class (computer programming) wikipedia , lookup

Go (programming language) wikipedia , lookup

Library (computing) wikipedia , lookup

C Sharp syntax wikipedia , lookup

Object-oriented programming wikipedia , lookup

Name mangling wikipedia , lookup

Java syntax wikipedia , lookup

Scala (programming language) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Java (programming language) wikipedia , lookup

Java performance wikipedia , lookup

Transcript
Introduction To Java
Objectives For Today
 Introduction To Java
 The Java Platform & The (JVM) Java Virtual Machine
 Core Java (API) Application Programming Interface
 Java Applications & Applets
What Is Java ?
 An Object Oriented Language and platform developed by Sun
Micro Systems that is machine independent and can be used to
write applications and applets for the internet.
 Developed initially for home electronics as a language that could
be used with any microprocessor in the home on devices such as
converters and remote controls.
 Sun saw a benefit for such a language and realized it could be
applied to computing and the internet.
 Write once run anywhere. Pure Java programs are compiled into
machine-independent byte-code which runs consistently on any
platform.
Introduction To Java
The authors of Java have written the Java “White Paper”
that explains their design goals and accomplishments. The
paper is organized around the following buzzwords:
Simple
 Powerful but easy to learn in comparison to other object
oriented languages. (ie. C++ not VB)
Object Oriented
 Concentrates on the data represented in objects that have
both a state and behavior.
 As a developer, you concentrate on the data in your objects
and then the methods that act upon them.
Introduction To Java
Object Oriented
 This differs significantly from procedural based programming
where the focus was on the procedures of the program, not the
data being manipulated.
 Java comes with a rich set of classes that you can re-use to
to build your own programs.
 For example, Java provides a set of classes you can use to
create a Graphical user interface.
 Almost everything in Java is an object except the primitive
data types you are familiar with. (integers, doubles etc.)
Introduction To Java
Interpreted & Distributed
Interpreted
 Java contains a compiler that translates Java source code
into byte-code for the Java Virtual Machine.
 Byte-code is machine independent which means it is not
dependent on the native machine code.
 It can run on any platform.
Distributed
 Distributed simply means Java provides a lot of
support for networking.
Introduction To Java
Distributed
 Java can read remote files and resources across
networks almost as easily as reading from the local file
system.
 Java also allows for objects to send messages to one
another across networks as if they were local objects.
 This is called RMI. (Remote Method Invocation)
Robust
 Java puts considerable emphasis on early checking for
possible problems,dynamic(run-time) checking, and
eliminating situations that are error prone.
Introduction To Java
Secure:
 Java has built in security features that verifies code
before it is executed if it originates from an unknown source.
 Applets are Java programs that come from unknown
sources and run within the confines of your browser.
 Applets that come from sources not trusted are placed
in what is commonly called a sandbox inside your browser.
 As a result Applets are limited as to what they can do
and cannot do the following:
 Read Files, Write Files, Delete Files, Rename Files.
Introduction To Java
Architecture Neutral & Portable
 As mentioned earlier, the Java compiler
generates byte-code for the Java Virtual Machine.
 Byte-codes can run on any platform such as
Mac, Unix, Windows, etc.
 Java can run on any platform as long as that system
implements the Java Virtual Machine (JVM)
Introduction To Java
High Performance
 Java is an interpreted language.
 It is not as fast as compiled languages such as C
but is still more than adequate to run interactive
GUI and Network based applications.
 However, you can get Just In Time (JIT) compilers
in Java that can translate byte-code into machine
code for a particular CPU.
Introduction To Java
Multithreaded
 Java allows the user to program multiple threads, which
are small programs that run simultaneously.
 A developer may want to write a program that
plays an audio clip.
 At the same time a the program may have the capability
to download a file.
Introduction To Java
Dynamic
 Java was designed to be dynamic.
 Java is a language that can adapt to a changing environment.
 As time passes, new API Classes are developed that can
easily be implemented with already existing Classes.
The Java Platform
The Java Platform consists of the following:
 The Java Virtual Machine (JVM)
 Java compiler and interpreter
 Java Core Classes (API) (Application Programming
Interface)
 Java Documentation
 Java Development Kit (JDK) incorporates all points above.
The Java Virtual Machine
 You can think of the JVM as a computer integrated
in software on your computer.
 When you compile Java source code it is compiled
into byte-codes.
 The JVM is capable of interpreting these instructions in the
form of machine independent byte-codes.
 This is the key to a Java programs portability.
 As long as your computer runs the JVM or your web
browser is Java enabled, you will be able to execute
Java byte-codes and therefore run Java Applications and
Applets.
How Java Works
The Java Core Classes (API)
 When programming in Java you have access to a
rich set of programming elements called Classes.
 You can use these Classes to build your programs.
ie
java.util
java.lang
Vector
String
 These classes are called the Java Core Classes.
 The JDK documentation provides a complete
list of the core classes and their specifications.
 Let’s take a look at the JDK documentation.
The Java Development Kit (JDK)
How do we build Java Applications and Applets?
 We use the Java Development Toolkit which includes the JVM,
the core API and various tools.
 We can use a set of tools provided by Java. These tools are
located in the jdk bin directory on your computer.
 Some of the tools you will come most familiar with are:
• javac
compiles java files into byte-code
• java
runs class files (also called the interpreter)
• appletviewer built in browser for running applets
• javadoc
compiles javadoc comments in html format
 These tools are very crude and are run from the dos prompt.
The Tools We Will Use
Text Editors
 We will begin our work in Java using text editors
to create simple Applications and Applets.
 Any text editor can be used, but we will use:
•Notepad
•Text Pad
Shareware version of Text Pad has been installed
for you on the image.
The Tools We Will Use
Visual Age For Java
 An application development tool from IBM. (Version 2)
 Visual Age greatly enhances our ability to develop applications
and applets by providing us with these key features:
• IDE (Integrated Development Environment)
• Workbench (Organizes packages and classes)
• Smart Guides (Similar to wizards in MS Access)
• VCE (Visual Composition Editor)
• Visual Age Debugger
Java Applications
Run stand alone in the JVM
All applications have a starting point
public static void main (String [] args) {}
Can be simple command line programs or more
advanced GUI programs that we are use to.
Demonstration of a simple Java Application
Java Applets
Run in web browser or appletviewer
Invoked by HTML tags <applet></applet>
Call must extend: java.applet.Applet
Use methods: init, start, paint, stop, destroy
Demonstration of a simple Java Applet