Академический Документы
Профессиональный Документы
Культура Документы
• Another way, it shows only important things to the user and hides the
internal details for example sending sms, you just type the text and
send the message. You don't know the internal processing about the
message delivery.
1) Abstract class can have abstract and non- Interface can have only abstract methods. Since Java
abstract methods. 8, it can have default and static methods also.
3) Abstract class can have final, non-final, static Interface has only static and final variables.
and non-static variables.
4) Abstract class can provide the implementation of Interface can't provide the implementation of
interface. abstract class.
5) The abstract keyword is used to declare abstract The interface keyword is used to declare interface.
class.
6) Example: Example:
public abstract class Shape{ public interface Drawable{
public abstract void draw(); void draw();
} }
t.setVehicle(new Car());
t.startTrip();
t.setVehicle(new Bike());
t.startTrip();
}
}
• By string literal
• By new keyword
• By equals() method
• By = = operator
• By compareTo() method
• You can get substring from the given string object by one of the two
methods:
• public String substring(int startIndex): This method returns new String
object containing the substring of the given string from specified startIndex
(inclusive).
• public String substring(int startIndex, int endIndex): This method returns
new String object containing the substring of the given string from
specified startIndex to endIndex.
• In case of string:
• startIndex: inclusive
• endIndex: exclusive
• Allow you to find the first and last position of a character or substring
within a string:
• indexOf(char ch) // first position of 'ch'
• indexOf(String str) // first position of 'str'
• lastIndexOf(char ch) // last position of 'ch'
• lastIndexOf(String str) // last position of 'str‘
• All the methods return -1 if the character or string is not found
• Simple tests for the beginning and ending of strings can be done by
using:
• public boolean startsWith(String prefix);
• public boolean endsWith(String suffix).
• these methods return true if a comparison is done with an empty
string:
myStr.endsWith(""); // true
myStr.startsWith(""); // true
• Java Collections can achieve all the operations that you perform on a
data such as searching, sorting, insertion, manipulation, and deletion.
2 public boolean addAll(Collection<? extends E> c) It is used to insert the specified collection elements
in the invoking collection.
3 public boolean remove(Object element) It is used to delete an element from the collection.
4 public boolean removeAll(Collection<?> c) It is used to delete all the elements of the specified
collection from the invoking collection.
1 public boolean hasNext() It returns true if the iterator has more elements
otherwise it returns false.
2 public Object next() It returns the element and moves the cursor pointer to
the next element.
3 public void remove() It removes the last elements returned by the iterator. It
is less used.
• Data Growth: ArrayList increments 50% of the current array size if the
number of elements exceeds its capacity, while vector increments
100% (thread-safe)
Java TreeSet class implements the Set interface that uses a tree for
storage. Like HashSet, TreeSet also contains unique elements.
However, the access and retrieval time of TreeSet is quite fast. The
elements in TreeSet stored in ascending order.