JAVA WORKSHOP(DAY 3) 1234567889999999.pptx

aniketraj4440 26 views 28 slides Sep 10, 2024
Slide 1
Slide 1 of 28
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28

About This Presentation

PPT OF JAVA WORK SHOP HGWEFCKHFSDACKHFDSAYUKCFD,JH CVSADYJCFWDACHVDJH,DFTYDFKHGCGHGHCGHFYTGFTYKGHTYRHV BHFYFKFIYFHJHDTYIFCKGHFYUVHDYFSYUVSHJFOYUVCDSHJFWEYUDSHJDSVFOYUWEFDSJHCVSDYLUFWEYUFVDSALJHFWEYOUFGASLJHFyouFHLJSAFGYUWFGYUFCVWYUOFWEYUVA


Slide Content

Noida Institute of Engineering and Technology, Greater Noida JAVA TRAINING Mr. Sumit Kumar Subject code- BMCA0253 OOT using JAVA DATE - 10/04/2024 TIME – 9:00 TO 05:00

Java Array Java array is an object the contains elements of similar data type. It is a data structure where we store similar elements . Array holds a fixed number of elements. Length of an array is specified when an array is created. Once length of an array is specified it remains fixed. Array in Java is index based and the index starts from 0. So the first element is stored in the array at index 0 . Elements in Java array are always numbered from 0 to (n – 1) where n is the individual elements in the array . They are dynamic, created on the heap memory . Array objects implement Cloneable and Serializable interfaces . To declare an array, define the variable type with  square brackets :[] 2

3

An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. As we know Array is a data structure where we store similar elements and Array a starts from index 0. Each item in an array is called an element, and each element is accessed by its numerical index. Since arrays are objects in Java, we can find their length using member length. A Java array variable can also be declared like other variables with [] after the data type. The variables in the array are ordered and each has an index beginning from 0. Java array can be also be used as a static field, a local variable or a method parameter. The size of an array must be specified by an  int  value and not long or short 4

5

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. Disadvantage of Java Array S ize Limit:  We can store the only fixed size of elements in the array. It doesn't grow its size at runtime. To solve this problem,  collection framework  is used in java. 6

7

8

Types of Array in java Single Dimensional Array Multidimensional Array 9

10

Declaring a Variable to Refer to an Array // this form is discouraged float anArrayOfFloats []; int [] anArray ; An array's type is written as type[], where type is the data type of the contained elements; the brackets are special symbols indicating that this variable holds an array. The size of the array is not part of its type (which is why the brackets are empty). Creating an Array Int [] anArray = new int [ 10 ]; String[] anArrayOfStrings = new String[10]; Object [] anArrayOfObjects = new Object[10]; 11

12

Multidimensional array in java In such case , data is stored in row and column based index (also known as matrix form). Syntax to Declare Multidimensional Array in java dataType [][] arrayRefVar ; (or) dataType arrayRefVar [][]; (or) dataType [] arrayRefVar []; 13

Example to instantiate Multidimensional Array in java int [][] arr =new int [3][3]; //3 row and 3 column Example to initialize Multidimensional Array in java arr[0][0]=1; arr[0][1]=2; arr[0][2]=3; arr[1][0]=4; arr[1][1]=5; arr[1][2]=6; arr[2][0]=7; arr[2][1]=8; arr[2][2]=9; 14

Example of Multidimensional java array class Testarray3{ public static void main(String args []){ //declaring and initializing 2D array int arr [][]={{1,2,3},{2,4,5},{4,4,5}}; //printing 2D array for( int i=0;i<3;i++){ for( int j=0;j<3;j++){ System.out.print ( arr [i][j]+" "); } System.out.println (); } } } Output :- 1 2 3 2 4 5 4 4 5 15

OOPs (Object-Oriented Programming System) OOPs (Object-Oriented Programming System)Object means a real-world entity such as a pen, chair, table, computer, watch, etc. Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies software development and maintenance by providing some concepts : Object Class Inheritance Polymorphism Abstraction Encapsulation 16

Object The Object is the real-time entity having some state and behavior. In Java, Object is an instance of the class having the instance variables as the state of the object and the methods as the behavior of the object. The object of a class can be created by using the new keyword in Java Programming language.  1. An object is a real-world entity. 2. An object is a runtime entity. 3. The object is an entity which has state and behavior. 4. The object is an instance of a class .  object in Java is the physical entity Real-world examples Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Chair, Bike, Marker, Pen, Table, Car, Book, Apple, Bag etc. It can be physical or logical (tangible and intangible). 17

Apart from these concepts, there are some other terms which are used in Object-Oriented design : - Coupling - Cohesion - Association - Aggregation - Composition 18

19

class A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. In short, a class is the  specification or template of an object . class in Java is a logical entity only .  A class is a template or blueprint from which objects are created. So, an object is the instance(result) of a class. A class in Java can contain: Fields Methods Constructors Blocks Nested class and interface 20

21

class  < class_name >{       method;       field;   }    22

23

//Java Program to illustrate how to define a class and fields    //Defining a Student class.    class  Student{     //defining fields      int  id; //field or data member or instance variable     String name;     //creating main method inside the Student class      public   static   void  main(String  args []){      //Creating an object or instance      Student s1= new  Student(); //creating an object of Student       //Printing values of the object       System.out.println (s1.id); //accessing member through reference variable       System.out.println (s1.name);    }   } 24

//Java Program to demonstrate having the main method in     //another class    //Creating Student class.    class  Student{     int  id;    String name;   }   //Creating another class TestStudent1 which contains the main method    class  TestStudent1{     public   static   void  main(String  args []){     Student s1= new  Student();      System.out.println (s1.id);      System.out.println (s1.name);    }   }   25

class  Student{     int  id;    String name;   }   class  TestStudent2{     public   static   void  main(String  args []){     Student s1= new  Student();     s1.id= 101 ;     s1.name= " Sonoo " ;      System.out.println (s1.id+ " " +s1.name); //printing members with a white space     }   }   26

class  Student{     int   rollno ;    String name;     void   insertRecord ( int  r, String n){      rollno =r;     name=n;    }     void   displayInformation (){ System.out.println ( rollno + " " +name);}   }   class  TestStudent4{     public   static   void  main(String  args []){     Student s1= new  Student();     Student s2= new  Student();     s1.insertRecord( 111 , "Karan" );     s2.insertRecord( 222 , "Aryan" );     s1.displayInformation();     s2.displayInformation();    }   }   27

public static void main(String args []){ Student2 s1=new Student2(); Student2 s2=new Student2(); s1.insertRecord(111,"Karan"); s2.insertRecord(222,"Aryan"); s1.displayInformation(); s2.displayInformation(); } } 111 Karan 222 Aryan OUTPUT 28
Tags