- to store n number of data we can use arrays. but there are some problem in array: 1-array is a fixed length 2-type is defined and fixed and we can not store different data types. 3-the operations like insertion and deletion are very difficult.
- java provides Collection interface. Collection is an interface in java.util package
- collection has 4 sub interfaces:
- 1-set: set has 2 classes hash set and linked hash set.
- 2-List{Array list, linked list, stack, vector}
- 3-Queue
- 4-map{hash table, hash map}
- set is an interface. we can add different type of objects to it.
1-set doesn't support duplicate Values.
2-the size of set is not fixed.
3-while storing, set does not store the data in same order in which we
have provided. hash set support null for example hs.add(null)
4-set has 2 differents implemented class one is hash set and another is
linked hash set.
hash set: is support all feature of the set. it stores the data in
array format.
LinkedHashset: it support the feature of set but it stores the data in same order how it was been provided. it stores data in the format of link list.
فریبا
سهشنبه 17 مردادماه سال 1391 ساعت 01:41 ق.ظ
- the Exception class is divided to 2 types: 1-checked 2-unchecked exception
- checked exceptions are the exception objects for which my compiler can rise them and handle them.
- unchecked: the compiler will not rise any complaint if we did not check. unchecked is subclass of the run time exception.
فریبا
سهشنبه 17 مردادماه سال 1391 ساعت 12:59 ق.ظ
- error has 2 types: compile time error and run time error or syntax error and logical error.
- in logical error once the control face the error statement it creates the object of corresponding exception class. once exception object created the object passes to calling place of the method. once the object reject at JVM, JVM terminates the program by giving a exception message without for the execution.
- without executing last statement if the program terminates that is known as abnormal termination.
- to avoid abnormal termination we have to handle the exception.
- All Exception class are the subclass of Throwable class. an exception can be of 2 types 1-simple exception 2 -serious exception
- simple exceptions are subclass of Exception class.
- serious exceptions are subclass of Error Class.
- java advises not to handle serious exceptions. we can handle those which are from Exception class.
- identify the exception object, catching it and handling it are known as Exception handling.
- try and catch: java supports these 2 keywords to handle the exceptions.
- the job of try keyword is to identify the exception object and pass the object to the catch. catch block will catch the exception object and handles it.
- at time only one block will be execute: try or catch.
- we can write n number of catch block to a single try but by revers is not possible.
- throw keyword is used to throw an exception object, explicitly.
- try... finaly: finally to force for doing some instruction. finally is not a method
- the job of throws keyword is to transport Exception object from the method to the calling place.
- in the calling place the end user has to handle the exception class object using the try and catch block.
- the suggestion not to use throws keyword on main method because the calling
place of main is JVM and once JVM will find the Exception object it will
terminate the program. - when we put throws for a method, when we want to call it, we should
call it in try and catch block. - Example: void meth(int x, int y) throws ArithmeticException
فریبا
سهشنبه 17 مردادماه سال 1391 ساعت 12:19 ق.ظ
- Access specified specified the accessibility of the members.
- access specified can be used before a method, constructor, variable, constant, class and other structures.
- java can support 4 types of access specifides: 1-public 2-private 3-protected 4-default
- the public describes the accessibility as global. that means any one can use public members.
- private accessibility is only within the class. the same class members can be access private members.
- default: if we will not mention any access specified, as public, private or protected then java compiler identify the access specified as a default. there is no keyword for default accessified. the default member is available/accessible only within the package and outside the package it is private. it means inside package it is public else it is private.
- protected is same as Default. but can be accessible through sub class out side of the package.
- we can create private, for the inner class not for the class.
فریبا
دوشنبه 16 مردادماه سال 1391 ساعت 11:45 ب.ظ
- package is same as a folder that contains the related .class file.
- to create a package the keyword "package" is used.
- the classes in the package should be declared as a public.
- if you want to use this classes in another class outside the package then
you have to import to that class using import keyword. - using import keyword you can import a single or particular class or all
the classes using * operator. - the * operator imports only classes present in that package. not the sub packages.
- to compile a class that contains a package we use "javac -d . programname.java"
- "-d" describe to create the directory. "." describes the part of directories same where the file is stored.
- the package statement should be the first statement in the program and only
one package statement can be written inside a program whereas n number of
import statement we can write. - if class is not public we can not use it outside the package.
فریبا
دوشنبه 16 مردادماه سال 1391 ساعت 09:59 ب.ظ