SlideShare ist ein Scribd-Unternehmen logo
1 von 28
JAVA 
BASIC 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.
Facts and history 
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
Features of java 
Compiled and interpreted 
 Source code  byte code and byte code  machine code 
 Platform independent and portable 
 Can be run on any platform 
 Secure 
 Ensures that no virus is communicated with applet 
 Distributed 
 Multiple programmers at different remote locations can collaborate and work together 
 High performance 
 Faster execution speed 
 Multi 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… 
File name: Abc.java 
Code: 
class abc 
{ 
public static void main(String args[]) 
{ 
System.out.print("hello, how are you all??"); 
} 
}
Meaning of each term 
Public: visibility mode 
Static: to use without creating object 
Void: return type 
String: pre-defined class 
Args: array name 
System: pre-defined class 
Out: object 
Print: method 
Make sure: 
 No need of saving file with initial capital 
letter 
 File name can be saved with the different 
name of class name
String to integer and double 
class 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 variable 
Value 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 errors 
 Run-time errors 
Exception 
 Condition 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 keyword 
 Missing double quotes in string 
 Use of undeclared variable 
 Use of = in place of == operator 
 Path not found 
Changing the value of variable which is declared final
errors 
Run-time Error 
 Program compile successfully 
 Class file also generated. 
 Though may not run successfully 
 Or may produce wrong o/p due to wrong logic 
 Error message generated 
 Program aborted 
 For 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 number 
 Accessing 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 
} 
……………………….... 
…………………………
example 
class 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: 17 
int limit = 25; int count = 30; int total = 200; count *=5; limit -=5; total +=count 
+ limit; System.out.println("total =" + total); 
 Output: 370 
String 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”
References 
 http://darwinsys.com/java/javaTopTen.html 
 http://www.funtrivia.com/en/subtopics/javao-programming-204270.html 
 http://cs-fundamentals.com/java-programming/difference-between-jdk-jre-jvm-jit. 
php 
 http://www.javabeat.net/what-is-the-difference-between-jrejvm-and-jdk/ 
 http://www.fixoncloud.com/Home/LoginValidate/OneProblemComplete_Detailed.p 
hp?problemid=535
Prepred by: 
Saurabh Prajapati(11ce21)

Weitere ähnliche Inhalte

Was ist angesagt?

Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 

Was ist angesagt? (20)

Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 
JNDI
JNDIJNDI
JNDI
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Component and Deployment Diagram - Brief Overview
Component and Deployment Diagram - Brief OverviewComponent and Deployment Diagram - Brief Overview
Component and Deployment Diagram - Brief Overview
 
JVM
JVMJVM
JVM
 
Java exception
Java exception Java exception
Java exception
 
Assemblies
AssembliesAssemblies
Assemblies
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Jsp element
Jsp elementJsp element
Jsp element
 
Exception handling
Exception handlingException handling
Exception handling
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
java Features
java Featuresjava Features
java Features
 
core java
core javacore java
core java
 

Andere mochten auch

Andere mochten auch (20)

History of java
History of javaHistory of java
History of java
 
History of Java 1/2
History of Java 1/2History of Java 1/2
History of Java 1/2
 
Evolution Of Java
Evolution Of JavaEvolution Of Java
Evolution Of Java
 
Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOC
 
Ip sec
Ip secIp sec
Ip sec
 
remote sensor
remote sensorremote sensor
remote sensor
 
Data mining
Data miningData mining
Data mining
 
12. dfs
12. dfs12. dfs
12. dfs
 
6. The grid-COMPUTING OGSA and WSRF
6. The grid-COMPUTING OGSA and WSRF6. The grid-COMPUTING OGSA and WSRF
6. The grid-COMPUTING OGSA and WSRF
 
Distributed file system
Distributed file systemDistributed file system
Distributed file system
 
Distributed Operating System_2
Distributed Operating System_2Distributed Operating System_2
Distributed Operating System_2
 
Ccleaner presentation
Ccleaner presentationCcleaner presentation
Ccleaner presentation
 
Lecture28 tsp
Lecture28 tspLecture28 tsp
Lecture28 tsp
 
Multiple Access in wireless communication
Multiple Access in wireless communicationMultiple Access in wireless communication
Multiple Access in wireless communication
 
optimization of DFA
optimization of DFAoptimization of DFA
optimization of DFA
 
Distributed shred memory architecture
Distributed shred memory architectureDistributed shred memory architecture
Distributed shred memory architecture
 
Distributed computing
Distributed computingDistributed computing
Distributed computing
 
IDS n IPS
IDS n IPSIDS n IPS
IDS n IPS
 
Soft computing
Soft computingSoft computing
Soft computing
 
