Concepts of Java programming, - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Concepts of Java programming,

Description:

... CPU, which is expensive and time consuming to create (.i.e windows and linux C compiler) ... Why Java is Important to the Internet ... – PowerPoint PPT presentation

Number of Views:100
Avg rating:3.0/5.0
Slides: 25
Provided by: ahs8
Category:

less

Transcript and Presenter's Notes

Title: Concepts of Java programming,


1
Lecture 1
  • Concepts of Java programming,
  • Data types,
  • Variables and Expressions

2
Javas lineage
  • Java is related to C, which is direct
    descendent of C
  • From C, Java derives its syntax
  • Many of Javas object-oriented features were
    influenced by C
  • OOP is a programming methodology that helps
    organize complex programs through the use of
    inheritance, encapsulation and polymorphism

3
The creation of JAVA
  • Java was developed at Sun Microsystems at 1991,
    after an effort of 18 months
  • The original impetus for Java was not Internet!
    Instead the primary motivation was the need for a
    platform-independent language that could be used
    to create software to be implemented in various
    consumer electronic devices, such as microwave
    ovens and remote controls
  • The trouble with other languages is that they are
    designed to be complied for a specific target

4
The creation of JAVA (Contd.)
  • We know, compilation of a language requires a
    compiler targeted for that CPU, which is
    expensive and time consuming to create (.i.e
    windows and linux C compiler)
  • So effort was given to develop a
    platform-independent language that could be used
    to produce code that would run on a variety of
    CPUs under differing environments. The ultimate
    result is Java
  • A second force worked behind the creation of
    Java, that is the emergence of World Wide Web or
    Internet
  • The code for internet required portability and
    this realization caused the focus of Java to
    switch from consumer electronics to Internet
    programming

5
Why Java is Important to the Internet
  • In a network, two very broad categories of
    objects are transmitted between server and your
    PC
  • passive information (i.e. email, programs code)
  • Dynamic, active programs (i.e. self-executing
    program). Such a program is an active agent on
    the client computer, yet is initiated by the
    server (i.e. applets)
  • An applet is an application designed to be
    transmitted (dynamically downloaded) over the
    Internet and executed by a Java-compatible Web
    browser.
  • Applet is an intelligent program (not just an
    animator or image file or media file) that can
    react to user input and dynamically change

6
Security
  • Whenever you download a program, you are risking
    a viral infection
  • So most users dont download executable programs
    or scan them prior to execution
  • Another type of malicious programs gather private
    information (i.e. credit card numbers, bank
    account balances, passwords etc)
  • Java provides a firewall between a networked
    application and your computer
  • Also Java achieves the protection by confining a
    Java program to the Java execution environment
    and not allowing it access to other parts of the
    computer

7
Javas Magic The Bytecode
  • The secret behind the security and portability of
    Java is that the output of a Java compiler is not
    executable code. Rather, it is bytecode
  • Bytecode is a highly optimized set of
    instructions designed to be executed by the Java
    run-time system, which is called the Java Virtual
    Machine (JVM)
  • JVM is an interpreter of bytecode

8
Basics of a Typical Java Environment
  • Java systems contain
  • Environment
  • Language
  • APIs
  • Class libraries

9
Basics of a Typical Java Environment (cont.)
  • Java programs normally undergo five phases
  • Edit
  • Programmer writes program (and stores program on
    disk)
  • Compile
  • Compiler creates bytecodes from program
  • Load
  • Class loader stores bytecodes in memory
  • Verify
  • Verifier ensures bytecodes do not violate
    security requirements
  • Execute
  • Interpreter translates bytecodes into machine
    language

10
Fig A typical Java environment.
11

12
Benefits of bytecode
  • Translating a Java program into bytecode helps
    makes it much easier to run a program in a wide
    variety of environments
  • Only JVM needs to be implemented for each
    platform
  • Once the run-time package exists for a given
    system, any java program can run on it

13
  • An overview of JAVA

14
Object Oriented Programming
  • Two paradigms of programming
  • Process-oriented model characterizes a program
    as a series of linear steps (i.e. C)
  • What is happening?
  • Code acting on data
  • Object-oriented programming organizes a program
    around its data (that is, objects) and a set of
    well-defined interfaces to that data
  • Who is being affected?
  • Data controlling access to code

15
Essential elements of OOP
  • Abstraction (the way humans manage complexity)
  • i.e. people dont think of a car as a set of tens
    of thousands individual parts. They think of it
    as a well-defined object with its own unique
    behavior. They are free to utilize the object as
    a whole
  • A complex system can be broken into more
    manageable pieces, which are hidden by
    hierarchical abstraction
  • The three OOP Principles
  • Encapsulation
  • Inheritance
  • Polymorphism

16
Inheritance
17
A First Simple Program
  • /
  • This is a simple Java program. Call this file
    "Example.java".
  • /
  • class Example
  • // Your program begins with a call to main().
  • public static void main(String args)
  • System.out.println("This is a simple Java
    program.")

18
Entering the program
  • The name of a source file is very important
  • In Java, all code must reside inside a class. By
    convention, the name of that class should match
    the name of the file that holds the program
  • A source file use the .java filename extension
  • Java is case-sensitive

19
Compiling the Program
  • Cgt\javac Example.java
  • The javac compiler creates a file called
    Example.class, that contain the bytecode version
    of the program
  • To actually run program, you must use the Java
    interpreter, called java
  • Cgt\java Example
  • When java source code is compiled, each
    individual class is put into its own output file
    named after the class and using the .class
    extension

20
A closer look at the first program
  • All Java application begin execution by calling
    main()
  • A complex program will have dozens of classes,
    only one of which will need to have a main()
    method to get things started
  • Java applets dont have any main() method
  • Java interpreter run only the class that have a
    main method
  • println() is a built-in method
  • System is a predefined class that provides access
    to the system, and out is the output stream that
    is connected to the console

21
Control statements
  • if (condition) statement
  • for(initializationconditioniteration) statement

22
Lexical issues
  • White space between tokens
  • Identifiers
  • Literals (the way constant value is created)
  • Integer
  • Floating point
  • Character
  • String
  • Comments
  • Separators
  • Keywords

23
Data types
  • Integers
  • long (64 bit)
  • int (32 bit)
  • short (16 bit)
  • byte (8 bit)
  • Floating-pointer numbers
  • double (64 bit)
  • float (32 bit)
  • Characters (char, 8 bit)
  • Booleans (boolean, true or false)

24
Arrays
  • Arrays in Java work differently than they do in
    other languages
  • First declare the array
  • int month_days
  • Then allocate memory
  • month_daysnew int12
  • Arrays can be initialized during declaration
  • Multidimensional arrays
  • int twoDnew int45
  • Alternative array declaration
  • int a2new int3
  • String type object
Write a Comment
User Comments (0)
About PowerShow.com