Java: Java Programming For Beginners a simple Start To Java Programming (Written By a software Engineer)


Download 0.82 Mb.
Pdf ko'rish
bet63/95
Sana09.01.2022
Hajmi0.82 Mb.
#261112
1   ...   59   60   61   62   63   64   65   66   ...   95
Bog'liq
Java Programming For Beginners - A Simple Start to Java Programming ( PDFDrive )

Listing Directories:
You can utilize list( ) method provided by the File class to provide a list of all the records
and directories accessible in an index.
Sample Implementation:
import java.io.File;
public class MyReadDir {
public static void main(String[] args) {
File myfile = null;
String[] paths;
try{
myfile = new File(“/tmp”);
mypaths = file.list();
for(String path:mypaths)
{
System.out.println(path);
}
}catch(Exception e){
e.printStackTrace();
}
}
}



Exception Handling
During  the  execution  of  your  program,  it  may  experience  abnormal  or  exceptional
conditions. As a result of these, the system may crash. An exception may occur due to a
number of reasons. Some of these include:
A file that needs to be opened can’t be found.
A client has entered invalid information.
A system association has been lost amidst correspondences or the JVM has used up
all the available memory.
Some of these special cases are created by client mistake, others by developer blunder, and
others  by  physical  assets  that  have  fizzled  into  your  code  in  some  way.  To  see  how
exception  handling  works  in  Java,  you  have  to  comprehend  the  three  classifications  of
exceptions:
Errors: These are not special cases whatsoever. Therefore, errors can be defined as
issues that are beyond the understanding and the ability to control of the client or
the software engineer. They are normally overlooked in your code on the grounds
that  you  can  once  in  a  while  take  care  of  a  mistake.  Case  in  point,  if  a  stack
overflow happens, it is sure to result in an error. They are additionally disregarded
at the time of compiling.
Runtime Exceptions: It is a special case that most likely could have been dodged
by  the  software  engineer.  Runtime  exceptions  are  disregarded  at  the  time  of
assemblage.
Checked  Exceptions:  It  is  a  special  case  that  is  regularly  a  client  mistake  or  an
issue  that  can’t  be  predicted  by  the  developer.  Case  in  point,  if  a  file  is  to  be
opened,  yet  the  file  can’t  be  found,  an  exception  of  this  type  happens.  These
special cases can’t just be disregarded at the time of compilation and dry runs.

Download 0.82 Mb.

Do'stlaringiz bilan baham:
1   ...   59   60   61   62   63   64   65   66   ...   95




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling