COURSES
MBAData Science & AnalyticsDoctorate Software & Tech AI | ML MarketingManagement
Professional Certificate Programme in HR Management and AnalyticsPost Graduate Certificate in Product ManagementExecutive Post Graduate Program in Healthcare ManagementExecutive PG Programme in Human Resource ManagementMBA in International Finance (integrated with ACCA, UK)Global Master Certificate in Integrated Supply Chain ManagementAdvanced General Management ProgramManagement EssentialsLeadership and Management in New Age BusinessProduct Management Online Certificate ProgramStrategic Human Resources Leadership Cornell Certificate ProgramHuman Resources Management Certificate Program for Indian ExecutivesGlobal Professional Certificate in Effective Leadership and ManagementCSM® Certification TrainingCSPO® Certification TrainingLeading SAFe® 5.1 Training (SAFe® Agilist Certification)SAFe® 5.1 POPM CertificationSAFe® 5.1 Scrum Master Certification (SSM)Implementing SAFe® 5.1 with SPC CertificationSAFe® 5 Release Train Engineer (RTE) CertificationPMP® Certification TrainingPRINCE2® Foundation and Practitioner Certification
Law
Job Linked
Bootcamps
Study Abroad
Master of Business Administration (90 ECTS)Master of Business Administration (60 ECTS)Master in Computer Science (120 ECTS)Master in International Management (120 ECTS)Bachelor of Business Administration (180 ECTS)B.Sc. Computer Science (180 ECTS)MS in Data AnalyticsMS in Project ManagementMS in Information TechnologyMasters Degree in Data Analytics and VisualizationMasters Degree in Artificial IntelligenceMBS in Entrepreneurship and MarketingMSc in Data AnalyticsMS in Data AnalyticsMaster of Science in AccountancyMS in Computer ScienceMaster of Science in Business AnalyticsMaster of Business Administration MS in Data ScienceMS in Information TechnologyMaster of Business AdministrationMS in Applied Data ScienceMaster of Business AdministrationMS in Data AnalyticsM.Sc. Data Science (60 ECTS)Master of Business AdministrationMS in Information Technology and Administrative Management MS in Computer Science Master of Business Administration MBA General Management-90 ECTSMSc International Business ManagementMS Data Science MBA Business Technologies MBA Leading Business Transformation Master of Business Administration MSc Business Intelligence and Data ScienceMS Data Analytics MS in Management Information SystemsMSc International Business and ManagementMS Engineering ManagementMS in Machine Learning EngineeringMS in Engineering ManagementMSc Data EngineeringMSc Artificial Intelligence EngineeringMPS in InformaticsMPS in Applied Machine IntelligenceMS in Project ManagementMPS in AnalyticsMS in Project ManagementMS in Organizational LeadershipMPS in Analytics - NEU CanadaMBA with specializationMPS in Informatics - NEU Canada Master in Business AdministrationMS in Digital Marketing and MediaMS in Project ManagementMaster in Logistics and Supply Chain ManagementMSc Sustainable Tourism and Event ManagementMSc in Circular Economy and Sustainable InnovationMSc in Impact Finance and Fintech ManagementMS Computer ScienceMS in Applied StatisticsMS in Computer Information SystemsMBA in Technology, Innovation and EntrepreneurshipMSc Data Science with Work PlacementMSc Global Business Management with Work Placement MBA with Work PlacementMS in Robotics and Autonomous SystemsMS in Civil EngineeringMS in Internet of ThingsMSc International Logistics and Supply Chain ManagementMBA- Business InformaticsMSc International ManagementMBA in Strategic Data Driven ManagementMaster of Business AdministrationMSc Digital MarketingMBA Business and MarketingMaster of Business AdministrationMSc Digital MarketingMSc in Sustainable Luxury and Creative IndustriesMSc in Sustainable Global Supply Chain ManagementMSc in International Corporate FinanceMSc Digital Business Analytics MSc in International HospitalityMSc Luxury and Innovation ManagementMaster of Business Administration-International Business ManagementMS in Computer EngineeringMS in Industrial and Systems EngineeringMSc International Business ManagementMaster in ManagementMSc MarketingMSc Business ManagementMSc Global Supply Chain ManagementMS in Information Systems and Technology with Business Intelligence and Analytics ConcentrationMSc Corporate FinanceMSc Data Analytics for BusinessMaster of Business AdministrationMaster of Business Administration 60 ECTSMaster of Business Administration 90 ECTSMaster of Business Administration 60 ECTSMaster of Business Administration 90 ECTSBachelors in International ManagementMS Computer Science with Artificial Intelligence and Machine Learning ConcentrationMaster of Business Administration
For College Students

