Download presentation
Presentation is loading. Please wait.
Published byMaría Dolores Zúñiga Moya Modified over 6 years ago
1
Introduction to Java Dept. Business Computing University of Winnipeg
Yangjun Chen Dept. Business Computing University of Winnipeg 11/9/2018
2
Outline: Introduction to Java
What is Java? - Java characters A simple Java program Java download and program execution 11/9/2018
3
What is Java? Java is a high level programming language that is very similar to C and C ++. - You do not need to know these languages to learn Java, but they would help. Java is an object-oriented language. Java is platform independent. Java is multi-threaded. 11/9/2018
4
Java is Object-Oriented
In traditional computer languages, data are separated from procedures as in C, Pascal, … (procedural language) Prolog, and (declarative language) LISP (functional language) In Java, data are encapsulated by the procedures defined over them. Traditional languages: Java: Data files procedure1 procedure2 procedureN data procedures 11/9/2018
5
Java is Object-Oriented
Advantage of object-oriented programming - Application independence - Software reuse - Easy maintenance of programs 11/9/2018
6
Platform Independence
- A platform is basically some combination of hardware and software running within a system: CPU and operating system - An executable program (object code) may not be executed on different machines (platforms) due to the fact that each machine has its own machine instruction set. Java solves the platform-independence problem by using bytecodes and the so-called Java Virtual Machine (JVM). 11/9/2018
7
Platform Independence
JVM - The JVM is some software that implements a virtual or imaginary machine inside your computer. - Accordingly, a Java program will be executed in two phases: compiling and interpreting The first phase (Java compiler) - It compiles the program, but instead of generating machine code specific to hardware, it generates bytecodes. - Bytecodes are instructions that looks like machine code but are not specific to any one processor. 11/9/2018
8
Platform Independence
The second phase (Java interpreter) - The interpreter will read in the bytecode and translate it into native machine instructions. - The Java bytecode interpreter is often called the Java Virtual machine or the Java Runtime. By the traditional language, a program is compiled into machine code or processor instructions. - These instructions are specific to the processor your computer is running. 11/9/2018
9
Platform Independence
Java: Traditional compiler: Java code code Java Compiler compiling SPARC compiler Power compiler Pentium compiler compiling Java Bytecode interpreting SPARC Power PC Pentium SPARC Power PC Pentium 11/9/2018
10
Java Virtual Machine The JVM is different for each platform because each machine has a different machine instruction set. - But all JVMs take Java bytecode as input. Interpreters are slower than compilers because they translate as they go. Using the “Just-In-Time” compiler, Java increases the execution speed which rivals that of C++. 11/9/2018
11
Java is Multi-Threaded
Multithreading can be loosely defined as the simultaneous execution of multiple processes within a program. Java is inherently multi-threaded. - For example, multiple applets can run on the same web page with each applet receiving more or less equal CPU time. Downside to multi-threading - Errors in using threads can be very difficult to locate. 11/9/2018
12
A simple Java Program Let’s take a look at a simple program
import java.lang.*; //A simple Java application public class HelloWorld { public static void main(String args[]) { System.out.println(“HelloWorld!”); } 11/9/2018
13
Java Download and Program Execution
Java Download (JDK1.1.8) - (you’ll see a table.) In the first item of the table, click “continue” button. (you’ll see the license information.) click “ACCEPT” button jdk-1_1_8_004-win.exe will be stored in your computer. - PATH and CLASSPATH setting (Windows 95/98) Example: (in Autoexec.bat file) PATH C:\Novell\Client32;%PATH%;C:\jdk1.1.8\bin set CLASSPATH=.;jdk1.1.8\bin\..\classes;jdk1.1.8\lib\classes.zip 11/9/2018
14
Java Download and Program Execution
Java Download (JDK1.4) - (you’ll see J2SE SDK Click on this, you’ll get another page for downloading Click on “download” You’ll see a table with title “Dowload J2SE v 1.4.2_03” Click on “download” under “SDK” (you’ll see the license information) click “ACCEPT” button. In the next page, click on Windows Offline Installation, Multi-language (j2sdk-1_4_2_03-windows-i586-p.exe, MB) 11/9/2018
15
Change path environment variable: For windows 2000,
My Computer Control panel System click on Tab “Advanced” click on “Environment Variables …” edit the system variable “Path” by adding ;C:\J2SDK-1_4_2_03\bin RealJ Download Using Google or Yahoo to find ‘RealJ’ home page; and then download it onto your computer. 11/9/2018
16
Java Download and Program Execution
- The code should be written in a plain text editor; not a word processor. The file name must be of the form: <filename>.java; <filename> must match the public class name stored in it. Example: HelloWorld.java - You would then compile the program using “javac”, the Java compiler. Example: javac HelloWorld.java - A class, for example, HelloWorld.class, will be produced. - The final step is to run the program: java HelloWorld This will print “HelloWorld!” onto the screen. 11/9/2018
17
What is the difference between the object-oriented method
and the traditional programming method with files? What is the platform-independence? 11/9/2018
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.