Introduction To Programming: Sheikh Qaisar Ayub, Sulma Rashid
Introduction To Programming: Sheikh Qaisar Ayub, Sulma Rashid
Introduction To Programming: Sheikh Qaisar Ayub, Sulma Rashid
Introduction to Programming
Lecture 01
sheikhqaisar@gmail.com
Introduction to Programming
What is Language ?
“Language is mean of communication”
What is Computer Language ?
“Computer language is mean of communicating with computer”
Types of Computer Language ?
High Level Language (needs Interpreter/Compiler)
Low Level Language (Instructions directly given to computer)
Hardware
Introduction to Programming
What is JAVA ?
Java is computer language developed by under team leader Gosling at sun Microsystems in 1991
with name Oak, renamed with JAVA in 1995.
Web Programming/applets:
Introduction to Programming
What is JAVA ?
Develop applications on server side: JAVA SERVLET
Introduction to Programming
What is JAVA ?
Develop applications on server side: JAVA SERVLET
Introduction to Programming
What is JAVA ?
Develop Desktop Applications
Introduction to Programming
What is JAVA ?
Mobile applications
Introduction to Programming
Java Is Simple
• Java is simple as compared to C++.
• Automatic memory management and garbage collection.
• Well documented easy to understand syntax.
Java Is Object Oriented
• Provide reusability / security.
Java Is Distributed
• Distributed computing involves where several computers working as unit to perform a task.
Java Is Interpreted
• A program compiled in java can be executed on all platforms.
Java Is Robust
• A java compiler can detect many errors at compile time which may appear as exception in
case of other languages.
Java Is Secure
• When java applet execute it prevents harmful action by applications.
Introduction to Programming
Java Is Dynamic
• New features can be added in JAVA, without any modification to existing application.
How these Goals are achieved ?
JVM
Garbage collection
Code security
Introduction to Programming
Byte Code
Most of Languages (C++,PASCAL compile source code of program into machine code which depends
on specific machine architecture.
Drawback
If machine architecture changes, needs to recompile the program.
Source Code
Java
Compiler
Byte Code
Introduction to Programming
Java Program
Compilation
Byte Code
JVM
Part of JVM
• A set of registers
• A stack
• A garbage-collected heap
• A method storage area
• An instruction set
• Class file format
Registers
Registers in java are used to maintain the state of the registers.
The Registers are updated after execution of each line of Byte code.
The stack
The Java Virtual Machine uses an operand stack to supply parameters to methods and operations,
and to receive results back from them
• isub byte code instruction expects two integers to be stored on the top of the stack
• It means that the operands must have been pushed there by the previous set of instructions.
• isub pops the operands off the stack, subtracts them.
• pushes the results back onto the stack.
Introduction to Programming
Heap size is IMB,as java program runs heap size grows, in order to maintain the heap, automatic
Garbage collection thread is executed to deallocate memory from unused objects.
Garbage Collection
• Garbage collection:
• Checks for and frees memory no longer needed
• Is done automatically
• Can vary dramatically across JVM implementations
Introduction to Programming
• Java source file compiled code represented using a format known as the class file format.
• The class file format precisely defines the representation of a class, including details such as
byte ordering that might be taken for granted in a platform-specific object file format.
Instruction set
• Each processor understand the special set of instructions, INTEL CPU execute different
Instructions set then Motorola cup inside Apple.
• Each instruction set consist of a number which tells the CPU what to do.
• C6 06 64 00 01 (ADD 1 at memory address 100).
http://www.xs4all.nl/~mpdeboer/scriptie/node17.html#SECTION02421000000000000000
Introduction to Programming
• Class loader determines when and how classes can be loaded in JRE,from loacal and external.
Type correctness: The arguments of an instruction are always of the types expected by the instruction.
istore_1 Instruction shows that variable of type integer, iadd addition of integers
Code containment: The program counter must always point within the code for the method.
Register initialization: Registers that do not correspond to method parameters are not initialized on
method entrance, and it is an error to load from an uninitialized register.
Object initialization: when an instance of a class C is created, one of the initialization methods for class
C (corresponding to the constructors for this class) must be invoked before the class instance can be
used.
Data Conversions: No conversion (from integer to pointer)
Stack Protection: The code causes no operand stack overflows or underflows.
Java Runtime Environment
abc.java
Compile
abc.class (1) Class Loader (2) Byte Code verifier (3) Interpreter (4)Hardware
Compilation JRE
Introduction to Programming
Editors
DrJava: (http://drjava.sourceforge.net/)
JEdit: (http://www.jedit.org/)
JBuilder: (http://www.borland.com/)
Eclipse: (http://www.netbeans.org/)
Introduction to Programming
Javac TestGreeting
Java TestGreeting
Introduction to Programming
(1) Can’t find class TestGreeting Exception in thread "main“ java.lang.NoSuchMethodError: main