Welcome to Java. 2 History of java Advantages of java Java first program Rules to be followed ...
-
Upload
roxanne-perry -
Category
Documents
-
view
227 -
download
0
Transcript of Welcome to Java. 2 History of java Advantages of java Java first program Rules to be followed ...
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
Contents continued
Interface and package
ThreadsException handlingGraphical
programmingAwtSwingsApplet
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 ?
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
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
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)
# 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
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
Basically function as two partsFunction prototype(head)Function body(defination)
add()…………………….function prototype(head){………….………………….}
Function body
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()
#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
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
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
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
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……..?
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
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…?
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…………?
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
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
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
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
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
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
Import java.io.*public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); }}
Simple java Program
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
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
31
Let us consider example
Person AKnows only
english
Person BKnows
english/french
Person cKnows only
French