Summary

This document is a Java programming tutorial, introducing basic concepts such as computer system components and fundamental Java elements. It covers Java applications, computer programming terminologies, and the importance of choosing Java as a programming language. The tutorial provides an overview of Java's capabilities and its role in the programming landscape.

Full Transcript

Table of Contents {#table-of-contents.TOCHeading} ================= **Module 1: Introduction to Computer Programming1** Introduction to Java Application3 Java Basic Building Blocks3 **Module 2: Basic Data Types4** Data Types in Java5 **Module 3: Java Operators** Assignment Operators53 Compar...

Table of Contents {#table-of-contents.TOCHeading} ================= **Module 1: Introduction to Computer Programming1** Introduction to Java Application3 Java Basic Building Blocks3 **Module 2: Basic Data Types4** Data Types in Java5 **Module 3: Java Operators** Assignment Operators53 Comparison Operators54 Logical Operators55 Bitwise Operators56 Unary Operators57 **Module 1** **Introduction to Computer Programming** At the end of this module you are expected to: 1. Define basic concepts of Information Technology 2. Understand Java as a programming Language 3. Learn and apply on how to install Java on your computer 4. Identify different Parts of a Java Program **Basic Concepts of Information Technology** **Technology** is the application of science, math, engineering, art and other filed of knowledge to create tools & implementation considered useful by the society **Information Technology** (IT) is the totality means employed to systematically collect, store, process, present, and share info. In support of human intellectual activities, it serves as a tool. Is pronounced \"I.T.\" It refers to anything related to computing technology, such as networking, hardware, software, the Internet. **Data** -- a collection of raw facts, numbers letters symbols, or any combination of these and provide results. **Information** -- data that is made meaningful based on the needs of the user through manipulation in computer terms. **Computer system components/ Elements of a computer** 1. **Hardware** This includes the physical components of a computer Functional parts: - Data preparation devices - Input devices - Output devices 2. **Software** Serving as the intermediary between computer users and the computer hardware, software refers to the intangible part of the computer system. Software categories: - **Applications software** (also called end-user programs) includes such things as database programs, word processors, Web browsers, and spreadsheets. is the most common software on the computer that performs a special function - **System software** - is a type of computer program that is designed to run a computer\'s hardware and application programs. 3. **Peopleware** Refers to personnel that manages and uses the computer system. Examples of Peopleware include various job roles that are commonly understood as parts of an IT process. **Types of memory** **Random Access Memory** (RAM) - Volatile memory is temporary memory while - This type of memory is volatile and all information that was stored in RAM is lost when the computer is turned off. **Read-Only Memory** (ROM) -- is non-volatile and holds data permanently when the power is turned off. **Operating System Architecture** A computer system can be divided into four components: ![](media/image2.png)**Computer System Organization** **Introduction to Java Application** **Java **is a high level, a modern programming language designed in the early 1990s by Sun Microsystems, and currently owned by Oracle. Java is **Platform Independent**, which means that you only need to write the program once to be able to run it on several different platforms!\ Java is **portable**, **robust**, and **dynamic**, with the ability to fit the needs of virtually any type of application. Java guarantees that you\'ll be able to **Write Once, Run Anywhere**. **Several Computer Programming Terminologies** To tell a computer what to do, you have to use a special language to write terse, unambiguous instructions. A special language of this kind is called a ***computer programming language**.* A set of instructions written in such a language is called a ***program**.* When looked at as a big blob, these instructions are called ***software*** or ***code**.* **Here's what code looks like when it's written in Java:** Figure. Sample Java Code ***Why You Should Use Java*** To prepare for the party, I'll bake a cake. I'm lazy, so I'll use a ready-to-bake cake mix. Let me see... add water to the mix and then add butter and eggs... Hey, wait! I just looked at the list of ingredients. What's MSG? And what about propylene glycol? That's used in antifreeze, isn't it? I'll change plans and make the cake from scratch. Sure, it's a little harder, but that way I get exactly what I want. Computer programs work the same way. You can use somebody else's program or write your own. If you use somebody else's program, you use whatever you get. When you write your program, you can tailor the program, especially for your needs. Writing computer code is a big, worldwide industry. Companies do it, freelance professionals do it, hobbyists do it --- all kinds of people do it. A typical big company has teams, departments, and divisions that write programs for the company. But you can write programs for yourself or someone else, for a living or fun. In a recent estimate, the number of lines of code written each day by programmers in the United States alone exceeds the number of methane molecules on the planet Jupiter. Take almost anything that can be done with a computer. With the right amount of time, you can write your program to do it. (Of course, the "right amount of time" may be very long, but that's not the point. Many interesting and useful programs can be written in hours or even minutes.) ***Getting Perspective: Where Java Fits In*** **1954--1957: FORTRAN is developed.** FORTRAN was the first modern computer programming language. For scientific programming, FORTRAN is a real racehorse. Year after year, FORTRAN is a leading language among computer programmers throughout the world. **1959: Grace Hopper at Remington Rand develops the COBOL programming language.** The letter B in COBOL stands for Business, and business is just what COBOL is all about. The language's primary feature is the processing of one record after another, one customer after another, or one employee after another. Within a few years after its initial development, COBOL became the most widely used language for business data processing. Even today, COBOL represents a large part of the computer programming industry **1972: Dennis Ritchie at AT&T Bell Labs develops the C programming language.** In terms of power, you can use C to solve the same problems that you can solve by using FORTRAN, Java, or any other modern programming language. (You can write a scientific calculator program in COBOL, but doing that sort of thing would feel strange.) The difference between one programming language and another isn't power. The difference is ease and appropriateness of use. That's where the Java language excels. **1986: Bjarne Stroustrup (again at AT&T Bell Labs) develops C++.** Unlike its C language ancestor, the language C++ supports object-oriented programming. This support represents a huge step forward. **May 23, 1995: Sun Microsystems releases its first official version of the Java programming language.** Java improves upon the concepts in C++. Java's "Write Once, Run Anywhere" philosophy makes the language ideal for distributing code across the Internet. Additionally, Java is a great general-purpose programming language. With Java, you can write windowed applications, build and explore databases, control handheld devices, and more. Within five short years, the Java programming language had 2.5 million developers worldwide. **November 2000: The College Board announces that starting in the year 2003, the Computer Science Advanced Placement exams will be based on Java.** 2002: Microsoft introduces a new language named C\#. June 2004: Sys-Con Media reports that the demand for Java programmers tops the demand for C++ programmers by 50 percent And there's more! The demand for Java programmers beats the combined demand for C++ and C\# programmers by 8 percent. Java programmers are more employable than VB (Visual Basic) programmers by a whopping 190 percent. **2007: Google adopts Java as the primary language for creating apps on Android mobile devices.** **January 2010: Oracle Corporation purchases Sun Microsystems, bringing Java technology into the Oracle family of products.** June 2010: eWeek ranks Java first among its "Top 10 Programming Languages to Keep You Employed" **August 2013: Java runs on more than 1.1 billion desktop computers and Android Java runs on 250 million mobile phones** **Java JDK, JRE, and JVM** **What is JVM?** **JVM** (Java Virtual Machine) is an abstract machine that enables your computer to run a Java program. When you run the Java program, Java compiler first compiles your Java code to bytecode. Then, the JVM translates bytecode into native machine code (set of instructions that a computer\'s CPU executes directly). Java is a platform-independent language. It\'s because when you write Java code, it\'s ultimately written for JVM but not your physical machine (computer). Since JVM ​executes the Java bytecode which is platform-independent, Java is platform-independent. Figure. Working with java **What is JRE?** **JRE** (Java Runtime Environment) is a software package that provides Java class libraries, Java Virtual Machine (JVM), and other components that are required to run Java applications. JRE is the superset of JVM. Figure. JRE **What is JDK?** **JDK** (Java Development Kit) is a software development kit required to develop applications in Java. When you download JDK, JRE is also downloaded with it. In addition to JRE, JDK also contains several development tools (compilers, JavaDoc, Java Debugger, etc). Figure. JDK **Relationship between JVM, JRE, and JDK.** Figure. Relationship **How to Download & Install Java JDK 8 in Windows** Following are steps to install Java in Windows **Step 1)** Go to the [link](https://www.oracle.com/java/technologies/javase-downloads.html) (https://www.oracle.com/java/technologies/javase-downloads.html). Click on Download JDK. For java latest version. https://www.guru99.com/images/java/1912211\_install\_javaimage1.jpg Figure. Java Platform **Step 2)** Next, 1. Accept License Agreement 2. Download the latest Java JDK for your version(32 or 64 bit) of java for Windows. ![https://www.guru99.com/images/java/1912211\_install\_javaimage2.jpg](media/image9.jpeg) Figure. Java Development Kit **Step 3)** Once the download is complete, run the exe for install JDK. Click Next https://www.guru99.com/images/java/1912211\_install\_javaimage3.jpg Figure. Set-up **Step 4)** Select the PATH for Java installation and click next. ![https://www.guru99.com/images/java/1912211\_install\_javaimage4.jpg](media/image11.jpeg) Figure. Java Path Selection **Step 5)** Once installation is complete click Close https://www.guru99.com/images/java/1912211\_install\_javaimage5.jpg Figure. Installation Complete **How to set Environment Variables in Java: Path and Classpath** The PATH variable gives the location of executable like javac, java, etc. It is possible to run a program without specifying the PATH but you will need to give full path of executable like **C:\\Program Files\\Java\\jdk-13.0.1\\bin\\javac A.java** instead of simple **javac A.java** The CLASSPATH variable gives the location of the Library Files. Let\'s look into the steps to set the PATH and CLASSPATH **Step 1)** Right Click on the My Computer and Select the properties ![https://www.guru99.com/images/java/111417\_1107\_Java25.png](media/image13.png) Figure. My Computer **Step 2)** Click on advanced system settings https://www.guru99.com/images/java/111417\_1107\_Java26.png Figure. Advance System Settings **Step 3)** Click on Environment Variables ![https://www.guru99.com/images/java/111417\_1107\_Java27.png](media/image15.png) Figure. Environment Variables **Step 4)** Click on New Button of User variables https://www.guru99.com/images/java/1912211\_install\_javaimage9.jpg **Step 5)** Type PATH in the Variable name. ![https://www.guru99.com/images/java/111417\_1107\_Java29.png](media/image17.png) Figure. PATH **Step 6)** Copy the path of the bin folder which is installed in the JDK folder. https://www.guru99.com/images/java/1912211\_install\_javaimage11.jpg Figure. Copy the Path **Step 7)** Paste Path of bin folder in Variable value and click on OK Button. ![https://www.guru99.com/images/java/1912211\_install\_javaimage12.jpg](media/image19.jpeg) Figure. Paste the Path **Note:** In case you already have a PATH variable created in your PC, edit the PATH variable to PATH = \\\bin;%PATH%; Here, %PATH% appends the existing path variable to our new value **Step 8) **You can follow a similar process to set CLASSPATH. https://www.guru99.com/images/java/1912211\_install\_javaimage13.jpg Figure. Class Path **Note:** In case your java installation does not work after installation, change classpath to CLASSPATH = \\\lib\\tools.jar; **Step 9)** Click on OK button ![https://www.guru99.com/images/java/1912211\_install\_javaimage14.jpg](media/image21.jpeg) Figure. Select OK **Step 10)** Go to command prompt and type javac commands. If you see a screen like below, Java is installed. https://www.guru99.com/images/java/1912211\_install\_javaimage15.jpg Figure. Type javac Command For a video tutorial on Installing JDK and Writing Your First Java Program: - **Java Basic Building Blocks** **Parts of a Java Program** **A Hello World Program** **Your First Java Program** Let\'s start by creating a simple program that prints "Hello World" to the screen. Figure. Sample java Code In Java, every line of code that can run needs to be inside a **class**.\ In our example, we named the class **MyClass**. You will learn more about the classes in the upcoming modules. In Java, each application has an entry point, or a starting point, which is a method called **main**. Along with the main, the keywords **public **and **static **will also be explained later. As a summary: \- Every program in Java must have a class. \- Every Java program starts from the main method. **The main Method** To run our program, the **main **method must be identical to this signature: **public [static] [void] main([String]\[ \] args)** - **public**: anyone can access it - **static**: method can be run without creating an instance of the class containing the main method - **void**: method doesn\'t return any value - **main**: the name of the method For example, the following code declares a method called **test**, which does not return anything and has no parameters: [void] test(). The [method]\'s parameters are declared inside the parentheses that follow the name of the [method]. For **main**, it\'s an [array] of strings called **args**. We will use it in our next lesson, so don\'t worry if you don\'t understand it all now. **System.out.println()** Next is the body of the main method, enclosed in curly braces: { System.out.println(\"Hello World!\"); } The **println **method prints a line of text to the screen. The **System **class and its **out-**stream are used to access the **println **method. In classes, methods, and other flow-control structures code is always enclosed in curly braces { }. **Semicolons in Java** Figure. Sample Java Code In Java, each code statement must end with a **semicolon**. Remember: do not use **semicolons **after [method] and class declarations that follow with the body defined using the curly braces. **Java Comments** **Comments** The purpose of including comments in your code is to explain what the code is doing. Java supports both single and multi-line comments. All characters that appear within a comment are ignored by the Java compiler. A **single-line** comment starts with **two forward slashes **and continues until it reaches the end of the line. For example: **// this is a single-line comment** x = 5; **// a single-line comment after code** Adding comments as you write code is a good practice because they provide clarification and understanding when you need to refer back to it, as well as for others who might need to read it. Single-line comments are created using: \*/ characters at the beginning of the line // characters at the beginning of the line // characters at the end of the line \*\* characters at the beginning of the line **Multi-Line Comments** Java also supports comments that span multiple lines. You start this type of comment with a forward slash followed by an asterisk and end it with an asterisk followed by a forward slash. For example: Note that Java does not support nested multi-line comments.\ However, you can nest single-line comments within multi-line comments. /\* This is a single-line comment: // a single-line comment \*/ Another name for a Multi-Line comment is a Block comment. Make this text a multi-line comment. [/\*] some \* comment text [\*/] **Documentation Comments** **Documentation comments** are special comments that have the appearance of multi-line comments, with the difference being that they generate external documentation of your source code. These begin with a forward slash followed by two asterisks and end with an asterisk followed by a forward slash.\ For example:/\*\* This is a documentation comment \*/ /\*\* This is also a\ documentation comment \*/ **Javadoc **is a tool that comes with JDK and it is used for generating Java code documentation in HTML format from Java source code which has required documentation in a predefined format. When a documentation comment begins with more than two asterisks, Javadoc assumes that you want to create a \"box\" around the comment in the source code. It simply ignores the extra asterisks. For example:/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\ This is the start of a [method]\ \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/ This will retain just the text \"This is the start of a [method]\" for the documentation. **Case is Important** Yes, Java is case sensitive. This might seem a little frustrating, especially when you realize why your program isn\'t running right. The variable you sent (TreeCount) is really named treeCount! There is a reason for this, and it\'s really at the level of bits and bytes. To a computer, t is not T. This can frustrate a human, but the computer doesn\'t care. They are completely different values in memory. Therefore, the following code is perfectly acceptable (although it might drive your quality analyst or tester crazy). **References and Supplementary Materials** **Books** 1. Barry Burd (2014). Java for Dummies. A Wiley Brand, New Jersey: John Wiley & Sons, Inc. **Online Supplementary reading Material** 1. **Java JDK, JRE and JVM;** **https://www.programiz.com/java-programming/jvm-jre-jdk; Retrieved August 28, 2020** 2. **How to Download & Install Java JDK 8 in Windows; https://www.guru99.com/install-java.html; Retrieved August 27, 2020** 3. **Java;** **https://www.sololearn.com/play/java/; Retrieved July 20, 2020** **Module 2** **Basic Data Types** At the end of this module you are expected to: 1. Understand different Variables in Java 2. Learn and apply what are the Data types in Java **Variables** Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. **Variables **store data for processing. A variable is given a name (or **identifier**), such as area, age, height, and the like. The name uniquely identifies each variable, assigning a value to the variable and retrieving the value stored. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables. Variables have **types**. Some examples: - **int**: for integers (whole numbers) such as 123 and -456 - **double**: for floating-point or real numbers with optional decimal points and fractional parts in fixed or scientific notations, such as 3.1416, -55.66. - **String**: for texts such as \"Hello\" or \"Good Morning!\". Text strings are enclosed within double quotes. You can declare a variable of a type and assign it a value. Example: [String] name = \"David\";\ This creates a variable called **name **of type **String**, and assigns it the value \"David\". It is important to note that a variable is associated with a type, and is only capable of storing values of that particular type. For example, an **[int] **variable can store [integer] values, such as 123; but it cannot store real numbers, such as 12.34, or texts, such as \"Hello\". **Data Types in Java** **Data Types in Java are defined as specifiers that allocate different sizes and types of values that can be stored in the variable or an identifier. Java has a rich set of data types. Data types in Java can be divided into two parts:** 1. **Primitive Data Types - which include integer, character, boolean, and float** 2. **Non-primitive Data Types - which include classes, arrays and interfaces.** Figure. Data Types **Primitive Data Types** There are eight primitive data types supported by Java. Primitive data types are predefined by the language and named by a keyword. Let us now look into the eight primitive data types in detail. **byte** - Byte data type is an 8-bit signed two\'s complement integer - Minimum value is -128 (-2\^7) - Maximum value is 127 (inclusive)(2\^7 -1) - Default value is 0 - Byte data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an integer. - Example: byte a = 100, byte b = -50 Figure. Sample Java Code **short** - Short data type is a 16-bit signed two\'s complement integer - Minimum value is -32,768 (-2\^15) - Maximum value is 32,767 (inclusive) (2\^15 -1) - Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an integer - Default value is 0. - Example: short s = 10000, short r = -20000 Figure. Sample Java Code **int** - Int data type is a 32-bit signed two\'s complement integer. - Minimum value is - 2,147,483,648 (-2\^31) - Maximum value is 2,147,483,647(inclusive) (2\^31 -1) - Integer is generally used as the default data type for integral values unless there is a concern about memory. - The default value is 0 - Example: int a = 100000, int b = -200000 Figure. Sample Java Code **long** - Long data type is a 64-bit signed two\'s complement integer - Minimum value is -9,223,372,036,854,775,808(-2\^63) - Maximum value is 9,223,372,036,854,775,807 (inclusive)(2\^63 -1) - This type is used when a wider range than int is needed - Default value is 0L - Example: long a = 100000L, long b = -200000L Figure. Sample Java Code Notice, the use of L at the end of -42332200000. This represents that it\'s an integral literal of the long type. You will learn about integral literals later in this article. **float** - Float data type is a single-precision 32-bit IEEE 754 floating point - Float is mainly used to save memory in large arrays of floating point numbers - Default value is 0.0f - Float data type is never used for precise values such as currency - Example: float f1 = 234.5f Figure. Sample Java Code Notice that, we have used -42.3f instead of -42.3in the above program. It\'s because -42.3 is a double literal. To tell the compiler to treat -42.3 as float rather than double, you need to use f or F. **double** - double data type is a double-precision 64-bit IEEE 754 floating point - This data type is generally used as the default data type for decimal values, generally the default choice - Double data type should never be used for precise values such as currenc - Default value is 0.0d - Example: double d1 = 123.4 Figure. Sample Java Code **boolean** - boolean data type represents one bit of information - There are only two possible values: true and false - This data type is used for simple flags that track true/false conditions - Default value is false - Example: boolean one = true Figure. Sample Java Code **char** - char data type is a single 16-bit Unicode character - Minimum value is \'\\u0000\' (or 0) - Maximum value is \'\\uffff\' (or 65,535 inclusive) - Char data type is used to store any character - Example: char letterA = \'A\' Figure. Sample Java Code **Reference Data types** - Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed. For example, Employee, Puppy, etc. - Class objects and various type of array variables come under reference datatype. - Default value of any reference variable is null. - A reference variable can be used to refer any object of the declared type or any compatible type. - Example: Animal animal = new Animal(\"giraffe\"); **Java Literals** A literal is a source code representation of a fixed value. They are represented directly in the code without any computation. Literals can be assigned to any primitive type variable. For example -- byte a = 68; char a = \'A\'; byte, int, long, and short can be expressed in decimal(base 10), hexadecimal(base 16) or octal(base 8) number systems as well. Prefix 0 is used to indicate octal, and prefix 0x indicates hexadecimal when using these number systems for literals. For example -- int decimal = 100; int octal = 0144; int hexa = 0x64; **Variables** Figure. Sample java Code **Non-Primitive Data Types** Non-primitive data types are called **reference types** because they refer to objects. The main difference between **primitive** and **non-primitive** data types are: - Primitive types are predefined (already defined) in Java. Non-primitive types are created by the programmer and is not defined by Java (except for String). - Non-primitive types can be used to call methods to perform certain operations, while primitive types cannot. - A primitive type has always a value, while non-primitive types can be null. - A primitive type starts with a lowercase letter, while non-primitive types starts with an uppercase letter. - The size of a primitive type depends on the data type, while non-primitive types have all the same size. Examples of non-primitive types are **[Strings](https://www.w3schools.com/java/java_strings.asp), [Arrays](https://www.w3schools.com/java/java_arrays.asp), [Classes, ](https://www.w3schools.com/java/java_classes.asp)[Interface](https://www.w3schools.com/java/java_interface.asp)**, etc. You will learn more about these in a later chapter. **Module 3** **Java Operators** At the end of this module you are expected to: 1. Understand different Operators in Java 2. Learned and Applied what are the Operators in Java **Java Operators** **Operators** are used to perform operations on variables and values. In Java, operator is a symbol which is used to perform operations. For example: +, -, \*, / etc. Example: int x = 100 + 50; Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups. - Arithmetic operators - Assignment operators - Comparison operators - Logical operators - Bitwise operators - Unary operators **Arithmetic Operators** Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, etc. **Operator** **Meaning** -------------- ----------------------------------------------- \+ Addition (also used for string concatenation) \- Subtraction Operator \* Multiplication Operator / Division Operator \% Remainder Operator **Example:** (Arithmetic Operator) class ArithmeticOperator { public static void main(String\[\] args) { double number1 = 12.5, number2 = 3.5, result; // Using addition operator result = number1 + number2; System.out.println(\"number1 + number2 = \" + result); // Using subtraction operator result = number1 - number2; System.out.println(\"number1 - number2 = \" + result); // Using multiplication operator result = number1 \* number2; System.out.println(\"number1 \* number2 = \" + result); // Using division operator result = number1 / number2; System.out.println(\"number1 / number2 = \" + result); // Using remainder operator result = number1 % number2; System.out.println(\"number1 % number2 = \" + result); } } **Output:** number1 + number2 = 16.0 number1 - number2 = 9.0 number1 \* number2 = 43.75 number1 / number2 = 3.5714285714285716 number1 % number2 = 2.0 In the above example, all operands used are variables. However, it\'s not necessary at all. Operands used in arithmetic operators can be literals as well. For example, result = number1 + 5.2; result = 2.3 + 4.5; number2 = number1 -2.9; The + operator can also be used to concatenate two or more strings. **Example:** Arithmetic Operator to Add String class ArithmeticOperator { public static void main(String\[\] args) { String start, middle, end, result; start = \"Talk is cheap. \"; middle = \"Show me the code. \"; end = \"- Linus Torvalds\"; result = start + middle + end; System.out.println(result); } } **Output:** Talk is cheap. Show me the code. - Linus Torvalds **Assignment Operator** Assignment operators are used in Java to assign values to variables. For example, int age; age = 5; The assignment operator assigns the value on its right to the variable on its left. Here, 5 is assigned to the variable age using = operator. There are other assignment operators too. However, to keep things simple, we will learn other assignment operators later in this module. **Example:** Assignment Operator class AssignmentOperator { public static void main(String\[\] args) { int number1, number2; // Assigning 5 to number1 number1 = 5; System.out.println(number1); // Assigning value of variable number2 to number1 number2 = number1; System.out.println(number2); } } **Output:** 5 5 The addition assignment operator (+=) adds a value to a variable: class AssignmentOperator2 { public static void main(String\[\] args) { int x = 10; x += 5; System.out.println(x); } } **Output:** 15 **Comparison Operators** The comparison operators determine the relationship between the two operands. It checks if an operand is greater than, less than, equal to, not equal to and so on. Depending on the relationship, it is evaluated to either true or false. **Operator** **Description** **Example** -------------- -------------------------- ------------------------------ == equal to 5 == 3 is evaluated to false != not equal to 5 != 3 is evaluated to true \> greater than 5 \> 3 is evaluated to true \< less than 5 \< 3 is evaluated to false \>= greater than or equal to 5 \>= 5 is evaluated to true \