I have a test on Java and there are a few review topics listed below. Could you
ID: 3808697 • Letter: I
Question
I have a test on Java and there are a few review topics listed below. Could you please give me a brief explanation for each of these? Thanks!
How to throw a Java exception.
What the Java pointer null is.
How the Java equals methods work.
How the Java ‘==’ operator works.
When to use equals, and when to use ‘==’.
How the Java toString methods work.
How inheritance works with Java classes.
How the extends keyword works.
What a Java interface is.
How to use an interface to simulate multiple inheritance.
How to analyze the run time of an algorithm.
How O ‘‘big-O’’ notation works.
How an algorithm can run in constant time O(1).
How an algorithm can run in linear time O(n).
How an algorithm can run in logarithmic time O(log n).
How an algorithm can run in quadratic time O(n2).
How the functions used in O notation grow at different rates.
How to represent a set using an array.
How set methods work: add, isIn, length, remove, where. (See Moodle.)
How inner (nested) Java classes work.
How to implement a linear, singly-linked list using an inner class.
What a stack is.
How stack operations work: isEmpty, isFull, peek, pop, push.
How to implement a stack using an array.
How to implement a stack using a linear, singly-linked list.
What a queue is.
How queue operations work: dequeue, enqueue, isEmpty.
How to implement a queue using a linear, singly-linked list.
What a special case is.
Explanation / Answer
1).To throw an exception, you simply use the throw keyword with an object reference, as in:
throw new TooColdException();
The type of the reference must be Throwable or one of its subclasses...The thrown exceptions are caught using catch keyword
2). In Java, a special null value can be assigned to an object reference. NullPointerException is thrown when program attempts to use object reference that has the null value. NullPointer Exception is a runtime Exception.
3).one can test two strings for equality by using equals(). It compares the content of two objects ,it return TRUE if the objects are equivalent,and false otherwise. To compare that ignores case differences we use equalsIgnoreCase().
4). '==' is a relational operator which compares two operands,generally used to check whether the two operands are equal or not.
5)'==' is different from equals() compares object reference whereas '==' compares the operands.
6) toString() returns a string that contains a description of the object on which it is called,and it is automatically called when an object is output using println().It can be overridden to customize the string representation.
7).extends is a keword which is used to inherit the properties from a parent class to a subclass.Likewise many number of subclasses can inherit from the parent class.
class A{
}
class B extends A{
}
in the above example , class A is the parent classs and classB is the subclass which inherits all the properties of A and these can also be overridden in class B/ can use them in class B.
8).Inheritance; a mechanism wherein a new class is derived from an existing class. In Java, classes may inherit or acquire the properties and methods of other classes. A class derived from another class is called a subclass, whereas the class from which a subclass is derived is called a superclass.This is acheived using the keyword extends
9) Java Interface is similar to that of the java class.using interface u can specify a set of methods that can be implemented by one or more number classes.It does not actually define any implementation,these are similar to abstract class, along with a new additional feature that is a single interface can be implmented by one or more number of classes by using a keyword implements.
10); a class cannot write two extends keywords,which is necessary to implement multiple inheritance .This can be acheived using interfaces.
class A {
}
// the methods ,parameters which are to be included in the next class are written in the interface .
interface a1{
}
class B extends A implements a1{
}
now classs B extends A and implements a1 later performs similar to multiple inheritance.
11).The running time of an algorithm for a specific input depends on the number of operations executed. The greater the number of operations, the longer the running time of an algorithm.
the runtime of an algorithm is generally calculated using asymptotic notations.
12).Big OH notation is used to find the theoritical time of execution of an algorithm.
iff there exists c & n' are positive constants; f(n)<=c*g(n); for all n,n>=n' .
13)O(1) means that it takes a constant time, like 14 ms, or 3 minutes no matter the amount of data in the set.It means that it takes the same amount of time to look up a value in the collection whether you have a small number of items in collection.If we somehow make the upper bound of running time to be constant for an algorithm then it is said to have have O(1).
14)Java inner class/ nested class is a class (i.e). declared inside the class or interface. We use inner classes to logically group classes and interfaces in one place so that it can be more readable and maintainable. Additionally, it can access all the members of outer class including private data members and methods.
15).
public class SinglyLinkedListNode {
public int value;
public SinglyLinkedListNode next;
public SinglyLinkedListNode(int value) {
this.value = value;
next = null;
}
public class SinglyLinkedList {
private SinglyLinkedListNode head;
private SinglyLinkedListNode tail;
public SinglyLinkedList() {
head = null;
tail = null;
}
}
}
16).Stack is a data structure which is used to store the elements .It follows the FIRST IN LAST OUT principle ..these are controlled using two opns as push() and pop(),to insert the elements and delete the elements respectively.
17).isEmpty():
it is a boolean return type , which return true if the invoking string contains no characters and has alength of zero.
isFull():
it is also simliar to the above function which return true if the data structure is full otherewise as false.
peek():
return the element at the head of the queue . It returns null if the queue is empty, the element is not removed.
pop(),push():
used to remove the element from the stack,push is used to insert the elements into the stack.
18).code:
17).node.java:
linkedlist.java:
likedlinkedstack.java:
18).queue is a datastructure which is used to store elements in FIRST IN FIRST OUT principle. it has two things as front end and rear end..
19).Dequeue is an opn which is used to delete an element from the queue,whereas tthe enqueue is an opn which is used to insert the elements into the queue., isEmpty() which is used to check whether is given datastructure is empty or not.
20).code:
LinkList.java
LinkListQueue.java
LinkedListQueueDemo.java
21).special cases are also know as Exceptions that araise when executing a code.These are handled using exception handlers java as ( try ,throw,catch).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.