introduction to java - sharif university of...
TRANSCRIPT
Introduction to Java
Computer Engineering DepartmentSharif University of Technology
1st Quiz
2
1st Quiz
1.What is Object?
2.What is Class?
3.What are the properties of an Object Oriented Programming? Define them!
2
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
Programming Language
3
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.
Interpret vs. Compile
4
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.
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
Platform Independency
6
Slot 1
Slot 2
Slot 3
The
Device
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?
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?
Entering the Java world!
Edit your java files
Compile your files
Run the class file
Java file
Class file
7
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
1st Exercise8
/* * This is your first java program. */
class HelloWorld{public static void main(String[] args){System.out.println(“Hello World!”);
}}
Edit your java file
9
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
Java Compilation
10
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).
Compile HelloWorld
11
$javac HelloWorld.java
Compile HelloWorld
• Java files can be compiled with javac (Java Compiler)
• Now a file named HelloWorld.class is generated.
11
$javac HelloWorld.java
Running Java Classes
12
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
Run HelloWorld
13
$java HelloWorld
Run HelloWorld
• Use java to run the class file.
13
$java HelloWorld
Any Questions?