Intro to JAVA - PowerPoint PPT Presentation

About This Presentation
Title:

Intro to JAVA

Description:

Was initially called 'Oak' but was renamed JAVA. Originally it was not developed for ... System.out.println ('Hypotenuse is ' c); 04/07/04. 10. Variable scope ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 26
Provided by: Gue145
Category:
Tags: java | hypotenuse | intro

less

Transcript and Presenter's Notes

Title: Intro to JAVA


1
Intro to JAVA
  • By
  • Riyaz Malbari

2
History of JAVA
  • Came into existence at Sun Microsystems, Inc. in
    1991.
  • Was initially called Oak but was renamed JAVA.
  • Originally it was not developed for the Internet
    but as a software to be embedded in various
    consumer electronic devices.
  • Derives much of its character from C/C.

3
Types of Programs
  • Applications
  • a program that runs on the computer, under its
    operating system.
  • it is like a normal program created using C/C.
  • Applets
  • a tiny JAVA program that can be transmitted over
    the Internet.
  • it is an intelligent program.

4
Bytecode
  • output of a JAVA compiler is Bytecode.
  • executed by the JAVA run-time system, which is
    called the JAVA Virtual Machine (JVM).
  • creates truly portable programs.
  • assures security while downloading programs over
    the Internet.

5
JAVA Virtual Machine
6
Object-Oriented Programming
  • The core of JAVA
  • Encapsulation
  • Inheritance
  • Polymorphism

7
A simple program
  • / A program to display the message Hello World.
  • Call this file hello.java. /
  • class hello
  • // The program begins with a call to
    main().
  • public static void main (String args )
  • System.out.println (Hello World.)
  • save as text file hello.java
  • at command line typegtjavac hello.java
  • execute program by typinggtjava hello

8
Data Types
  •   
  • Type Size Range
  •  
  •  byte 8 bits -128 to 127
  • short 16 bits -32768 to 32767
  • int 32 bits -2147483648 to 2147483647
  • long 64 bits -9223372036854775808 to
    9223372036854775807
  • float 32 bits 1.7e-308 to 1.7e308
  • double 64 bits 3.4e-038 to 3.4e038
  • char 16 bits 0 to 65536
  • boolean --------- true or false

9
Variables
  • basic unit of storage
  • a combination of an identifier, a type and an
    optional initializer
  • Syntax type identifier value,
    identifiervalue,
  • eg. int a,b,c
  • int d4, e, f7
  • byte w12
  • double pi3.14159
  • char xx
  • Dynamic initialization
  • class DyIn
  • public static void main (String args
    )
  • double a3.0, b4.0
  • double cMath.sqrt
    (aabb) // c is dynamically initialized
  • System.out.println (Hypotenuse is
    c)

10
Variable scope
  • scope is defined by a block
  • variables that are defined within the scope are
    not visible to the code that is defined outside
    the scope.
  • scopes can be nested
  • objects declared in the outer scope will be
    visible to code within the inner scope
  • eg. class Scope
  • public static void main (String args
    )
  • int x // known to
    all code within main
  • x10
  • if (x 10)
  • int y20 //
    known only to this block

  • System.out.println (x and y x y )
  • xy2
  • y 100 // y
    is unknown here and so there is a compile-time
    error
  • variables declared in the inner and outer scope
    cannot have the same name
  • eg. class scopeerr
  • public static void main (String args )

11
Arrays
  • collection of variables of the same data type
    addressed by a common name
  • an array element is accessed by its index
  • can have one or more dimensions
  • one-dimensional array
  • declaration type var_name
  • eg. int month
  • allocation var_namenew typesize
  • eg. month new int12
  • both can be done together int month
    new int12
  • assignment month0 31

  • month1 28
  • values can also be assigned during declaration
  • int month 31, 28, 31, 30, 31, 30, 31, 31,
    30, 31, 30, 31
  • Multi-dimensional arrays int twoD new
    int23

12
Class
  • fundamental concept in JAVA
  • defines a data type which can be used to create
    objects of that type
  • class is a template for an object and object is
    an instance of a class
  • declared by the class keyword
  • Syntax class classname
  • type var
  • type methodname (parameter
    list)

  • // body of method

