you sir have just got another subscriber. beautiful explanation and I wrote so many lines of code until you showed how to simply used those three attributes for ALL of the student objects instead of making one attribute for each object. definitely i am going to check out all of your other videos too. thank you.
I have a list which I got from DB query based on few conditions, which contains below location details... I want o/p as segregated locations i.e all cities and zipcodes into its state, all states into country Cou1 state1 city1 zip1 Cou1 state2 city2 zip2 Cou1 state1 city 3 zip3 O/p sld be as Cou1 State1 Cit1 - zip1 Cit3 - zip3 State2 Cit2 - zip2
Collection functionality wise ... If u create a object as collections U can access lot of methods to perform CRUD operations on data Which is in collection..nd also growable in nature size wise nd it follows some data Structures...i.e data in some order ..ascending or descending but if u create object as array ...it is fixed u cannot add new data and u cannot delete and allows it won't follow data structures When ever u r requirement is fixed heterogenous data and no need of delete of data .. we will go for Object array ..
Hello Sir, Getting below error error: cannot find symbol Student s1=new Student(); ^ symbol: class Student location: class ArrayObject ArrayObject.java:4: error: cannot find symbol Student s1=new Student(); ^ symbol: class Student location: class ArrayObject 2 errors MY code class ArrayObject{ public static void main(String a[]){
I have two doubts here, 1.When we create an object the class name should be same 2. When we create the three student objects you didnt intialize the data types for rollno, name, marks. If anyone knows please rectify my doubts. Thanks in advance
Okay let me address your doubts: 1. Yes, when you create an object in Java, the class name should be the same. For example: Imagine you have a class called Student. If you want to make an actual student object, you say Student st = new Student();. This naming consistency helps others (and yourself) easily understand what type of object is being created. class Student { // Class definition } Student st = new Student(); // Creating an object of the Student class 2. Coming to your second doubt, consider the below example : class Student { int rollNo; String name; double marks; } public class Main { public static void main(String[] args) { Student st1 = new Student(); st1.rollNo = 1; st1.name = "John"; st1.marks = 90.5; Student st2 = new Student(); st2.rollNo = 2; st2.name = "Jane"; st2.marks = 85.0; } } In the Student class, you have defined three instance variables: int is the data type for rollNo, String for name, and double for marks. These are the data types for the respective fields. In the Main class, you are creating two instances of the Student class (st1, st2) and initializing the data for each object. Hope you understood 😊!
you sir have just got another subscriber. beautiful explanation and I wrote so many lines of code until you showed how to simply used those three attributes for ALL of the student objects instead of making one attribute for each object. definitely i am going to check out all of your other videos too. thank you.
The best explanation of Array of Objects in Thank you!🙏
So array is going to store objects values in place of objects ?? Basically in a array each element consists of 3 different student values
I have a list which I got from DB query based on few conditions, which contains below location details... I want o/p as segregated locations i.e all cities and zipcodes into its state, all states into country
Cou1 state1 city1 zip1
Cou1 state2 city2 zip2
Cou1 state1 city 3 zip3
O/p sld be as
Cou1
State1
Cit1 - zip1
Cit3 - zip3
State2
Cit2 - zip2
Nice sir, can you do this using with constructor?
Can we use collection framework to create an array of objects.....??
Thanks in advance
First comment from #SriLanka.Thanks you so much for your help
public static void main(String[] args) use this if showing error
What is the difference b/w array of objects and collection functionality wise
Collection functionality wise ...
If u create a object as collections
U can access lot of methods to perform CRUD operations on data
Which is in collection..nd also growable in nature size wise nd it follows some data Structures...i.e data in some order ..ascending or descending but if u create object as array ...it is fixed u cannot add new data and u cannot delete and allows it won't follow data structures
When ever u r requirement is fixed heterogenous data and no need of delete of data .. we will go for Object array ..
More precise way
for(Student s: students) {
System.out.println(s.name + ":" + s.mark);
}
Is the length property a static attribute of the array object?
3:40 Good explanation
Getting error when Student class is not Static. But Navin didn't have it as static. What am I doing wrong?
What EDI do you use?
I think it's VS CODE
Vs code
VS Code (Visual studio code)
EDI or IDE 😂
@@Rahul-d7q3rman I thought I was losing my mind thinking the community changed the name
Hello Sir,
Getting below error
error: cannot find symbol
Student s1=new Student();
^
symbol: class Student
location: class ArrayObject
ArrayObject.java:4: error: cannot find symbol
Student s1=new Student();
^
symbol: class Student
location: class ArrayObject
2 errors
MY code
class ArrayObject{
public static void main(String a[]){
Student s1=new Student();
}
}
I got it solved, by creating a class using Student. Below is the code
class Student{
String name="";
int age= 0;
}
I have two doubts here, 1.When we create an object the class name should be same 2. When we create the three student objects you didnt intialize the data types for rollno, name, marks. If anyone knows please rectify my doubts. Thanks in advance
Okay let me address your doubts:
1. Yes, when you create an object in Java, the class name should be the same. For example:
Imagine you have a class called Student. If you want to make an actual student object, you say Student st = new Student();. This naming consistency helps others (and yourself) easily understand what type of object is being created.
class Student {
// Class definition
}
Student st = new Student(); // Creating an object of the Student class
2. Coming to your second doubt, consider the below example :
class Student {
int rollNo;
String name;
double marks;
}
public class Main {
public static void main(String[] args) {
Student st1 = new Student();
st1.rollNo = 1;
st1.name = "John";
st1.marks = 90.5;
Student st2 = new Student();
st2.rollNo = 2;
st2.name = "Jane";
st2.marks = 85.0;
}
}
In the Student class, you have defined three instance variables: int is the data type for rollNo, String for name, and double for marks. These are the data types for the respective fields.
In the Main class, you are creating two instances of the Student class (st1, st2) and initializing the data for each object.
Hope you understood 😊!
seson 2 kha hai bhae
How without proper {} this code is working,
You open { in last class and in main method but didn't close it
🔥🔥🔥🔥
i got an error
public class Main{
public static void main(String[] args) {
Student stud = new Student();
stud.roll = 1;
stud.marks = 88;
stud.name = "Kevin";
Student stud2 = new Student();
stud2.roll = 2;
stud2.marks = 78;
stud2.name = "Marco";
Student stud3 = new Student();
stud3.roll = 3;
stud3.marks = 90;
stud3.name = "Justin";
Student[] students = new Student[3];//Array with references
students[0] = stud;//Manual objects
students[1] = stud2;
students[2] = stud3;
for (Student student : students) {
System.out.print(student.name + " " + student.roll + " " + student.marks + "
");
}
}
}
class Student {
int roll;
int marks;
String name;
}
Why are you not updating VS Code? Please update VS Code.
It's sir choice 😅
In hindi?
Is Kiran is your best friend???😁