Data Structures is a way of storing/organising data in the memory, in such a way that access, management and modification become efficient.
Algorithms is any approach you use to perform operations on data (like searching, sorting, traversing, ..Etc.).
- PROGRAMMING LANGUAGE.
- CLASS AND OBJECTS.
- CONSTRUCTOR.
- this KEYWORD.
- ACCESS MODIFIERS IN JAVA.
- ENCAPSULATION.
- STATIC KEYWORD IN JAVA.
-
- You can call static methods from non static method but reverse is not true.
- INNER CLASS IN JAVA.
- Pass by value.
- Pass by refrence.
import java.util.*;
public class Hi {
// here value is copied in localVariable 'a'.
public static void incrementPrimitiveDT(int a) {
a++;
}
// here reference is copied, means 'input' is also pointing to 'arr'.
public static void incrementReferenceDT(int input[]) {
for(int i=0;i<input.length;i++) {
input[i]++;
}
}
public static void main(String[] args) {
int i=10;
incrementPrimitiveDT(i); // passByValue
System.out.println(i); // 10
int arr[]= {1,2,3,4,5};
incrementReferenceDT(arr); // passByReference
System.out.println(Arrays.toString(arr)); // [2, 3, 4, 5, 6]
}
}
public static void main(String[] args) {
// case 1:
Integer i= new Integer(1);
Integer j=new Integer(1);
System.out.println(i==j); // false, coz == check reference address of i and j, and here 'i' is pointing to 1 (i---> 1) and 'j' is pointing to different 1 (j---> 1)
System.out.println(i.equals(j)); // true
// case 2:
Integer a=new Integer(2);
Integer b=2;
System.out.println(a==b); // false
System.out.println(a.equals(b)); // true
// case 3:
Integer x=new Integer(3);
Integer y=x;
System.out.println(x==y); // true
System.out.println(x.equals(y)); // true
// case 4
Integer p=128;
Integer q=128;
System.out.println(p==q); // false
System.out.println(p.equals(q)); // true
// case 5 -128 to 127 is in cached memory so they point to same object without creating it instances.
Integer s=50;
Integer t=50;
System.out.println(s==t); // true
System.out.println(s.equals(t)); // true
}
-
% operator in JAVA : dividend % divisor - Here two statement is needed to be taken care :-
-
Store 2 numbers in a number.
- To Inject B in A we ADD(+) B*INF in A and store it in A, where INF is any number greater than A and B.
- to extract old number i.e., A from modified A we do (A % INF).
- to extract new number(Injected number) i.e., B from modified A we do (A / INF).
int a=5; int b=4;// number to be injected int INF=9999; a=a+(b*INF); System.out.println(a%INF); // 5 System.out.println(a/INF); //4
- Note : When there is no reference variable pointing to actual object then it is deleted automatically when garbage collection hits.
public class Demo{
public static void main(String[] args) {
Human obj=new Human();
Human son=obj; // this is his mom who call obj as hisSon.
Human bro=obj; // this is his sis who call obj as hisBro.
son.hairCut="done"; // here his mom made him do haircut.
// here his sister is also able to see his haircut.
System.out.println(bro.hairCut); // done
}
}
class Human{
String name="Vikash";
String hairCut="notDone";
}