clement allen, phd florida a&m university summer 2006

31
Clement Allen, PhD Florida A&M University SUMMER 2006

Upload: ira-short

Post on 01-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Clement Allen, PhD Florida A&M University SUMMER 2006

Clement Allen, PhD

Florida A&M University

SUMMER 2006

Page 2: Clement Allen, PhD Florida A&M University SUMMER 2006

http://www.cis.famu.edu/~cisjava

Page 3: Clement Allen, PhD Florida A&M University SUMMER 2006

http://www.cis.famu.edu/~cisjava

Page 4: Clement Allen, PhD Florida A&M University SUMMER 2006

http://www.cis.famu.edu/~cisjava

Page 5: Clement Allen, PhD Florida A&M University SUMMER 2006

http://www.cis.famu.edu/~cisjava

Page 6: Clement Allen, PhD Florida A&M University SUMMER 2006

http://www.cis.famu.edu/~cisjava

(SAMPLE)

Page 7: Clement Allen, PhD Florida A&M University SUMMER 2006

Introduction to JAVA

• History of Java

• Why all the fuss?

• Our first Java program

• Compiling and Executing a Java Program

~ ~ ~ ~if else~ ~ ~ ~system.out

Page 8: Clement Allen, PhD Florida A&M University SUMMER 2006

Introduction to JAVA

• History

• What is JAVA and why the big deal?

“A simple, object-oriented, multi-threaded, portable, platform-independent, secure programming environment for creating applications and smaller programs called applets”

SUN engineers embark on a mission to develop a platform independent language that could be used to program consumer appliances

Page 9: Clement Allen, PhD Florida A&M University SUMMER 2006

• SimpleStripped-down version of C/C++ minus all the confusing, troublesome features of C/C++

• Object-orientedPromotes good software engineering. Facilitates reuse.

• MultithreadedPrograms can handle many operations simultaneously

Page 10: Clement Allen, PhD Florida A&M University SUMMER 2006

• Platform-independentExecutable code is bytecode that can run run any machine. Compile once, run everywhere.

• SecureApplets run in a protected space

• PortableWorks the same on all machines. Write once, run anywhere.

Page 11: Clement Allen, PhD Florida A&M University SUMMER 2006

JAVA Fundamentals

The two types of Java programs

• Applets

• Applications

A program that is executed within a Web browser

All other programs; a program executed from the command line.

Page 12: Clement Allen, PhD Florida A&M University SUMMER 2006

• Use your favorite editor to create the source code

$ emacs Hello.java

// Program : Hello// Date : 8/27/97// Date Modified :// Authors : Clement Allen// Description : Our first application

public class Hello { // Defines the application called Hello

public static void main (String args[ ]) { // Every application has main

System.out.println("Hello!"); // This prints the word Hello

} // end main

} // end Hello

Page 13: Clement Allen, PhD Florida A&M University SUMMER 2006

• Compile source code

$ javac Hello.java

• Execute the program

$ java Hello

Hello

creates a file called Hello.class

RunProgram

Page 14: Clement Allen, PhD Florida A&M University SUMMER 2006

import javax.swing.*;

public class Welcome { // Defines an application called Welcome

// begin the execution

public static void main(String args[ ] ) {

// display a window

JOptionPane.showMessageDialog(null,"Welcome to COP3060!!!");

// terminates the application

System.exit(0);

}

}

Page 15: Clement Allen, PhD Florida A&M University SUMMER 2006

• Compile source code

$ javac Welcome.java

• Execute the program

$ java Welcome

creates a file called Welcome.class

RunProgram

Page 16: Clement Allen, PhD Florida A&M University SUMMER 2006

Eclipse is an open source IDE (Integrated Development Environment) for developing applications in Java, C/C++, HTML, Cobol, Perl, etc.

The official Eclipse web site (eclipse.org) says, “Eclipse is a kind of universal tool platform -- an open extensible IDE for anything and nothing in particular.”

Java Development with Eclipse

Page 17: Clement Allen, PhD Florida A&M University SUMMER 2006

• Provides a consistent feature set on most platforms

• Supports more than just Java or any single language

• Open source and free, yet fully supported

• Truly extensible and configurable

• Industrial strength

Eclipse:

Java Development with Eclipse

Page 18: Clement Allen, PhD Florida A&M University SUMMER 2006

Start Eclipse by Double-clicking on the icon that appears on your desktop. The welcome screen will appear.

Page 19: Clement Allen, PhD Florida A&M University SUMMER 2006

From this screen you can get an Overview of Eclipse, Tutorials, and Code Samples.

Page 20: Clement Allen, PhD Florida A&M University SUMMER 2006

Each window is called a View. A collection of views is called a Perspective. There is a Java Perspective, Debug Perspective, C++ Perspective, etc.

Page 21: Clement Allen, PhD Florida A&M University SUMMER 2006

To switch to a Perspective, go to Window -> Open Perspective…Then choose the Perspective you want. In this case, it is the Java Perspective.

Page 22: Clement Allen, PhD Florida A&M University SUMMER 2006

To create a Java program, first create a Project that will contain your source code: File -> New -> Project -> Java Project

Page 23: Clement Allen, PhD Florida A&M University SUMMER 2006

Give your project a name, in this case the project is Lab1. Choose Next and then Finish

Page 24: Clement Allen, PhD Florida A&M University SUMMER 2006

You will see a folder called Lab1 in the Package Explorer View.

Page 25: Clement Allen, PhD Florida A&M University SUMMER 2006

To create a Java program, Choose New -> Other -> Class.

Page 26: Clement Allen, PhD Florida A&M University SUMMER 2006

Give your class a name, in the case Hello. Choose Finish.

Page 27: Clement Allen, PhD Florida A&M University SUMMER 2006

You will see the the Class in the Package Explorer View, and an Editor View appears where you will enter the code.

Page 28: Clement Allen, PhD Florida A&M University SUMMER 2006

Type in the code for Hello.

Page 29: Clement Allen, PhD Florida A&M University SUMMER 2006

To save, Right-click on the editor, choose Save.

Page 30: Clement Allen, PhD Florida A&M University SUMMER 2006

To save, Right-click on the editor, choose Run As -> Java Application.

Page 31: Clement Allen, PhD Florida A&M University SUMMER 2006

The output will appear in the Console View.