This is for programming one in java. I have a quiz coming up and the teacher gav
ID: 3912068 • Letter: T
Question
This is for programming one in java. I have a quiz coming up and the teacher gave us a topic sheet for the quiz. Could you please answer these:1) what’s the difference b/w Relational operators (>,>=,<,<=,==,!=) and Boolean operators (&&, ||).
2) how to use the equals and compareTo instance methods in the string class. What is an ASCII table used for? What is Unicode?
3)Definitions of object-oriented programming, class, and object; How do you declare an object? What is the only type of object that does not require new?
4)What is a constructor method? When is it called? What is overloading?
5)Differences b/w public vs. private members.
6)Constructing a Boolean expression and using Boolean variables.
Thank you very much! This is for programming one in java. I have a quiz coming up and the teacher gave us a topic sheet for the quiz. Could you please answer these:
1) what’s the difference b/w Relational operators (>,>=,<,<=,==,!=) and Boolean operators (&&, ||).
2) how to use the equals and compareTo instance methods in the string class. What is an ASCII table used for? What is Unicode?
3)Definitions of object-oriented programming, class, and object; How do you declare an object? What is the only type of object that does not require new?
4)What is a constructor method? When is it called? What is overloading?
5)Differences b/w public vs. private members.
6)Constructing a Boolean expression and using Boolean variables.
Thank you very much!
1) what’s the difference b/w Relational operators (>,>=,<,<=,==,!=) and Boolean operators (&&, ||).
2) how to use the equals and compareTo instance methods in the string class. What is an ASCII table used for? What is Unicode?
3)Definitions of object-oriented programming, class, and object; How do you declare an object? What is the only type of object that does not require new?
4)What is a constructor method? When is it called? What is overloading?
5)Differences b/w public vs. private members.
6)Constructing a Boolean expression and using Boolean variables.
Thank you very much!
Explanation / Answer
Relational Operators
Relational Operators are also called conditional operators. These operators are used to compare between two numerical values.
1. >
This operator is known as greater than operator. It is used to compare between 2 numbers and check whether 1st number is exactly greater than 2nd number or not
e.g. if(25 > 20)
2. >=
This operator is known as greater than or equal to operator. It is used to compare between 2 numbers and check whether 1st number is greater than or equals 2nd number or not
e.g. if(25 >= 25)
3. <
This operator is known as less than operator. It is used to compare between 2 numbers and check whether 1st number is exactly less than 2nd number or not
e.g. if(20 < 25)
4. <=
This operator is known as less than or equal to operator. It is used to compare between 2 numbers and check whether 1st number is less than or equals 2nd number or not
e.g. if(20 <= 20)
5. ==
This operator is known as equal to operator. It is used to compare between 2 numbers and check whether 1st number is exactly equal to 2nd number or not
e.g. if(50 == 50)
6. !=
This operator is known as not equal to operator. It is used to compare between 2 numbers and check whether 1st number is unequal to the 2nd number or not
e.g. if(25 != 20)
2. Difference between equals and compareTo
Both the methods equals() and compareTo() method are used with Strings.
The equals method is used to check the equality of 2 Strings. It decides whether 2 Strings are same or not. e.g.
String s1 = "Hello";
String s2 = "Welcome";
if(s1.equals(s2)){
System.out.print('The Strings are equal");
else
System.out.print('The Strings are not equal");
In the above case it will print The Strings are not equal since the Strings are not equal.
The compareTo method is also used with Strings, it when used with 2 Strings returns a value greater than 0 if 1st String is greater than the 2nd and return a negative value if 2nd String is greater than the 1st else returns 0 if both Strings are same.
e.g. if(s1.compareTo(s2) < 0 )
In the above case the expression s1.compareTo(s2) will return a negative number and the if condition will evaluate to true.
ASCII values are the integer representation of the alphabet characters and special symbols of english alphabet. There are total 128 english characters including special symbols such as numbers, comma, question mark, exclamation mark etc.. e.g. ASCII code of character A is 65.
UNICODE values work alike ASCII code but difference is that it also supports the characters outside of the english alphabet.e.g. to repesent the non-english characters such as any French alphabet or any other symbol not in the English alphabet.
Boolean Operators
These are also known as logical operators. These are used to compare between 2 or more than 2 expressions together.
1. &&
This operator is known as logical AND operator used to compare 2 conditions and carry a specific task if both of the sub-expressions are evaluate to true.
e.g. if(num1 > num2 && num1 > num3)
In the above expression the if condition will evaluate to true if num1 is greater than num2 and num1 is greater than num3 as well.
2. ||
This operator is called logical OR operator. It is used to check whether any of the sub-expression is true or not.
e.g. if(num1 > num2 || num3 < num2)
In the above condition the if condition will evaluate to true if num1 is greater than num2 or num3 is greater than num2. Just any of the sub-expression is needed to be true.
3. Object Oriened Programming is a Programming technique in which all the Programming task is performed with the help of Classes and objects.
Class is an encapsulated form or a container which consist of methods, instance variables which is used to encapsulate the required programming details under a single broader unit.
Object give life to classes. They are instance or representative of the classes of which they are declared. When we declare an object to a class then programmatically we allocate a memory to a single instance of the class.
Suppose we create a class called Demo then to create an object to this class we need to write Demo objectDemo = new Demo();
Where objectDemo is the created object of the class Demo.
=>When we are cloning an object from another object then it doesnot require the new keyword. e.g. Demo anotherObject = (Demo)objectDemo.clone();
4. A Constructor is a default/user-defined method which is automatically called when an Object to that class is created. It is defined with the same name as that of the class.
When we declare two or more than 2 constructors within a class with different parameter list then it is known as Constructor Overloading.
5. Public members are global data members which are accessible to everywhere within the class, its sub-class, package and sub-packages. The members uses a keyword public to make them public or global members. e.g. public int num;
Private members are the data members which are accessible to that class only in which they are declared and are not accessible any where outside that class. e.g. private int num;
6. A boolean expression is an expression which when evaluated produces either true or false based on their truthness. They are constructed by using the combination of relational operators and/or logical AND and OR operators.
e.g. boolean result = (i > 10 && i < 20)?true:false;
In the above expression the i is compared with 10 and 20, if its greater than 10 and less than 20 then result is true else its false.
Boolean variables are the variables which has the value either true or false. The default value of a boolean value is false.
e.g. boolean result;
Relational Operators
Relational Operators are also called conditional operators. These operators are used to compare between two numerical values.
1. >
This operator is known as greater than operator. It is used to compare between 2 numbers and check whether 1st number is exactly greater than 2nd number or not
e.g. if(25 > 20)
2. >=
This operator is known as greater than or equal to operator. It is used to compare between 2 numbers and check whether 1st number is greater than or equals 2nd number or not
e.g. if(25 >= 25)
3. <
This operator is known as less than operator. It is used to compare between 2 numbers and check whether 1st number is exactly less than 2nd number or not
e.g. if(20 < 25)
4. <=
This operator is known as less than or equal to operator. It is used to compare between 2 numbers and check whether 1st number is less than or equals 2nd number or not
e.g. if(20 <= 20)
5. ==
This operator is known as equal to operator. It is used to compare between 2 numbers and check whether 1st number is exactly equal to 2nd number or not
e.g. if(50 == 50)
6. !=
This operator is known as not equal to operator. It is used to compare between 2 numbers and check whether 1st number is unequal to the 2nd number or not
e.g. if(25 != 20)
2. Difference between equals and compareTo
Both the methods equals() and compareTo() method are used with Strings.
The equals method is used to check the equality of 2 Strings. It decides whether 2 Strings are same or not. e.g.
String s1 = "Hello";
String s2 = "Welcome";
if(s1.equals(s2)){
System.out.print('The Strings are equal");
else
System.out.print('The Strings are not equal");
In the above case it will print The Strings are not equal since the Strings are not equal.
The compareTo method is also used with Strings, it when used with 2 Strings returns a value greater than 0 if 1st String is greater than the 2nd and return a negative value if 2nd String is greater than the 1st else returns 0 if both Strings are same.
e.g. if(s1.compareTo(s2) < 0 )
In the above case the expression s1.compareTo(s2) will return a negative number and the if condition will evaluate to true.
ASCII values are the integer representation of the alphabet characters and special symbols of english alphabet. There are total 128 english characters including special symbols such as numbers, comma, question mark, exclamation mark etc.. e.g. ASCII code of character A is 65.
UNICODE values work alike ASCII code but difference is that it also supports the characters outside of the english alphabet.e.g. to repesent the non-english characters such as any French alphabet or any other symbol not in the English alphabet.
Boolean Operators
These are also known as logical operators. These are used to compare between 2 or more than 2 expressions together.
1. &&
This operator is known as logical AND operator used to compare 2 conditions and carry a specific task if both of the sub-expressions are evaluate to true.
e.g. if(num1 > num2 && num1 > num3)
In the above expression the if condition will evaluate to true if num1 is greater than num2 and num1 is greater than num3 as well.
2. ||
This operator is called logical OR operator. It is used to check whether any of the sub-expression is true or not.
e.g. if(num1 > num2 || num3 < num2)
In the above condition the if condition will evaluate to true if num1 is greater than num2 or num3 is greater than num2. Just any of the sub-expression is needed to be true.
3. Object Oriened Programming is a Programming technique in which all the Programming task is performed with the help of Classes and objects.
Class is an encapsulated form or a container which consist of methods, instance variables which is used to encapsulate the required programming details under a single broader unit.
Object give life to classes. They are instance or representative of the classes of which they are declared. When we declare an object to a class then programmatically we allocate a memory to a single instance of the class.
Suppose we create a class called Demo then to create an object to this class we need to write Demo objectDemo = new Demo();
Where objectDemo is the created object of the class Demo.
=>When we are cloning an object from another object then it doesnot require the new keyword. e.g. Demo anotherObject = (Demo)objectDemo.clone();
4. A Constructor is a default/user-defined method which is automatically called when an Object to that class is created. It is defined with the same name as that of the class.
When we declare two or more than 2 constructors within a class with different parameter list then it is known as Constructor Overloading.
5. Public members are global data members which are accessible to everywhere within the class, its sub-class, package and sub-packages. The members uses a keyword public to make them public or global members. e.g. public int num;
Private members are the data members which are accessible to that class only in which they are declared and are not accessible any where outside that class. e.g. private int num;
6. A boolean expression is an expression which when evaluated produces either true or false based on their truthness. They are constructed by using the combination of relational operators and/or logical AND and OR operators.
e.g. boolean result = (i > 10 && i < 20)?true:false;
In the above expression the i is compared with 10 and 20, if its greater than 10 and less than 20 then result is true else its false.
Boolean variables are the variables which has the value either true or false. The default value of a boolean value is false.
e.g. boolean result;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.