نکاتی در مورد پلی مورفیسم و Overloading در جاوا

  • Writing more than one method with the same name but their job is different is as known as polymorphism.
  • polymorphism has 2 type: 1-static polymorphism 2-dynamic polymorphism
  • static polymorphism: it is known as a compile time polymorph. by using the methods we know which method are going to be executed before compilation is known as static poly morph.
  • static polymorphism can be achieved using method overloading or constructor overloading.
  • method overloading: writing more than one method with same name but different signature in the one class in known as  method overloading
  • Constructor overloading: writing more than one constructor with different signature is known as constructor overloading

تفاوت == و Equals در جاوا

what is different between "==" and equals methods?

  • The "==" operator compares the address of both of the objects if both are same it will  return true else false.
  • equals method compare the content. if contents are same it will  be return true else false.


توضیح در مورد ایجاد String با یا بدون استفاده از new در جاوا

Q1: What is difference between create String with the new keyword or without a new keyword?

  1. String s1 = new String("NIIT");
  2. String s2 = "NIIT";
the first statement will create the object of string type without searching anywhere.
the second statement will search String Constant Pool, the same content if found, it will reference the existing object without creating a new one, else will be created new object.

Q2: What is string constant pool? It is a special memory location where the strings had been created.

چند روش برای ایجاد String در جاوا

we can create String in 4 ways in Java:
  1. as character array  char n[] = {'n','i','i','t'};
  2. by create an object with string class  String s1 = new String('niit');
  3. String s2 = "niit"; without a new keyword
  4. by Stringbuffer class object. StringBuffer b1 = new StringBuffer("niit")

StringBuffer is another String type mutable class. mutable means modified. we can modify it after the creation

چند نکته در مورد آرایه و String در جاوا

  • All members of one array has the same data type.
  • Array is fix length variable.
  • Array are known as fixed  length variables that stores homogeneous (similar type) type of data.
  • In java we can create an array as "type   name of array [] = new type[size]" Example: int x[] = new int[10]; Test t[] = new Test[3];
  • There is an inbuild keyword "Length" that return the size of an array: myArray.length
  • String is known as collection of arrays but in java it is a class
  • String is known as immutable class. immutable means once the object be
    created no one can modify the object.  String n1 = "NIIT"; we can not change n1