Java Hyd Team
746 subscribers
986 photos
39 videos
670 files
690 links
https://teamhydteam.my.canva.site/

Can visit us on our website 😊
Still working on it 😊
Download Telegram
https://docs.google.com/spreadsheets/d/1j5O9_P7DbsqNLjv5s-DmYGvRey_GRwPLAOVpWXJ7s8Y/edit?usp=sharing click on this link to join the new sheet i will update by today night
Anyone wanna join this ?
1
public class Student { private int studentId; private String studentName; private int marks; private char grade; public Student() { // TODO Auto-generated constructor stub } public Student(int studentId, String studentName, int marks) { super(); this.studentId = studentId; this.studentName = studentName; this.marks = marks; calculateGrade(); } public String displayDetails() { return "Student [name=" + studentName + ", studentId=" + studentId + ", marks=" + marks + ", grade=" + grade + "]"; } private void calculateGrade() { if (marks <= 100 && marks >= 90) { grade = 'A'; } else if (marks <= 89 && marks >= 81) { grade = 'B'; } else if (marks <= 80 && marks >= 71) { grade = 'C'; } else if (marks <= 70 && marks >= 61) { grade = 'D'; } else if (marks <= 60 && marks >= 0) { grade = 'E'; } } }

public class Tester { public static void main(String[] args) { Student s1 = new Student(123, "John Smith", 95); System.out.println(s1.displayDetails()); } }

Output:

Student [name=John Smith, studentId=123, marks=95, grade=A]
There are five different ways to create an object in Java:
Java new Operator
Java Class.newInstance() method
Java newInstance() method of constructor
Java Object.clone() method
Java Object Serialization and Deserialization
class_name object_name = new class_name()
public T newInstance() throws IllegalAcccessException
public T newInstance(Objects...initargs)
public class Test {
public static void main(String[] args) {
String input = "sat23h6y7a8";
int sum = 0;
for (int i = 0; i < input.length(); i++) {
char ch = input.charAt(i);
if (Character.isDigit(ch)) {
sum = sum + Integer.parseInt(String.valueOf(ch));
}
}
System.out.println(sum);
}
}
Difference between final finally and finalize

The main difference between final, finally, and finalize in Java is that final is a keyword, finally is a block, and finalize is a method.

A final variable can only be assigned once and it cannot be changed.
A finally block is used to execute important code such as closing a connection, stream, or file.
A finalize method is used to perform cleanup operations before an object is destroyed.