Posts

Showing posts from December, 2017

Java Technology - 2018 - String

Image
 String is basically an object that represents sequence of char values. An array of characters works same as java string. char[] ch = {'m','a','n'}; String str = new String(ch); The java.lang.String class implements  Serializable ,  Comparable  and  CharSequence  interfaces. The CharSequence interface is used to represent sequence of characters The java String is immutable i.e. it cannot be changed. Whenever we change any string, a new instance is created. For mutable string, you can use StringBuffer and StringBuilder classes. Generally, string is a sequence of characters. But in java, string is an object that represents a sequence of characters. The java.lang.String class is used to create string object. How to create String object? There are two ways to create String object: By string literal By new keyword String str = "everest"; ava String literal is created by using double quotes. For Example: String s=...

Java Technology 2018 - Array

Array:  Array is a collection of similar type of elements that have contiguous memory location.  Array in java is index based, first element of the array is stored at 0 index. Advantage of Java Array Code Optimization:  It makes the code optimized, we can retrieve or sort the data easily. Random access:  We can get any data located at any index position. There are two types of array. Single Dimensional Array Multidimensional Array Syntax to Declare an Array in java dataType[] arr; (or)   dataType []arr; (or)   dataType arr[];   Instantiation of an Array in java arrayRefVar=new datatype[size];   class Testarray{   public static void main(String args[]){      int a[]=new int[5];//declaration and instantiation   a[0]=10;//initialization   a[1]=20;   a[2]=70;   a[3]=40;   a[4]=50;    ...

Java Basics Practice

Image
Variable that are declared inside method - local Variable that are declared inside class and outside method - instance Variable that are declared as static - static, Static can't be local ------------------------------------------------- data type types: primitive: int, long, float, short, double, boolean, char, byte                           non-primitive: Array, String ------------------------------------------------- Object: It is an entity that has state, behavior and identity. eg: chair- solid, tall, brown - state. Behavior - for sitting. Identity - table from my home which is unique.  It can be physical or logical. Class: Collection of object, only logical When object acquires properties of parent object - inheritance. Eg. dog can acquire properties of Animal. Dog itself can bark and can eat like other animals. To perform one task in different ways - polymorphism. Eg. Draw() - it can be drawCircle() or...