Download presentation
Presentation is loading. Please wait.
Published byVerity Haynes Modified over 9 years ago
1
ITP 109 Week 2 Trina Gregory Introduction to Java
2
2 Overview Recap of last lecture Basic computer components Different ways of writing and running programs –Compiled –Interpreted Java –How does it work
3
3 Recap Java – object-oriented programming language 3 different platforms for Java –Standard (J2SE) –Enterprise (J2EE) –Mobile (J2ME) Features of Java –Small, simple, easy to compile, powerful & flexible
4
4 Benefits of Java Object-oriented Improved on C++ Security APIs (Application Programming Interface) –Lots of prewritten code Distributed –Able to run over the network “Write once, run anywhere” –Platform independent
5
5 Java Programs Application –Runs natively on the system through the Java Virtual Machine (JVM) Applet –Runs in a browser –Does smaller tasks Programs –Both applets and applications are “Java programs”
6
6 Basic Computer Components Hardware –CPU, memory, secondary storage Operating System –Windows, Mac OS, Linux, Unix Applications –MS Office, Adobe Suite (Photoshop), games, web browsers, Eclipse
7
7 What programs need to communicate? Platform –Windows, Mac, Linux, etc. –Each platform recognizes a different format for running programs Windows – Executable (.exe) Mac – Universal Binary –Executable programs written for a Windows computer will not work on a Linux system In addition, processors on each different computer category speak a different kind of machine language –Typically, we don’t need to worry about this because the operating system takes care of it
8
8 2 Solutions to Program Development Compiled –Communicates with only one kind of computer Interpreted –Communicates with any kind of computer
9
9 Complied Programs
10
10 Compiled Programs They are reasonably fast Compiling also checks for errors The compiled code is platform specific Programmers have to produce a different version for each platform they want to run on
11
11 Interpreted Programs
12
12 Interpreted Programs Cross Platform –Only need to write the program once for all platforms Slow –Error checking and interpreting
13
13 How does Java work? Uses compiling and interpretation A little slower, but runs on any operating system Compiles source code to bytecode Uses Java Virtual Machine (JVM) to interpret bytecode Different operating system has different JVM –Typically, the JVM is written in C
14
14 How Java Works
15
15 Java Terminology Java Virtual Machine (JVM) Java Runtime Environment (JRE) Application Programming Interface (API) –Consists of pre-written code that you can use –Example: DirectX, OpenGL Java Developers Kit (JDK) –Old name for Java technology Java 2, Java 2 platform, Java 2 SDK –New name for Java technology
16
16 Java Terminology JVM JRE Java SDK
17
17 Java API Documentation http://java.sun.com/javase/7/docs/api/ Detailed information about API Extremely valuable resource
18
Your First Java Program Hello World –Traditionally your first computer program –Originates from the first C programming text What does HelloWorld.java look like? class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } 18
19
Hello World - Breakdown class HelloWorld –This specifies the class name. –Everything in Java is part of a class. –We will learn more about classes in a later lecture. –Everything between the curly braces { and } belongs to the class. public static void main (String[] args) –Every Java application must have these lines. These lines tell the compiler that this is the start of the program. System.out.println("Hello World"); –This says to the compiler “I want to print the exact words Hello World”. –The semi-colon ; is the end of a statement. Think of it like a period in the English language. 19
20
Comments A comment can begin with //. Everything after these symbols and to the end of the line is treated as a comment and is ignored by the compiler. class HelloWorld { // My first program public static void main(String[] args) { // Print out the words - Hello World System.out.println("Hello World!"); } class HelloWorld { // My first program public static void main(String[] args) { // Print out the words - Hello World System.out.println("Hello World!"); }
21
Comments A comment can begin with /* and end with */ Everything between these symbols is treated as a comment and is ignored by the compiler. /* Hello World by Trina Gregory */ class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } /* Hello World by Trina Gregory */ class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); }
22
Comments A javadoc comment, begins with /** and ends with */. It can be extracted automatically from Java software. /** * Hello World program * @author Trina Gregory */ class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } /** * Hello World program * @author Trina Gregory */ class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); }
23
When to Use Comments Begin each program file with an explanatory comment –What the program does –The name of the author (YOU) –Contact information for the author (email) –Date of creation or the last modification Provide only those comments which the expected reader of the program file will need in order to understand it.
24
Example 24 /* * Trina Gregory, trina.gregory@usc.edu * ITP 109 Fall 2011, 8/30/2011 * HelloWorld program */ class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } /* * Trina Gregory, trina.gregory@usc.edu * ITP 109 Fall 2011, 8/30/2011 * HelloWorld program */ class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); }
25
25 Bugs and Debugging Bugs: –Program does not compile –Program produces output that is not expected when it executes Debugging is the act of removing them A programmer spends about half of his/her time debugging code Compiler error Executing (or run-time) error
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.