Upload
todd-greer
View
216
Download
2
Embed Size (px)
Citation preview
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
1
IT1202-Fundamentals Of Programming(Using JAVA)
Interacting with Java ProgramsVersion 1.0
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
2
Introduction to Java Development Kit (JDK)
JDK provides core set of tools that are necessary to develop Professional Java applications
These tools are discussed in detail later
JDK tools are also written in Java.
BIT
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
3BIT
Introduction…………
JDK is a set of command-line programs, text-based utilities that don’t make use of a graphical user interface.
Programmers run each of the JDK’s utilities by typing java GetFunky.class
This command tells the java program – the bytecode interpreter – to run a bytecode
file called GetFunky.class (As you see later today, compiled Java programs all have
the .class file extension)
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
4
Introduction…………
Windows 95 users must use the MS-DOS prompt command to open a window where commands can be typed.
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
5
Introduction……….
Installing the Java Development Kit
JDK for different platforms available
in a CD or can download from the
web site: http://java.sun.com
Windows InstallationBefore installing the JDK on your system
make sure that no other Java development
tools are installed.
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
6
Installation……….To install the JDK on Windows, double-click the installation archive file or use the Start Run command from the Windows taskbar to find and run the file.
After you see a dialog box asking whether you want to install JDK the JDK Setup Wizard is displayed. You can use this window to configure how the JDK is installed in your system.
The default settings for this wizard should be fine for most users. The JDK is installed in a new folder with a name based on the version you’re downloading
(such as \jdk1.2), unless you use the Browse button to select a different folder on your system.
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
7
Installation………
The wizard will install the following JDK components:
Program files
Native Interface header files
Tooldocs
Demo files
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
8
Installation……….
Solaris Installation
Sun’s Solaris version of the JDK can be installed on the following platforms:
SPARC systems running Solaris 2.4 or higher
x86 systems running Solaris 2.5 or higher
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
9
Creating a source file
Java applications are standalone Java programs that do not require a Web browser to run.
Run them locally with your mouse or
by typing the program name at a command line.
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
10
Creating a source file
Any plain text editor or text editor capable of saving in ASCII format can be used to create a Source file
Examples are DOS EDIT, Notepad etc.
Source File should be saved with a .java extension
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
11
Creating……….
If you are using Windows 95, 98 or NT, a text editor such as Notepad may add an extra .txt file extension to the filename of any Java source files you save.
The Java compiler will only handle source files with the .java file extension.
To avoid this problem place quotation
marks around the filename when you
are saving a source file.
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
12
Creating……….
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
13
Creating………….Writing the program
Choose the editor according to your choice & enter the Java program.
class HelloDan { public static void main (String[] arguments) { System.out.println (“What’s your name?”); } }
» After finish typing the program, save the file somewhere on your drive with the name HelloDan.java.
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
14
Compiling & running the source file
Compile the Source FileFirst set the Java Environment
Setting The PathIn your Autoexec.bat file set the PATH and CLASS PATH as followsPATH …………;\C:\JDK1.3\BIN\…. Indicates any existing paths
SET CLASSPATH =C:\JDK1.3\lib\classes.zip;.;
BIT
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
15
Compiling………….
Compiling and Running the Source File contd..Assuming you saved your source file in myJavaPrg Directory
C:\myJavaPrg>Javac Test.java
Java Compiler
Source File Name (ensure to use Same name as the class Name)
Java Compilerwill create aJava byte code file
BIT
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
16
Running Java Programs
To execute byte code file
C:\myJavaPrg>Java Test
Java Interpreter
Class Name
Java Byte Code InterpreterExecute the Java Byte codeclass file
BIT
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
17
Java byte code fileBytecode is the Java virtual machine’s version of the machine code, the instructions it directly understands.
The virtual machine known as Java interpreter or Java runtime.
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
18
Java……….
The virtual machine takes compiled Java programs & converts their instructions into commands, which known as byte code, can run on any platform & operating system that has a Java virtual machine.
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
19
Java byte code interpreter
Java codeJava code
Java Compiler Java Bytecode (Platform Independent)
Java Interpreter (Pentium)
Java Interpreter
(PowerPC)
UCSC 2003. All rights reserved. No part of this material may be reproduced and sold.
20
Java byte code Interpreter…..
Source code, is the set of programming statements a programmer enters into a text editor when creating a program.
Source code is compiled into bytecode so that it can be run by a Java virtual machine.
The capability of a single bytecode file to run across
platforms is crucial to what makes Java work on the
World Wide Web, because the Web itself is
platform-independent.