Download presentation
Presentation is loading. Please wait.
Published byBarnaby Harvey Modified over 8 years ago
1
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 15: Java Basics Fundamentals of Web Programming Lecture 15: Java Basics
2
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 2 Lecture 15: Java Basics Today’s Topics What is Java? Why Java? Basic Language Constructs HelloWorld.java
3
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 3 Lecture 15: Java Basics What is Java? “Java is a simple, robust, object- oriented, platform-independent, multi-threaded, dynamic, general- purpose programming environment.” http://java.sun.com/aboutJava/ http://java.sun.com/aboutJava/
4
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 4 Lecture 15: Java Basics Java Virtual Machine (VM) Generated on a specific platform Runs only on that platform C++ Source Program Native Compiler Native Binary Developer’s Computer User’s Computer Generated on a specific platform Runs on any platform with a Java VM Java Source Program Byte Compiler Universal Binary Java VM “The portability of scripting with the performance of compilation” (mostly) “Write once, run anywhere”
5
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 5 Lecture 15: Java Basics 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
6
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 6 Lecture 15: Java Basics 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
7
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 7 Lecture 15: Java Basics 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.
8
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 8 Lecture 15: Java Basics 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/ http://java.sun.com/docs/
9
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 9 Lecture 15: Java Basics 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
10
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 10 Lecture 15: Java Basics Java Is Not C++ In C++, but not in Java: –Overloading –Multiple Inheritance –Destructors –Templates
11
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 11 Lecture 15: Java Basics 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
12
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 12 Lecture 15: Java Basics Getting Started: Tools javac –The Java byte compiler –e.g. javac HelloWorld.java java –The Java virtual machine –e.g. java HelloWorld
13
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 13 Lecture 15: Java Basics 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
14
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 14 Lecture 15: Java Basics 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)local mirror
15
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 15 Lecture 15: Java Basics First Example Application: HelloWorld.java Applet: HelloWorldApplet.java, HelloWorldApplet.html http://omaha.mt.cs.cmu.edu/20-753/HelloWorld/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.