Monday, June 5, 2017

Object Oriented Principles

1)Inheritance will only work when the child class's constructor is accessible(public)
When Inheritance is applied all the methods in Parent class's are copied into child class

Class A
{
Members
}

Class B:A
{
Consuming members of A
}

A is the Super class or Parent Class

2)When Parent and Child both have constructors

Parent Class constructor is called first

3)Parent Class can not access Child class members

4)We can initialize Parent Class variable by using a child class instance
Class A
{
A a;
B b=new B();
a=b; //b is an instance variable and a is class variable
}

Monday, May 22, 2017

String Methods

1)charAt 2)str.toCharArray() 3) s.indexOf(c) 4)s.lastIndexOf(c)

Sunday, May 21, 2017

Ascii

Ascii has 255 Characters

1) Any Ascii character has its integer value from 0-255

Java Arrays

Type[] name = new Type[Size];
Example : boolean[] charSet = new boolean[256];
Note : 
1)Default value of Boolean array element is False
2) Default value of Int array element is 0

Thursday, May 11, 2017

Java Random numbers

Use
Import java.util.Random;


1)To fetch a random number from 0 to that number
Random().nextInt(int bound) generates a random integer from 0 (inclusive) to bound (exclusive).

2)To fetch a random number in a Range
private static int getRandomNumberInRange(int min, int max) {
 Random r = new Random();
 return r.nextInt((max - min) + 1) + min;
}
3)To fetch Random objects from an array
String []guess={"Red","Blue","Green"};
char[] randomguess=guess[random.nextInt(guess.length)].toCharArray();


Source : https://www.mkyong.com/java/java-generate-random-integers-in-a-range/


Monday, February 13, 2017

Java interesting Rules

1)  Java file can only have one Public with same Name of the file.
Can have any number of classes with different names...

2) A file can have any number of classes and any number of mains in each class

3)