Top Banner
Welcome to Java
33

Welcome to Java. 2 History of java Advantages of java Java first program Rules to be followed Data types Operators Casting Control statements.

Dec 22, 2015

Download

Documents

Roxanne Perry
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Welcome to Java

Page 2: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

History of javaAdvantages of javaJava first programRules to be followedData typesOperatorsCastingControl statementsTaking input from

keyboard

ArraysStringsString buffer and string

builderOops conceptsAccess specifiersConstructorsDifferent types of

methodsThis Keyword

contents

Page 3: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Contents continued

Interface and package

ThreadsException handlingGraphical

programmingAwtSwingsApplet

Page 4: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

This is java tutorial from Java Bean this is the demo version of first class

In this tutorial we are going to learn the basic foundations required to learn java

Before getting into java the first question comes to mind is

Is java tough ?

Page 5: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

5

Definitely not !

If yes then how we understand other languages like English, Hindi although our mother tongue may be different how we learnt those languages

We had certain basic foundation through which we Started learning

We started with alphabets A B C D grouped these alphabets to form words .we grouped these words to form sentence

These sentences are used as communication bridge to talk and understand others talk

Page 6: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Similarly we can learn java .here also we have alphabets known as variables, words known as keywords statements known as syntax

By using these syntax we can communicate to computer to perform task

English Java

Alphabets variables

Words Keywords

Statements Syntax

Page 7: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Before stepping into java ,basic knowledge of C& C++ is needed as they are the foundation on which java is been designed

If you don’t have no need to worry in this tutorial required knowledge of C & C++ is covered

Let us begin Java with C program….hello word to know the meaning of Syntax(So called statements)

Page 8: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

#include<stdio.h>

main() {

printf("Hello World"); }

Simple Hello world Program

Page 9: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

# means preprocessor directives

As a name says which are processed before , The C preprocessor modifies a source file before handing it over to the compiler

Or we can say pre written,

Include is simple including of pre written function definition

<stdio.h> is a label where the definition of function are Stored

Page 10: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Don’t be confused now we will understand where #include<stdio.h> will come into picture

In last slide I was talking about function definition

Basically there are 2 types of functions 1.Predefined 2.Userdefined

Function is defined as set(group) of syntax performing specific task

Page 11: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Basically function as two partsFunction prototype(head)Function body(defination)

add()…………………….function prototype(head){………….………………….}

Function body

Page 12: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

function prototype: Says what I am going to do

function definition: Says what task I am doing

When we consider our above program we have to functions

main()

printf()

Page 13: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

#include<stdio.h>

main()……………………..no semicolon {

printf("Hello World"); …….semicolon }

What difference you can notice between main and printf

When function has no semicolon it is followed by { and ended with }Which means head and body exist

Page 14: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Main : is the function where execution starts

After main exection goes to printf(); where no defination is found so compiler goes to library search for <stdio.h> label inside which it search for printf defination

When defination is found it copies the entire code from library to program and execute it

Page 15: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

add()…………………….function prototype(head){………….………………….}

Function can only executed if it has both head and body

Then in case of printf(); where is the body,if no body how can it run

Function body

Page 16: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Regular used functions definition are pre written and are stored in library which at the start of the program we are including

Since there are lot of predefined functions they categorized by labels<stdio.h><conio.h><math.h>

In these blocks respective function definitions are stored

Similarly the function defined by us are called as user defined function

Page 17: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

#include<stdio.h>

main() {

printf("Hello World");

}

C library

Stdio.h Conio.h

Math.h

definition

Page 18: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

The reason to start with c program was just to know the meaning Of the words what we use in program , when we know the meaning of the syntax,programs are easy to learn

now it’s a time to know how java came into existence and why it has become so important

Although we have c and c++ ,why java came into existance ?

Where c and c++ fail……..?

Page 19: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

C and C++ failed due to platform dependencies

Platform is base where we run program, platform is combination of operating System and Processor

Win 7os

keyboard

I3process

or

platform

Page 20: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

When we write C program in operating system and processor ,it can be re runned in only in same operating system and processor

For example if I write program in win7 nd p4 processor it can be runned again in the same,if I try to run in different os and processor like win7 and i5 ,it fails to run

Why c and c++ fail to run…?

Page 21: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

case 1

Win7P4

Add.c

case 2

Win7I3

Add.c

Add.obj Add.obj

Add.exe Add.exe

Compile

run

Compile

run

Why it is not running…………?

Page 22: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Lets know the reason

When we write c program we save with the extension .cAdd.c

This is source code

When we compile c program we get the extension .objAdd.obj

This is machine code(object code)

This machine code always depends upon processor and operating System

Page 23: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

case 1

Win7P4

Add.c

Add.obj

Add.exe

Compile

run

Let us consider Case 1Os:-win 7Process:p4

When we compiles Add.cFor adding of two numbers Machine codeformat we get

Add A,B

Page 24: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

case 2

Win7I3

Add.c

Add.obj

Add.exe

Compile

run

When we consider case 2Os:win7Process:i3

When we compiles Add.cFor adding of two numbers Machine codeformat we get

A ADD B

Page 25: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Now we try to take code of case 1 after compiling and pate to run in case 2Case 1 lang:ADD A,B

Case 2 lang:A ADD B

Case 2 cannot recognize case 1 language hence it cannot run

This made c and c++ failure

Since all systems cannot have same os and processor it is platform dependent

Page 26: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Being a software developer we want our application(program) to be used by all in such a case it should be recognized by all the system

This made the invention of java

Page 27: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

History of java

Gosling is founder of Java programming language in 1994 it was named as oak

In January 1995 it was renamed as java since was already registered

Its platform independent pure object oriented if we write once we can run anywhere

Page 28: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Import java.io.*public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); }}

Simple java Program

Page 29: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Before we enter in depth lets see how it was made platform Independent

Saving java program:Example.java

After compiling

Example.class

Class code is not machine code like c,it is called as Byte code

Page 30: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Byte code is a intermediate code which is nither source code nor machine code

Problem was machine code reason if we convert to Machine code only that machine can understand

This code is given to converter (jvm) which converts to machine language depending on machineHence depending on machines there are flavors of jvm

Page 31: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

31

Let us consider example

Person AKnows only

english

Person BKnows

english/french

Person cKnows only

French

Page 32: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Similar Thing happens in java

This is how java is platform independent

jvm

jvm

jvm

Page 33: Welcome to Java. 2  History of java  Advantages of java  Java first program  Rules to be followed  Data types  Operators  Casting  Control statements.

Advantages of javaJava first programRules to be

followed

This is it For First class We shall continue next class with below topics