Computer Science - PowerPoint PPT Presentation

1 / 45
About This Presentation
Title:

Computer Science

Description:

Java is just a small, simple, safe, object-oriented, interpreted or dynamically ... the Java API and the virtual machine insulate the program from the hardware ... – PowerPoint PPT presentation

Number of Views:130
Avg rating:3.0/5.0
Slides: 46
Provided by: kurtul
Category:

less

Transcript and Presenter's Notes

Title: Computer Science


1
Computer Science Engineering Department
ofHacettepe University
1 July 2003 R. A. Kurtulus GÜNGÖR Kurtulus_at_cs.hace
ttepe.edu.tr
2
What Java is?
  • Java is just a small, simple, safe,
    object-oriented, interpreted or dynamically
    optimized, byte-coded, architecture-neutral,
    garbage-collected, multithreaded programming
    language with a strongly typed exception-handling
    mechanism for writing distributed, dynamically
    extensible programs.

3
Simple, Object Oriented, and Familiar
  • The most complex parts of C were excluded from
    Java, such as pointers and memory management.
    These elements are complicated to use, and are
    thus easier to use incorrectly. Memory management
    occurs automatically in Java-programmers do not
    have to write their own garbage-collection
    routines to free up memory.
  • Another design decision to make Java simpler is
    its elementary data types and objects.

4
Java Is Object Oriented
  • Object-oriented programs are more adaptable for
    use in other projects, easier to understand, and
    more bugproof.

5
Java Is Safe
  • Java was designed to make it extremely difficult
    to execute damaging code. The elimination of
    pointers is a big step in this regard. Pointers
    are a powerful feature, as the programmers of
    C-like languages can attest, but pointers can be
    used to forge access to parts of a program where
    access is not allowed, and to access areas in
    memory that are supposed to be unalterable. By
    eliminating all pointers except for a limited
    form of references to objects, Java is a much
    more secure language.

6
Java Is Safe
  • Java programs are compiled into sets of
    instructions called bytecodes. Before a Java
    program is run, a verifier checks each bytecode
    to make sure that nothing suspicious is going on.
  • In addition to these measures, Java has several
    safeguards that apply to applets. To prevent a
    program from committing random acts of violence
    against a user's disk drives, an applet cannot
    open, read, or write files on the user's system.

7
Java Is Platform Independent
  • Java's variable types have the same size across
    all Java development platforms-so an integer is
    always the same size, no matter which system a
    Java program was written and compiled on.

8
Java bytecodes
  • With most programming languages, you either
    compile or interpret a program so that you can
    run it on your computer. The Java programming
    language is unusual in that a program is both
    compiled and interpreted. With the compiler,
    first you translate a program into an
    intermediate language called Java bytecodes the
    platform-independent codes interpreted by the
    interpreter on the Java platform. The interpreter
    parses and runs each Java bytecode instruction on
    the computer. Compilation happens just once
    interpretation occurs each time the program is
    executed.

9
The following figure illustrates how Java VM
works.
10
write once, run anywhere
  • Java bytecodes help make "write once, run
    anywhere" possible. You can compile your program
    into bytecodes on any platform that has a Java
    compiler. The bytecodes can then be run on any
    implementation of the Java VM. That means that as
    long as a computer has a Java VM, the same
    program written in the Java programming language
    can run on Windows 2000, a Solaris workstation,
    or on an iMac

11
write once, run anywhere
12
The Java Platform
  • A platform is the hardware or software
    environment in which a program runs. We've
    already mentioned some of the most popular
    platforms like Windows 2000, Linux, Solaris, and
    MacOS. Most platforms can be described as a
    combination of the operating system and hardware.
    The Java platform differs from most other
    platforms in that it's a software-only platform
    that runs on top of other hardware-based
    platforms.

13
The Java platform has two components
  • The Java Virtual Machine (Java VM)
  • It's the base for the Java platform and is ported
    onto various hardware-based platforms
  • The Java Application Programming Interface (Java
    API)
  • The Java API is a large collection of ready-made
    software components that provide many useful
    capabilities, such as graphical user interface
    (GUI) widgets. The Java API is grouped into
    libraries of related classes and interfaces
    these libraries are known as packages

14
the Java API and the virtual machine insulate the
program from the hardware

15
Native Code- ByteCode
  • Native code is code that after you compile it,
    the compiled code runs on a specific hardware
    platform. As a platform-independent environment,
    the Java platform can be a bit slower than native
    code. However, smart compilers, well-tuned
    interpreters, and just-in-time bytecode compilers
    can bring performance close to that of native
    code without threatening portability.

16
Managing complexity
  • Procedural abstraction
  • The process is started by expressing a top-most
    statement (or function) that represents the task
    to accomplish. And then step by step the function
    is divided in functions that accomplish more
    basic tasks.
  • Data abstraction
  • the programmer needs to concentrate on the data
    in terms of operations that apply to those data.
    Data are represented by objects and you can them
    perform operations on those objects to observe or
    modify them. This is the Object Oriented
    paradigm.

17
Encapsulation
  • Encapsulation keeps related content together it
    minimizes traffic between different parts of the
    work and it separates certain specified
    requirements from other parts of the
    specification which may use those requirements.

18
The principle of hiding the used data structure
and to only provide a well-defined interface is
known as encapsulation.
  • With a Class, the functions inside the class are
    called private methods, the data inside the class
    are private variables and the interface functions
    for the outside world to your private methods are
    public methods. You can also have public
    variables

19
a Class
20
Inheritance
  • Inheritance allows for the description of objects
    in a hierarchical way.
  • Inheritance is the mechanism which allows a class
    A to inherit properties od class B. Objects of
    class A thus have access to attributes and
    methods of class B without the need to redefine
    them.