Relational and Logical Operators in Java

$$/$$

In this video, we will discuss boolean variables in detail — a topic we introduced earlier as well. You already know that these variables can have true or false values only. But you’re still not clear about the situations where you can apply them or use them. You will learn about this in the following video.

$$/$$

Video Transcript

 

So now we are going to take a look at another data type in Java which are known as Booleans. Then further ahead we are also going to discuss some other stuff such as relational operators and logical operators. So for now, recall that Boolean is a data type into which you can only store two types of values. That is a Boolean variable can only be either true or it can be false. The size of the Boolean variable is exactly one bit. So for example, I can declare a Boolean like this. I'll say boolean A is equal to true. Similarly, I can declare another variable, say boolean B is equal to false. So both of these Booleans contain the value true and false respectively. In what cases will these Booleans or the Boolean data type be useful? Well, they can be highly useful in some cases in which we have to compare two quantities. That is, if I have to check if two quantities are equal or if two quantities are unequal, or if one of the quantities is greater than or less than the other quantity, then Boolean variables are really very useful. For example, if I wish to know whether four is greater than equal to five, then in that case I can store the result of this particular mathematical operation into some particular Boolean variable. So these kind of relations or these kind of symbols which are used to compare two different entities are known as relational operators.

 

So some of the commonly used relational operators are greater than or less than, greater than, equal to, less than equal to, equal to, equal to or not equal to. So let us walk through each one of them and see what results we get. So I say that Boolean x one is equal to. I say suppose five is greater than equal to nine and I store the result of this particular operation inside my Boolean x one. Now, when I try to print the value of x one, what do you think will be printed? Since five greater than equal to nine is a false relation because five is actually lesser than nine. So this x one will contain the value false inside it and false will be printed on the console. Similarly, if I say Boolean x two is equal to, say five is equal to is equal to seven, then what do you think will be printed when I try to print x two? Well, since this relationship that is five is equal to, is equal to seven is actually false because five is actually not equal to seven. So the value false will be contained and stored inside the variable x two. So when I try to print X two it is going to print false here. Now, if I wish to compare two quantities and check if they are unequal, then I can use the not equal to operator. The not equal to operator is comprised of an exclamation mark and an equal to symbol. So I say that Boolean x three is equal to five, not equal to seven. Now, when the program encounters this statement, it sees five not equal to seven. So it checks if this statement is true or false, since five is actually not equal to seven. So this particular relationship evaluates to true. So when I try to print x three, it will print true on the console. Similarly, what do you think will be printed when I try to print four greater than five? When I try to print four greater than five, it is going to print false. Here, if I try to print two less than seven, what do you think will be printed? Well, since this relationship is true, because two is actually less than seven. So here true will be printed.

 

So basically, Booleans are very useful in comparing any two quantities of which initial value. Also, you might not know here it is easy to see that five is greater than equal to nine. But perhaps there might be cases in which we need to compare two variables of which whose value we do not know. For example, I might have some number stored inside my variable A and another number stored inside variable B. Then based on that, I would need to perhaps check whether A is equal to equal to B. In that case, I will write A equal to equal to B, and the result of this particular relational operation will be stored inside another Boolean variable. Then, based on the result of whether A is equal to B, it will either print true or false. So this is how relational operators and Booleans work.

 

Video Recap

 

  • Booleans are a data type in Java that can store only true or false values, with a size of one bit.

  • They are useful in comparing two quantities using relational operators such as greater than or less than, greater than or equal to, less than or equal to, equal to, and not equal to.

  • Relational operators can be used to compare two variables, and the result is stored in another Boolean variable.

  • Booleans are helpful when comparing two variables of unknown values.

  • Relational operations can be stored in a Boolean variable and printed as true or false based on the comparison.

 

In the previous video, you learned about relational operators.

You just saw the kind of situations in which you use the boolean data type. You learnt about the operators (>, >=, <, <= , ==, !=) that are used to compare true values and to frame a condition that a boolean data type evaluates to true or false.

 

Let’s now learn about logical operators, which make boolean data types even more useful.

$$/$$

You learned about the “and” and “or” operations here. The “and” operation results in a true value only both of the conditions involved are true. Whereas, the “or” operation results in a true value even if one of the conditions involved is true.