Posts

Showing posts from March, 2022

Collections in Java

Image
Overview Array An Array is an indexed collection of fixed number of Homogenous data elements. The main advantage of arrays is we can represent multiple values by using single variable so that readability of the code will be improved.  Limitations of Arrays Arrays are fixed in size i.e. once we create an array there is no chance of increasing or decreasing the size based on our requirement. Due to this, to use arrays concept compulsory we should know the size in advance which may not be possible always. Array can hold only homogenous data type elements. Student[] students = new Student[ 1000 ] ; students[ 0 ] = new Student( "Vim Payne" , 18 , 20 , 540 ) ; /* Prompts a compile time error: Incompatible types found: Teacher required: Student */ students[ 1 ] = new Teacher( "Vim Payne" , 18 , "St. Theressa School" , "9A" ) ; We can solve the above problem by using Object type arrays. Object[] students = new Object[ 1000 ] ; students[ 0 ] = new

Flow Control in Java

Image
Overview Flow Control describes the order in which the statements will be executed at runtime. There are three types of Flow Control statements that controls the flow of execution. Selection Statements If-else Statements Switch Statements Iterative Statements while loop do-while loop for loop for-each loop Transfer Statements break continue return try-catch-finally assert Reference

OOPS Concept in Java

Image
Overview Most import aspects of OOPS Data Hiding.  Outside person can't access our internal data directly or our internal data should not go out directly, this OOP feature is nothing but Data Hiding. After validation or authentication outside person can access our internal data. By declaring data member (variable) as private we can achieve Data Hiding. e.g. public class Person { final private String name ; final private int age ; public Person (String name , int age) { this . name = name ; this . age = age ; } public String getName () { // Validation return name ; } public int getAge () { // Validation return age ; } } The main advantage of Data Hiding is security.  e.g.  After providing proper username and password, we can able to access our Gmail inbox information. Even though we are valid customer of the bank, we can able to access our account information but we can't access other's account