![Page 1: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/1.jpg)
Introduction to Java
Computer Engineering DepartmentSharif University of Technology
![Page 2: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/2.jpg)
1st Quiz
2
![Page 3: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/3.jpg)
1st Quiz
1.What is Object?
2.What is Class?
3.What are the properties of an Object Oriented Programming? Define them!
2
![Page 4: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/4.jpg)
1st Quiz
1.What is Object?
2.What is Class?
3.What are the properties of an Object Oriented Programming? Define them!
2
Your Time is Finished
![Page 5: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/5.jpg)
Programming Language
3
![Page 6: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/6.jpg)
Programming Language
3
• A programming language is an artificial language that can be used to control the behavior of a machine, particularly a computer.
• PLs should support
• Data type, Sequence control, Object, Class, ...
• Java is an OOPL.
![Page 7: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/7.jpg)
Interpret vs. Compile
4
![Page 8: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/8.jpg)
Interpret vs. Compile
4
• Compile
• The program written in a language is translated to another language by another program named compiler.
• Interpret
• The program written in a language is executed statement by statement by another program named interpreter.
![Page 9: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/9.jpg)
5
C
C++
Pascal
Pascal Compiler for Linux
C++ Compiler for Mac
C Compiler for Windows
Pascal Compiler for Windows
Pascal Compiler for Mac
C Compiler for Mac
C Compiler for Linux
C++ Compiler for Mac
C++ Compiler for Mac
Platform and Compiler
![Page 10: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/10.jpg)
Platform Independency
6
Slot 1
Slot 2
Slot 3
The
Device
![Page 11: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/11.jpg)
Platform Independency
6
Slot 1
Slot 2
Slot 3
The
Device
When we have different platforms and a single device,
what can we do to support this device on all platforms?
![Page 12: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/12.jpg)
Platform Independency
6
Slot 1
Slot 2
Slot 3
The
Device
When we have different platforms and a single device,
what can we do to support this device on all platforms?
![Page 13: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/13.jpg)
Entering the Java world!
Edit your java files
Compile your files
Run the class file
Java file
Class file
7
![Page 14: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/14.jpg)
Entering the Java world!
• A Java file contains a class.
• A class contains a main function.
• Java file compiled to byte code file (class file)
• You can run your class.
Edit your java files
Compile your files
Run the class file
Java file
Class file
7
![Page 15: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/15.jpg)
1st Exercise8
/* * This is your first java program. */
class HelloWorld{public static void main(String[] args){System.out.println(“Hello World!”);
}}
![Page 16: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/16.jpg)
Edit your java file
9
![Page 17: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/17.jpg)
Edit your java file
• Any editor can be used
• VIM, Gedit, Textpad, Kedit, Textedit, Notepad, ...
• It’s much more simpler if you use an IDE
• Eclipse, IDEA, Forte, NetBeans, ...
• Java files have .java extension.
9
![Page 18: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/18.jpg)
Java Compilation
10
![Page 19: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/19.jpg)
Java Compilation
10
• The Java Compiler (javac) is used to compiler Java sources into byte code files.
• javac is just available in the Java SDK not JRE.
• Byte code files have .class extension.
• Byte code is the assembly language for the Java Virtual Machine (JVM).
![Page 20: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/20.jpg)
Compile HelloWorld
11
$javac HelloWorld.java
![Page 21: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/21.jpg)
Compile HelloWorld
• Java files can be compiled with javac (Java Compiler)
• Now a file named HelloWorld.class is generated.
11
$javac HelloWorld.java
![Page 22: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/22.jpg)
Running Java Classes
12
![Page 23: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/23.jpg)
Running Java Classes
• Java Virtual Machine (JVM) is used for running class files.
• JVM can run class files.
• Now, there are officially supported JVMs for Linux, Windows, Mac OS X and Solaris.
• JVM is also available for FreeBSD, AIX, Darwin, ...
12
![Page 24: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/24.jpg)
Run HelloWorld
13
$java HelloWorld
![Page 25: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/25.jpg)
Run HelloWorld
• Use java to run the class file.
13
$java HelloWorld
![Page 26: Introduction to Java - Sharif University of Technologyce.sharif.edu/.../resources/root/lectures/presentation4.pdf · 2017-02-07 · Entering the Java world! • A Java file contains](https://reader035.vdocument.in/reader035/viewer/2022081405/5f08863a7e708231d4226fe2/html5/thumbnails/26.jpg)
Any Questions?