basic of java-language

Upload: adeeti-chopra-s

Post on 05-Apr-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Basic of JAVA-Language

    1/27

    7/13/12

    INTRODUCTION to JAVA Java was conceived by James Gosling, Patrick

    Naughton, Chris Warth, Ed Frank, and MikeSheridan at Sun Microsystems, Inc. in 1991name with Oak

    In 1992 this can be used in hand held devices

    1993 this cab be used in WWW applications

    the same team in 1994 Hotjava bower isdeveloped ,it is more popular internet users.

    This language was initially called Oak but wasrenamed Java in 1995

    1996 java itself established not only internet

    program but also general purpose, and OOPlanguages.

  • 7/31/2019 Basic of JAVA-Language

    2/27

    7/13/12

    The Bytecode

    Bytecode is a highly optimized set ofinstructions designed to be executedby the Java run-time system, which is

    called theJava Virtual Machine (JVM). That is, in its standard form, the JVM

    is an interpreter for bytecode. This

    may come as a bit ofa surprise

  • 7/31/2019 Basic of JAVA-Language

    3/27

    7/13/12

    Java Features

    Simple Secure

    Portable

    Object-oriented

    Robust

    Multithreaded Architecture-neutral

    Interpreted

    Hi h erformance

  • 7/31/2019 Basic of JAVA-Language

    4/27

    7/13/12

    SimpleJava is simple because there are

    various features that makes the java

    as a simple language. Programs are

    easy to write and debug because

    java does not use the pointers

    explicitly, operator overloading ,multiple inheritance, process header

    files, goto stement

  • 7/31/2019 Basic of JAVA-Language

    5/27

    7/13/12

    Object-OrientedTo be an Object Oriented language, any

    language must follow at least the four

    characteristics.

    Inheritance

    Encapsulation

    Polymorphism

    Dynamic binding

    R

  • 7/31/2019 Basic of JAVA-Language

    6/27

    7/13/12

    Ro ust

    Java is a strictly typed language, it

    checks your code at compile time.

    Java has the strong memory

    allocation and automatic garbage

    collection mechanism.

    It provides the powerful exception

    handling and type checking

  • 7/31/2019 Basic of JAVA-Language

    7/27

    7/13/12

    Multithreaded Multi thread means handling multiple

    tasks simultaneously

    Java supports multithreaded

    programming, which allows you to

    write programs that do many things

    simultaneously.

    Java is also a Multithreaded

    programming language.

  • 7/31/2019 Basic of JAVA-Language

    8/27

    7/13/12

    Architecture-Neutral One of the main problems facing

    programmers is that no guaranteeexists that if you write a programtoday, it will run tomorroweven on

    the same machine Operating system upgrades,

    processor upgrades, and changes in

    core system resources can allcombine to make a programmalfunction

  • 7/31/2019 Basic of JAVA-Language

    9/27

    7/13/12

    The Java compiler does this by

    generating byte code instructions, to

    be easily interpreted on any machine

    and to be easily translated intonative machine code

    The compiler generates an

    architecture-neutral object file format

  • 7/31/2019 Basic of JAVA-Language

    10/27

    7/13/12

    Interpreted and HighPerformance

    Java enables the creation ofcross-platform programs by compiling intoan intermediate representation called

    Java bytecode. This code can beinterpreted on any system thatprovides a Java Virtual Machine

    Other interpreted systems, such asBASIC, Tcl, and PERL, suffer fromalmost insoluble performance deficits.

    Java, however, was designed to-

  • 7/31/2019 Basic of JAVA-Language

    11/27

    7/13/12

    Distributed

    Java is designed for the distributedenvironment of the Internet, becauseit handles TCP/IP protocols, HTTP and

    FTP are developed in java In fact, accessing a resource using a

    URL is not much different from

    accessing a file. Internet programmers can call

    functions on these protocols and can

    get access the files from any remote

    http://www.roseindia.net/java/java-introduction/java-features.shtmlhttp://www.roseindia.net/java/java-introduction/java-features.shtml
  • 7/31/2019 Basic of JAVA-Language

    12/27

    7/13/12

    Dynamic Dynamic Java programs carry with

    them substantial amounts of run-time type information that is used toverify and resolve accesses to

    objects at run time.This makes it possible to dynamically

    link code in a safe and expedient

    manner.Java is capable of dynamically linking

    in new class libries, methods and

    objects.

  • 7/31/2019 Basic of JAVA-Language

    13/27

    7/13/12

    Portability

    The feature Write-once-run-anywhere makes the javalanguage portable provided that the system must haveinterpreter for the JVM.

    programs to be dynamically downloaded

    to all the various types of platformsconnected to the Internet, some means ofgenerating portable executable code isneeded.

    the same mechanism that helps ensuresecurity also helps create portability

  • 7/31/2019 Basic of JAVA-Language

    14/27

    7/13/12

    Security

    Java system verify all memory accessbut also ensure that no virus are

    communicated with appletJava achieves this protection by

    confining a Java program to the Java

    execution environment and notallowing it access to other parts of thecomputer.

    The absence of pointers that

  • 7/31/2019 Basic of JAVA-Language

    15/27

    7/13/12

    Java environment

    JDK (java development KIT)collection of tools

    Appletviewer ( java compatiblebrowser)

    Javac ( compiler)

    Java (interpreter)Javap( dis assembler) : convert the

    bytcode to program

    Javah : produces the header files for

  • 7/31/2019 Basic of JAVA-Language

    16/27

    7/13/12

    JAVA API Language support package

    Utilities package

    Input /Out package

    Networking package AWT package

    Applet package

  • 7/31/2019 Basic of JAVA-Language

    17/27

    7/13/12

    Data Types, Variables,and Arrays

    Integers This group includes byte,short, int, and long, which are forwhole valued signed numbers.

    Floating-point numbersThis groupincludes float and double, whichrepresent numbers with fractional

    precision.

    Characters This group includes char,which represents symbols in a

    character set, like letters and numbers.

  • 7/31/2019 Basic of JAVA-Language

    18/27

    7/13/12

    Integers

    long 64 9,223,372,036,854,775,808 to

    9,223,372,036,854,775,807

    int 32 2,147,483,648 to2,147,483,647

    short 16 32,768 to 32,767

    byte 8 128 to 127

  • 7/31/2019 Basic of JAVA-Language

    19/27

    7/13/12

    Floating-Point Types

    Double 64 4.9e324 to1.8e+308

    float 32 1.4e045 to 3.4e+038

    Literals

    Integer Literals

    Floating-Point Literals

    Boolean Literals

    Ch t E

  • 7/31/2019 Basic of JAVA-Language

    20/27

    7/13/12

    Character EscapeSequences

    Escape Sequence Description \ddd Octal character (ddd)

    \uxxxx Hexadecimal UNICODE

    character (xxxx) \ Single quote

    \ Double quote

    \\ Backslash

    \r Carriage return

    \n New line (also known as line

  • 7/31/2019 Basic of JAVA-Language

    21/27

    7/13/12

    VariablesThe variable is the basic unit of

    storage in a Java program. A variableis defined by the combination of anidentifier, a type, and an optional

    initializer. In addition, all variables have a

    scope, which defines their visibility,

    and a lifetime Declaring a Variable

    type identifier[ = value][, identifier [=

    value] ...] ;

  • 7/31/2019 Basic of JAVA-Language

    22/27

    7/13/12

    Arrays

    One-Dimensional Arrays type var-name[ ];

    int month_days[];

    int month_days[] = { 31, 28, 31, 30,31, 30, 31, 31, 30, 31, 30, 31 };

    Multidimensional Arrays

    int twoD[][] = new int[4][5];

  • 7/31/2019 Basic of JAVA-Language

    23/27

    7/13/12

    Sample program

    /*

    This is a simple Java program.

    Call this file "Example.java". */

    import java.io.*;

    import java.util.*;

    class Example {

    // Your program begins with a call to

  • 7/31/2019 Basic of JAVA-Language

    24/27

    7/13/12

    Progrm-ii

    import java.io.*;

    import java.util.*;

    class Example2 {

    public static void main(String args[]) {

    int num; // this declares a variablecalled num

    num = 100; // this assigns num the

    value 100

  • 7/31/2019 Basic of JAVA-Language

    25/27

    7/13/12

    Using arrays

    class Average {

    public static void main(String args[]){

    double nums[] = {10.1, 11.2, 12.3,13.4, 14.5};

    double result = 0; int i;

    for(i=0; i

  • 7/31/2019 Basic of JAVA-Language

    26/27

    7/13/12

    Two dimensional arrays

    class TwoDArray {

    public static voidmain(String args[]) {

    int twoD[][]= newint[4][5];

  • 7/31/2019 Basic of JAVA-Language

    27/27

    7/13/12

    0 1 2 3 4

    5 6 7 8 9

    10 11 12 13 14

    15 16 17 18 19