Introduction To Programming: Sheikh Qaisar Ayub, Sulma Rashid

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 24

Sheikh Qaisar Ayub, Sulma Rashid

Prepare these presentations to help new students to build the


programming
Skills in JAVA.
(SCJP.6 certified Professional)

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)

What is Computer Program ?


“Sequence of instructions given to computer in order to carry out a task”

What is difference between computer programs and software ?

Types of Software/programs User


System Software
Application program
Application Software
Operating System

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

GOALS of JAVA Language

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

GOALS of JAVA Language

Java Is Architectural Natural


• As java use interpreted code, hence code written in java can run on any plate from, it is
independed of architecture of hardware.

Java programs are portable


• Due to architecture independed, once java program compiled can be executed on any plate
form.
Java Is Multithreaded
• A java program can perform multiple task at same time.

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

How ? JVM (Java Virtual Machine)

• Java byte code runs on specific type of microprocessor called JVM.


• Unlike physical microprocessor ,JVM is a logical component of JAVA.
• The Java Virtual Machine is responsible for interpreting Java byte code and translating this into
actions or Operating System calls

Java Program

Compilation

Byte Code

JVM

Windows Linux Unix


Introduction to Programming

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.

• Frame (Reference Frame): Pointer to the current method in execution.


• Optop (Operand top): Pointer to the top of operand stack, used to evaluate the Athmetic.
• PC (Program counter): Contains the address of next byte code to be executed.
• Var (variable register): Contains the address of next byte code to be executed.
Introduction to Programming

The stack

The Java Virtual Machine uses an operand stack to supply parameters to methods and operations,
and to receive results back from them

Follow LIFO (Last in First out) methodology.

• 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

Garbage Collection heap


Each program running in the Java runtime environment has a garbage-collected heap assigned to
It and instance of class allocated memory from this heap.

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

• Allocated memory that is no longer needed should be deallocated


• In other languages, deallocation is the programmer’s responsibility
• The Java programming language provides a systemlevel thread to track memory allocation

• Garbage collection:
• Checks for and frees memory no longer needed
• Is done automatically
• Can vary dramatically across JVM implementations
Introduction to Programming

Class File Format javap -c -s -verbose MyEnv

• 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

Java Run Time Environment (JRE)


Offers a library for Java Virtual Machines (JVM) to execute applications and applets scripted in Java.
• Loads code
• Verifies code
• Executes code

Java Class Loader


• The class which is referenced inside progarame/class(static void main())which is currently
running is loaded by java class loader.

• Class loader determines when and how classes can be loaded in JRE,from loacal and external.

Types of Class Loader


User define class loader
System Define class loader
Introduction to Programming

Java Byte code Verifier


when an JAVA application imports a code fragment from anywhere, it doesn't actually know if
code fragments follow Java language rules for safety: the code may not have been produced
by a known-to-be trustworthy Java compiler.

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

Writing Program in JAVA


• Java API
• Java 2 Standard Edition(J2SE)
• Java 2 Enterprise Edition (J2EE)
• Java 2 Micro Edition (J2ME)
Note
JDK consist of set of separate programs for developing and testing java programs invoked from
command line.

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

COMPILE TIME ERRORS

(1) javac: Command not found


Because of javac command is not in path variable
(2) TestGreet.java:4: Public class TestGreeting must be defined in a file called "TestGreeting.java".
Because of Classname and file name is different

RUN TIME ERRORS

(1) Can’t find class TestGreeting Exception in thread "main“ java.lang.NoSuchMethodError: main

When try to run a programe without main function/method


Thanks
References

1) A programmer guide to Java SCJP Certification by Khalid A.Mughal,Rolf W.


Rasmussen (Third Edition).
2) SCJP Sun Certified Programmer for Java 6 Exam 310-065 [Hardcover] (Author)
Katherine Sierra , Bert Bates
3) Core Java: Volume I, Fundamentals.
4) Teach yourself Java in 21 days.
5) Head First Java.
6) Java Complete Reference.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy