Posts

Showing posts from May, 2023

Access Modifier

Object Oriented Programming

 Classes and Object Class : Blueprints or prototype to create objects(House blueprint) Objects : Actual instances of classes(Different house models) Class-dorgercar STATES (byte numberodSeats,numberofDoors,horsePower,color,isDamaged) Behaviors(startEnginer(),getcolor(),getHorsePower()) OBJECTS: redDorge,greenDorge,yellowDordge Class-BasketballPlayer STATES (String name,nickname,yearofBorn) Behaviors(getName(),getNickName()) Access Modifier Inheritance Encapsulations Abstraction PolyMorphism.

Packages

They are simple containers group the classes. Two types--> Userdefined(Written by developer) and build in (prewritten packages)packages. Package name must be unique,lowercase. EG: package.subpackage.anothersubpackage import com.imdb.database.*;-->can use all the classes from this package. Two classes with the same name . import java.util.Date; import java.sql.Date; Dont use import all ,import only necessary class.

Arrays

 Used to store multiple values with the same data type in a single variable Array is collection elements of same data type(Homogenios data). We can store multiple values into a single variable. 2 types of arrays --------- 1) Single dimensional 2) two dimensional/multidimensional Single dimensional ---------------------- 1) Declare an array 2) insert values into array 3) Find size of an array 4) read single value from an array 5) read multiple values from an array Examples: import java.util.Arrays ; public class ArrayPrac { public static void main (String[] args) { //declare --approach 1 int a[] = new int [ 5 ] ; //insert a[ 0 ]= 100 ; a[ 1 ]= 200 ; a[ 2 ]= 300 ; a[ 3 ]= 400 ; a[ 4 ]= 500 ; //approach 2 int []b= { 111 , 222 , 333 , 444 , 555 } ; System. out .println(b. length ) ; //get single value from array System. out .println(b[ 3 ]) ; System. out .println(Arrays. toStrin...

Method

 Methods:  Block of code which only runs  when  it is called.they are reusalble. create a Method; declare with in the class returnType functionName(){ return  returnDataType ; } ex:2 accessModifier static returnType fucntionName(parameter){ } public double getTenPercentOffDiscountPrice(int price){ return price*0.9; } accessModifier- public, private static- methos belongs to class Call method in java- functionName(parameter); informations can be passed to methods via parameters,paramente acts as vaibales inside methods,method will have unlimited amount of parameters , recommends only 3  Parameters verus Argumenets: Parameter passed to method is called argument.  price-parameter public double getTenPercentOffDiscountPrice(int price ){ return price*0.9; } getTenPercentOffDiscountPrice(20000); 20000 is argument. Method Overloading :multiply methods will have samename with diff parameters. returnType sameFunctionName( dataType1 parameterName1 ){ ---} return...

Control Flow

 Control flow: Decision making and it enables your program to conditionally execute different code blocks. IF  if (price>500){ sout("");}  IF ELSE- Example package ControFlows ; import java.util.Scanner ; public class IfElse { public static void main (String[] args) { Scanner sc = new Scanner(System. in ) ; System. out .println( "Enter the browser you want to exec the test <<CHROME,IE,FIREFOX,SAFERI" ) ; String browser=sc.next() ; browser= browser.toUpperCase() ; if (browser.equals( "CHROME" )){ System. out .println( "Opening browser " + browser + " Starting test executation" ) ; } else if (browser.equals( "IE" )) { System. out .println( "Opening browser " + browser + " Starting test executation" ) ; } else if (browser.equals( "FIREFOX" )) { System. out .println( "Opening browser " +...

Java Loops

 Loops: Loops are repeating code, until a specific condition is met. While Loop  DO-While Loop For Loop Continue and Break  While Loop : int i=0; While (condition ){ ---//repeated until condition is true Example int i =0; while(i<=4){ i++; } } DO-while Loop : Do - will excute first and checks its condition in while , if it is true , it is repeated ,once while becomes  false it will come out of do while loop . do  { .... }while(condition); example: int j=1; do { // j++ }while(j<=3); For Loop : for (intialization; condition; update statement){ ---} for (int i =0 ; i<=100; i++); continue- skipping steps and loops. break - is for stopping the loop .

Java-operators

Equality and Relational Operator  Operator                     Meaning                                    Example ==                                   equals                                        5==5 !=                                   not euals to                               5!=5 >=                                 ...