Upload
saurabh-prajapati
View
387
Download
5
Tags:
Embed Size (px)
DESCRIPTION
this ppt contains history and basic facts of object oriented programming language java, difference between JIT, JVM, JRE and JDK. it also having information about different versions of java. advantages over other language, difference between error and exception with its types is also included. explanation of final variable and string to int conversation is also added. in the end some twisted question of it which sharpen the knowledge of its basic are added. beyond this some programming examples with output is there too. hope u find it useful...!! thanku..!!
Citation preview
JAVABASIC TERMS TO BE KNOWN…..
Facts and history
Who invented java?James Gosling
Where?Sun lab also known as sun micro
system.When?
Around 1992, published in 1995.What is first name at a time of invention?
“oak”, from the name of tree outside the window of James.
Why the name “java” and the symbol a “coffee cup”?Some issues with the name “oak”.Seating in the local café.Wounded up with the name “java”.From the cup of coffee.
What is the relation with c/c++?Java was created as a successor to C++ in order
to address various problems of that language
Facts and history
Features of javaCompiled and interpreted
Source code byte code and byte code machine code Platform independent and portable
Can be run on any platformSecure
Ensures that no virus is communicated with applet Distributed
Multiple programmers at different remote locations can collaborate and work togetherHigh performance
Faster execution speedMulti language supported
Dynamic and extensible New class library, classes and methods can be linked dynamically
JIT, Jvm, jre and jdk JIT
Just-In-Time Component of JRE Improves the performance
JVM Provides runtime environment in which java byte
code is executed. Compilation + interpretation Not physically present
JRE Runtime environment Implementation of JVM Contains a libraries + other files
JDK JRE + development tools Bundle of softwares
Different versions
JDK 1.0 (January 21, 1996) JDK 1.1 (February 19, 1997) J2SE 1.2 (December 8, 1998) J2SE 1.3 (May 8, 2000) J2SE 1.4 (February 6, 2002) J2SE 5.0 (September 30, 2004) Java SE 6 (December 11, 2006) Java SE 7 (July 28, 2011) Java SE 8 (March 18, 2014)
Advantages over c/c++
Improved software maintainability Faster development Lower cost of development Higher quality software Use of notepad makes it easier Supports method overloading and overriding Errors can be handled with the use of Exception Automatic garbage collection
STARTING THE BASICS…
Code:
class abc{
public static void main(String args[]){
System.out.print("hello, how are you all??");}
}
File name: Abc.java
Meaning of each term
Public: visibility modeStatic: to use without creating objectVoid: return typeString: pre-defined classArgs: array nameSystem: pre-defined classOut: object Print: method
Make sure:No need of saving file with initial capital
letterFile name can be saved with the different
name of class name
String to integer and doubleclass conv{
public static void main(String a[]){
int a;String b="1921";double c;a=Integer.parseInt(b);System.out.println(a);c=Double.parseDouble(b);System.out.println(c);
}}
Final variableValue that will be constant through out the program.Can not assign another value.
Study following program.
class fin{
public static void main(String a[]){
final int a=9974;System.out.print(a);a=759;System.out.print(a);
}}
Errors and exception
What is the difference???Errors
Something that make a program go wrong.Can give unexpected result.Types:
Compile-time errorsRun-time errors
ExceptionCondition that is caused by a run-rime error in the program.Ex. Dividing by zero. Interpreter creates an exception object and throws it.
errors
Compile-time Error Occurs at the time of compilation. Syntax errors Detected and displayed by the interpreter. .class file will not be created For successful compilation it need to be fixed. For ex. Missing semicolon or missing brackets.
More examples
Misspelling of identifier or keywordMissing double quotes in stringUse of undeclared variableUse of = in place of == operatorPath not foundChanging the value of variable which is declared final
errors
Run-time ErrorProgram compile successfullyClass file also generated.Though may not run successfullyOr may produce wrong o/p due to wrong logicError message generated Program abortedFor ex. Divide by zero.
More examples
Accessing an element that is out of bound of an array.Trying to store a value into an array of an incompatible class or type.Passing a parameter that is not in a valid range.Attempting to use a negative size for an array.Converting invalid string to a numberAccessing a character that is out of bound of a string.
class Err{
public static void main(String bdnfs[]){
int a=50,b=10,c=10;int result=a/(b-c);System.out.print(result);int res=a/(b+c);System.out.print(res);
}}
WHICH ONE IS THIS??
exception
Caused by run-time error in the program. If it is not caught and handled properly, the interpreter will display an error message.
Ex. ArithmeticException ArrayIndexOutOfBoundException FileNotFoundException OutOfMemoryExcepion SecurityException StackOverFlowException
Exception HANDLING
In previous program , if we want to continue the execution with the remaining code, then we should try to catch the exception object thrown by error condition and then display an appropriate message for taking correct actions.
This task Is known as Exception Handling. The purpose of this is to provide a means to detect and report circumstances.So appropriate action can be taken It contains 4 sub tasks.
Find the problem(Hit) Inform that error has occurred(Throw)Receive the error Information(Catch)Take corrective action(Handle)
Syntax ………………………….………………………….Try{
statements; // generates an Exception}Catch (Exception-type e){
statements; // processes the Exception}………………………....…………………………
exampleclass Err2{
public static void main(String bdnfs[]){
int a=50,b=10,c=10;int result,res;try{
result=a/(b-c);}catch (ArithmeticException e){
System.out.println("can not divided by zero ");
}res=a/(b+c);System.out.print(res);
}}
Multiple catch statements………………………….………………………….Try{
statements; // generates an Exception}Catch (Exception-type-1 e){
statements; // processes the Exception type 1}Catch (Exception-type-2 e){
statements; // processes the Exception type 2}..
.
.Catch (Exception-type-N e){
statements; // processes the Exception type N}………………………....…………………………
Finally statement
Finally statement is supported by Java to handle a type of exception that is not handled by catch statement.
It may be immediately added after try block or after the last catch block.
Guaranteed to execute whether the exception Is thrown or not.Can be used for performing certain house-keeping operation such a
closing files and realizing system resources.Syntax for using finally statement is shown in next slide.
Syntax Try{
…………..…………..
}Catch (……….){
…………..…………..
}Finally{
…………..…………..
}
Decide according to program that whether to use catch block or not…
class Err3{
public static void main(String bdnfs[]){
int a[]={50,100};int x=5;try{
int p=a[2]/(x-a[0]);}finally{
int q=a[1]/a[0];System.out.println(q);
}}
}
example
Some puzzles..String mesg = “Answer is “; int sum = 1 + 2; System.out.println(mesg + sum);
Output: “Answer is 3”int sum = 5; sum = sum + sum *5/2; System.out.println(sum);
Output: 17int limit = 25; int count = 30; int total = 200; count *=5; limit -=5; total +=count + limit; System.out.println("total =" + total);
Output: 370String str1 = "Java"; String str2 = "Java program"; String str3 = "program"; char c = ' '; String s1 = str1 + str3; String s2 = str1 + "c"; String s3 = str1 + c; String s4 = “ “; s4 += str1; String s5 = s4 + str3;
Output: “Javac”
http://darwinsys.com/java/javaTopTen.htmlhttp://www.funtrivia.com/en/subtopics/javao-programming-204270.htmlhttp://cs-fundamentals.com/java-programming/difference-between-jdk-jre-jvm-
jit.phphttp://www.javabeat.net/what-is-the-difference-between-jrejvm-and-jdk/http://www.fixoncloud.com/Home/LoginValidate/
OneProblemComplete_Detailed.php?problemid=535
References
Prepred by:Saurabh Prajapati(11ce21)