0 ratings0% found this document useful (0 votes) 6 views8 pagesJava Difference
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Definition
Exception Types
Handling
Requirement
Exception
Handling
Examples
Checked Exceptions
‘Checked at compile-time
1OException, ClassNotFoundException, ete.
Must be caught or declared using throws
keyword
Handled using try-catch blocks or throws
keyword
Program flow is interrupted and transferred to
catch block
File operations, database operations, etc
Unchecked Exceptions
Not checked at compile-time
NullPointerException,
ArrayindexOutOfBoundsException, etc
Optional to catch or declare using throws
keyword
Not required to handle explicitly
Program execution is halted with an error
message
Logical errors, invalid arguments, etc.Bu 9:39 Rae
“a £ here is a nice table which shows the
main differences between Thread class and
Runnable interface in Java:
These were some of the notable
differences between Thread and
Runnable in Java if you know any
other differences on Thread vs
Runnable than please share them via
comments. | personally use Runnable over
Thread for this scenario and recommend using
the Runnable or Callable interface based on your
requirement.
()
uPU We
1. Arrays are stored in contiguous
location.
2. Fixed in size.
3. Memory is allocated at compile time.
4. Uses less memory than linked lists.
5. Elements can be accessed easily.
6. Insertion and deletion operation takes
time.
LINKED LIS
1, Linked lists are not stored in
contiguous location.
2. Dynamic in size.
3. Memory is allocated at run time.
4. Uses more memory because it stores
both data and the address of next node.
5. Element accessing requires the
traversal of whole linked list.
6. Insertion and deletion operation is
faster.Text I/O vs. Binary I/O
> Text /O
« Text I/O is built upon binary I/O to provide a level
of abstraction for character encoding and
decoding.
« Encoding and decoding are automatically
performed for text I/O.
« The JVM converts a Unicode to a file-specific
encoding when writing a character and converts a
file-specific encoding to a Unicode when reading a
character.
Uz ~~Text I/O vs. Binary I/O (cont.)
» Binary I/O
« Binary I/O doest not require conversions.
« If you write a numeric value to a file using binary I/O, the
exact value in the memory is copied into the file.
« When you read a byte using binary I/O, one byte value
is read from the input.
+ In general, use text input to read a file created by a text
editor or a text output program, and use binary input to
read a file created by a Java binary output program.
Tm,oops interface vs abstract class
Interface
Abstract class
Interface support multiple inheritance
‘Abstract class does not support multigle
inheritance
Interface doas’n Contains Data Member
Abstract class contains Data Member
Interface does'n contains Cunstructors
Abstract class contains Cunstructors
‘An interface Contains only incomplete member
{signature of member)
An abstract class Contains both incomplete
(abstract) and complete member
An interface cannot have access modifiers by
default everything is assumed as public
An abstract class can contain access madifiers
for the subs, functions, properties
Member of interface can not be Static
Only Complete Member of abstract class can be
StaticImmutable - b
Immutability mmmnitable = CORFERE CANOE DE Mutable - content can be changed.
changed once created.
Synchronization Not synchronized - not thread-safe. Synchronized - thread-safe.
Performance Faster when creating a new object. Slower due to synchronization.
. . __ Coneatenation can be done within the
Concatenation Concatenation creates a new object.
same object.
Storage Area Scored in the string constant pool. Scored in the heap memory.
Offers fewer methods for string Offers additional methods like
Methods
manipulation, append(), reverse(), insert(), etc.
Preferred when string value won't Preferred when string value will be
Usage
change. modified often.
© Java Guides: heeps://[Link]/Pica
Ordering
Duplicates
eng
Maintains the order of insertion.
Allows duplicate elements.
RY
Does not guarantee order of elements,
Does not allow duplicate elements.
Null Elements
May allow null elements (depends on
the implementation).
May allow null elements (depends on
the implementation).
Main ArrayList, LinkedList, etc. HashSer, LinkedHashSet, TreeSer, etc.
Implementations
P r 7
Access by Index Provides methods to access elements by No index-based access.
an index.
Performance eherilly fsterat accessing elements Generally faster at searching, adding,
by index. and deleting elements.
‘When order and duplicate values are When a collection of unique elements
Use Case
needed.
is needed.
© Java Guides: heeps://www [Link]/