Methods
Instance variables
Class Members
13
Example
  • class Box
  • double width
  • double height
    // This class declares an object of type
    Box.
  • double depth
  • class BoxDemo
  • public static void main (String
    args )
  • Box mybox new Box()
    // An object called mybox is created
  • double vol
  • // Assign values to myboxs instance
    variables.
  • mybox .width 10
  • mybox .height 20
  • mybox .depth 15
  • vol mybox .width mybox .height
    mybox .depth
  • System.out.println (The volume is vol)

14
  • changing the instance variables of one object
    have no effect on that of another
  • class Box
  • double width
  • double height
  • double depth
  • class BoxDemo
  • public static void main (String
    args )
  • Box mybox1 new Box()
  • Box mybox2 new Box()
  • double vol
  • mybox1 .width 10
  • mybox1 .height 20
  • mybox 1.depth 15
  • mybox2 .width 3

15
  • adding a method to the box class
  • class Box
  • double width
  • double height
  • double depth
  • void volume()
  • System.out.println (Volume is (width
    height depth))
  • class BoxDemo
  • public static void main (String
    args )
  • Box mybox new Box()
  • double vol
  • mybox .width 10
  • mybox .height 20

16
  • Returning a value
  • class Box
  • double width
  • double height
  • double depth
  • double volume()
  • return width height depth
  • class BoxDemo
  • public static void main (String
    args )
  • Box mybox new Box()
  • double vol
  • mybox .width 10
  • mybox .height 20
  • mybox .depth 15
  • vol mybox .volume()

17
Constructors
  • initializes the object immediately upon creation
  • has the same name as that of the class
  • class Box
  • double width
  • double height
  • double depth
  • Box() // A constructor for the
    Box class
  • width 10
  • height 20
  • depth 15
  • double volume()
  • return width height depth
  • class BoxDemo

18
Method Overloading
  • implementation of polymorphism
  • two or more methods within the same class have
    the same name but different parameter
    declarations
  • overloaded methods must differ in the type and/or
    number of their parameters
  • class OverloadDemo
  • void test()
  • System.out.println (No
    parameters)
  • void test(int a) //
    Overload test for one integer parameter
  • System.out.println (a a)
  • void test(int a, int b) // Overload
    test for two integer parameters
  • System.out.println (a and b
    a b)
  • class Overload
  • public static void main (String args
    )
  • OverloadDemo ob new
    OverloadDemo()
  • ob.test()
  • ob.test(10)

19
Inheritance
20
class A // Creating a superclass A
int i, j void showij()
System.out.println (i and j i
j) class
B extends A // Creating a subclass B by
extending class A int k
void showk()
System.out.println (k k)
void sum()
System.out.println (i j k (i j k))
class
Inheritance public static void
main (String args) A
superOb new A() B subob new
B() superOb.i 10
superOb.j 20
superOb.showij() subOb.i 3
subOb.j 6 subOb.k
9 subOb.showij()
subOb.showk() subOb.sum()

21
Packages
  • partitions the class name space
  • classes defined in a package are not accessible
    by code outside that package
  • syntax package package_name
  • the import statement is used to bring certain
    packages or the entire package into visibility
  • package Demo
  • class Balance
  • String name
  • double bal
  • Balance(String n, double b)
  • name n
  • bal b
  • void show()
  • System.out.println(name
    bal)
  • class AccBal
  • public static void main(String args )

22
Access Specifiers
  • public No restrictions.
    Accessible from anywhere.
  • private Only accessible from
    within the class.  
  • package Accessible from package
    members.
  • protected Also accessible from
    subclasses and package members.

23
JAVA for Security
  • Basic concepts
  • Authentication
  • Authorization
  • Confidentiality
  • Integrity
  • JAVA tools
  • JAAS (JAVA Authentication And Authorization
    Service)
  • JSSE (JAVA Secure Socket Extensions)
  • GSS-API (JAVA Generic Security Service
    Application Programming
    Interface)

24
JAVA Security Mechanisms

25
Thank you!
Write a Comment
User Comments (0)
About PowerShow.com