Download No Slide Title

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
Fundamentals of
Web Programming
Lecture 15: Java Basics
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
1
Today’s Topics
• What is Java?
• Why Java?
• Basic Language Constructs
• HelloWorld.java
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
2
What is Java?
• “Java is a simple, robust, objectoriented, platform-independent,
multi-threaded, dynamic, generalpurpose programming
environment.”
http://java.sun.com/aboutJava/
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
3
Java Virtual Machine (VM)
C++
Java
Source
Program
Source
Program
Native
Compiler
Byte
Compiler
Universal
Binary
Native
Binary
• Generated on a specific
platform
• Runs only on that
platform
“The portability of scripting
with the performance of
compilation” (mostly)
“Write once, run anywhere”
Developer’s Computer
Java
VM
User’s Computer
• Generated on a specific
platform
• Runs on any platform with
a Java VM
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
4
Two Flavors of Java
• Java Applications
– Run as separate, standalone
programs on a computer or other
device
– Do not require a web browser
• Java Applets
– Run as embedded programs inside a
web browser
– Require web browser with Java VM
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
5
Why Java?
• Provide dynamic content
• Great support for network
programming
• Leverage client-side resources
• Platform-independence simplifies
distribution
• Small byte-code size shortens
download time
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
6
Why Java?
• Faster than other platform-neutral
languages (e.g., Perl)
• Developed with an intense focus
on distributed computing for the
Internet
• Comprehensive support libraries
for networking, GUI development,
client-server apps, etc.
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
7
Basic Language Constructs
• Basic Types (Table 38.1)
• Operators (Table 38.2)
• Control Flow (Table 38.3)
• Comments (Table 38.4)
• Documentation from Sun:
http://java.sun.com/docs/
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
8
Java Is Not JavaScript
• Strongly Typed
– variables must be declared as a
certain type
– variables can only hold values of that
type
• Compiled
– Java programs must be compiled
before they are run
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
9
Java Is Not C++
• In C++, but not in Java:
– Overloading
– Multiple Inheritance
– Destructors
– Templates
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
10
Java Is Not C++
• Java is “simpler and safer”
• In Java, but not in C++:
– Packages
– Interfaces
• Java requires object-oriented
analysis and design (optional in
other languages like C++)
• Result: Better Code Reusability
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
11
Getting Started: Tools
• javac
– The Java byte compiler
– e.g. javac HelloWorld.java
• java
– The Java virtual machine
– e.g. java HelloWorld
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
12
Getting Started: Tools
• appletviewer
– To view applets outside the browser
– e.g. appletviewer HelloWorld.html
• javadoc
– Generates HTML doc files for all your
Java classes
– e.g. javadoc *.java
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
13
Getting Started: Tools
• Linux
– kaffe implementation of Java 1.1
– pre-installed on your laptops
• Win32
– Sun’s Java Development Kit (JDK)
– Version 1.2.1 available from Sun
(or download from a local mirror)
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
14
First Example
• Application: HelloWorld.java
• Applet: HelloWorldApplet.java,
HelloWorldApplet.html
• http://omaha.mt.cs.cmu.edu/20-753/HelloWorld/
20-753: Fundamentals of
Web Programming
Lecture 15: Java Basics
Copyright © 1999, Carnegie Mellon. All Rights Reserved.
15
Related documents