Light emitting Diode
Light emitting DiodeLight emitting Diode
Light emitting Diode
 

Ähnlich wie Java history, versions, types of errors and exception, quiz

Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
Rich Helton
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
Satya Johnny
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
ssuser656672
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
sotlsoc
 

Ähnlich wie Java history, versions, types of errors and exception, quiz (20)

Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
CLR Exception Handing And Memory Management
CLR Exception Handing And Memory ManagementCLR Exception Handing And Memory Management
CLR Exception Handing And Memory Management
 
Introduction
IntroductionIntroduction
Introduction
 
Javascript
JavascriptJavascript
Javascript
 
Java cheat sheet
Java cheat sheet Java cheat sheet
Java cheat sheet
 
Java: Exception
Java: ExceptionJava: Exception
Java: Exception
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
java intro.pptx.pdf
java intro.pptx.pdfjava intro.pptx.pdf
java intro.pptx.pdf
 
Java -Exception handlingunit-iv
Java -Exception handlingunit-ivJava -Exception handlingunit-iv
Java -Exception handlingunit-iv
 
java basic for begginers
java basic for begginersjava basic for begginers
java basic for begginers
 
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
Adv kvr -satya
Adv  kvr -satyaAdv  kvr -satya
Adv kvr -satya
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
 
Java
JavaJava
Java
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
Java platform
Java platformJava platform
Java platform
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Kürzlich hochgeladen (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

Java history, versions, types of errors and exception, quiz

  • 1. JAVA BASIC TERMS TO BE KNOWN…..
  • 2. 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.
  • 3. Facts and history 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
  • 4. Features of java Compiled and interpreted  Source code  byte code and byte code  machine code  Platform independent and portable  Can be run on any platform  Secure  Ensures that no virus is communicated with applet  Distributed  Multiple programmers at different remote locations can collaborate and work together  High performance  Faster execution speed  Multi language supported Dynamic and extensible New class library, classes and methods can be linked dynamically
  • 5. 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
  • 6. 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)
  • 7. 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
  • 8. STARTING THE BASICS… File name: Abc.java Code: class abc { public static void main(String args[]) { System.out.print("hello, how are you all??"); } }
  • 9. Meaning of each term Public: visibility mode Static: to use without creating object Void: return type String: pre-defined class Args: array name System: pre-defined class Out: object Print: method Make sure:  No need of saving file with initial capital letter  File name can be saved with the different name of class name
  • 10. String to integer and double class 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); } }
  • 11. Final variable Value 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); } }
  • 12. Errors and exception What is the difference??? Errors Something that make a program go wrong.  Can give unexpected result. Types: Compile-time errors  Run-time errors Exception  Condition that is caused by a run-rime error in the program.  Ex. Dividing by zero.  Interpreter creates an exception object and throws it.
  • 13. 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.
  • 14. More examples  Misspelling of identifier or keyword  Missing double quotes in string  Use of undeclared variable  Use of = in place of == operator  Path not found Changing the value of variable which is declared final
  • 15. errors Run-time Error  Program compile successfully  Class file also generated.  Though may not run successfully  Or may produce wrong o/p due to wrong logic  Error message generated  Program aborted  For ex. Divide by zero.
  • 16. 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 number  Accessing a character that is out of bound of a string.
  • 17. 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??
  • 18. 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
  • 19. 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)
  • 20. Syntax …………………………. …………………………. Try { statements; // generates an Exception } Catch (Exception-type e) { statements; // processes the Exception } ……………………….... …………………………
  • 21. example class 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); } }
  • 22. 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 } ……………………….... …………………………
  • 23. 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.
  • 24. Syntax Try { ………….. ………….. } Catch (……….) { ………….. ………….. } Finally { ………….. ………….. } Decide according to program that whether to use catch block or not…
  • 25. 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
  • 26. 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: 17 int limit = 25; int count = 30; int total = 200; count *=5; limit -=5; total +=count + limit; System.out.println("total =" + total);  Output: 370 String 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”
  • 27. References  http://darwinsys.com/java/javaTopTen.html  http://www.funtrivia.com/en/subtopics/javao-programming-204270.html  http://cs-fundamentals.com/java-programming/difference-between-jdk-jre-jvm-jit. php  http://www.javabeat.net/what-is-the-difference-between-jrejvm-and-jdk/  http://www.fixoncloud.com/Home/LoginValidate/OneProblemComplete_Detailed.p hp?problemid=535
  • 28. Prepred by: Saurabh Prajapati(11ce21)

Hinweis der Redaktion

  1. Ask that will the program give me output?? Then explain that its not necessary of saving the programs with same name as class.
  2. Another visibility modes, return type, array name can b anything, another objects, methods