clement allen, phd florida a&m university summer 2006
TRANSCRIPT
Clement Allen, PhD
Florida A&M University
SUMMER 2006
http://www.cis.famu.edu/~cisjava
http://www.cis.famu.edu/~cisjava
http://www.cis.famu.edu/~cisjava
http://www.cis.famu.edu/~cisjava
http://www.cis.famu.edu/~cisjava
(SAMPLE)
Introduction to JAVA
• History of Java
• Why all the fuss?
• Our first Java program
• Compiling and Executing a Java Program
~ ~ ~ ~if else~ ~ ~ ~system.out
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
• 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
• 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.
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.
• 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
• Compile source code
$ javac Hello.java
• Execute the program
$ java Hello
Hello
creates a file called Hello.class
RunProgram
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);
}
}
• Compile source code
$ javac Welcome.java
• Execute the program
$ java Welcome
creates a file called Welcome.class
RunProgram
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
• 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
Start Eclipse by Double-clicking on the icon that appears on your desktop. The welcome screen will appear.
From this screen you can get an Overview of Eclipse, Tutorials, and Code Samples.
Each window is called a View. A collection of views is called a Perspective. There is a Java Perspective, Debug Perspective, C++ Perspective, etc.
To switch to a Perspective, go to Window -> Open Perspective…Then choose the Perspective you want. In this case, it is the Java Perspective.
To create a Java program, first create a Project that will contain your source code: File -> New -> Project -> Java Project
Give your project a name, in this case the project is Lab1. Choose Next and then Finish
You will see a folder called Lab1 in the Package Explorer View.
To create a Java program, Choose New -> Other -> Class.
Give your class a name, in the case Hello. Choose Finish.
You will see the the Class in the Package Explorer View, and an Editor View appears where you will enter the code.
Type in the code for Hello.
To save, Right-click on the editor, choose Save.
To save, Right-click on the editor, choose Run As -> Java Application.
The output will appear in the Console View.