21
(No Transcript)
22
Polymorphism
  • Overloading In classical programming you need 2
    different and separate functions to accomplish 2
    different tasks. But sometimes the 2 tasks you
    want to accomplish are very similar and only
    differ in the arguments they use. You wish you
    could give them the same function name and let
    the computer use the correct one based on the
    type of the arguments you give. That's exactly
    what overloading is all about.

23
Polymorphism
  • Recall that in the principal of inheritance,
    objects are a subclass of other objects and
    inherit all of their attributes. More precisely,
    an object will inherit all of the public methods
    and public variables specified in objects higher
    in the object hierarchy. But what if the public
    method of the superclass of a certain object is
    not exactly as you would like it to be ?Well,
    you can redefine the method for that objet and
    still keep the same name

24
Polymorphism
  • The Concept of dynamic binding allows a variable
    to take different types on the content at a
    particular time.
  • Overloading.
  • Objects of superclasses can be filled with
    objects of their subclasses. Operators and
    methods of subclasses can be defined to be
    evaluated on object content.

25
J2ee -Ejb
  • Enterprise JavaBeans (EJB) technology is part
    of a larger framework-- the Java 2 Platform,
    Enterprise Edition (J2EE). This platform is an
    architecture for developing, deploying, and
    executing applications in a distributed
    environment.

26
J2EE Architecture
27
J2EE Server
  • The J2EE server provides the following services
  • Naming and Directory - allows programs to locate
    services and components through the Java Naming
    and Directory Interface (JNDI) API
  • Authentication - enforces security by requiring
    users to log in
  • HTTP - enables Web browsers to access servlets
    and JavaServer Pages (JSP) files
  • EJB - allows clients to invoke methods on
    enterprise beans

28
EJB Container
  • Enterprise bean instances run within anEJB
    container. The container is a runtime environment
    that controls the enterprise beans and provides
    them with important system-level services
  • Transaction Management
  • Security
  • Remote Client Connectivity
  • Life Cycle Management
  • Database Connection Pooling

29
Enterprise Beans
  • Enterprise beans are server components written in
    the Java programming language.
  • Enterprise beans contain the business logic for
    your application.
  • There are two types of enterprise beans
  • session beans
  • entity beans.

30
Session Beans
  • A session bean represents a client in the J2EE
    server. A client communicates with the J2EE
    server by invoking the methods that belong to an
    enterprise bean.
  • Each session bean can have only one client. When
    the client terminates, its corresponding session
    bean also terminates.
  • Therefore, a session bean is transient, or
    non-persistent.

31
Entity Beans
  • An entity bean represents a business object in a
    persistent storage mechanism such as a database.
  • The persistence of an entity bean can be managed
    by either the entity bean itself, or by the EJB
    container.
  • Bean-managed persistence requires you to write
    the data access code in the Bean.
  • Container-managed persistence means that the EJB
    container handles the data access calls
    automatically.

32
Differences Between Session and Entity Beans
33
Using Session and Entity Beans
34
Session Beans State Management Modes
  • Stateful Session Beans
  • The state is retained for the duration of the
    client-bean session. When the client removes the
    bean, the session ends and the state disappears.
    This transient nature of
  • the state is not a problem, however, because
    when the conversation between the client and the
    bean is over there is no need to retain the
    state.
  • Stateless Session Beans

35
Session Beans State Management Modes
  • Stateful Session Beans
  • Stateless Session Beans
  • A stateless session bean does not maintain a
    conversational state for a particular client.
    When a client invokes the method of a stateless
    bean, the beanss instance variables may contain
    a state, but only for the duration of the
    invocation. When the method is finished, the
    state is no longer retained. Except during method
    invocation, all instances of a stateless bean are
    equivalent, allowing the EJB container to assign
    an instance to any client.

36
Life Cycle of a Stateful Session Bean
37
Life Cycle of a Stateless Session Bean
38
Entity Beans
  • Entity beans are
  • Persistent
  • allow shared access
  • Entity beans may be shared by multiple clients.
    Because the clients might want to change the same
    data, its important that entity beans work
    within transactions.
  • have primary keys
  • The unique identifier, or primary key, enables
    the client to locate a particular entity bean.

39
Persistence
  • Because the state of an entity bean is saved in a
    storage mechanism, it is persistent. Persistence
    means that the entity bean exists beyond the
    lifetime of the application or the J2EE server
    process. If youve worked with databases, youre
    familiar with persistent data. The data in a
    database is persistent because it still exists
    even after you shut down the database server or
    the applications it services.

40
Persistence
  • Bean-managed persistence
  • the entity bean code that you write contains the
  • calls that access the database.
  • Container manages persistence
  • If the container manages an entity beans
    persistence, it automatically generates the
    necessary database access calls.
  • For example, when a client creates an entity
    bean,
  • the container generates a SQL insert statement.
    The code that you write for the entity bean does
    not include any SQL calls. The container also
    synchronizes the entity beans instance variables
    with the data in the underlying database.

41
Container-managed persistence Bean-managed
persistence.
  • Entity beans with container-managed persistence
    require less code.
  • Because the beans dont contain the database
    access calls, the code is independent of any
    particular data store, such as a relational
    database.
  • Container-managed persistence has several
    limitations.

42
Life Cycle of an Entity Bean
43
(No Transcript)
44
JavaServer Pages Components
  • A JavaServer Pages (JSP) component may use a
    JavaBeans component as a proxy to access an
    enterprise bean.

45
Resources
  • Introduction to Object Oriented Programming -
    Peter Müller
  • The Java 2 Enterprise Edition Developers Guide
    Version 1.2.1 May 2000
  • Java How To Program - Deitel Deitel
  • http//java.sun.com/docs/books/tutorial/getStarted
    /intro/definition.html
Write a Comment
User Comments (0)
About PowerShow.com