New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Start learning with our library of video tutorials taught by experts. Get started

Java Essential Training
Illustration by
Watching:

Understanding operators


From:

Java Essential Training

with David Gassner

Video: Understanding operators

Every programming language supports operators, characters or sets of characters that execute particular operation. Java remember is C-style language and it uses the same set of operators as most such languages. If you already know JavaScript or ActionScript you will find that the operators in Java are almost identical. Here are some of the types of operators I'll discuss in this video. Assignment operators let you set values. There is a Simple Assignment Operator and then there were more Complex Assignment Operators that let you assignment and math in a single statement.
Expand all | Collapse all
  1. 10m 8s
    1. Welcome
      1m 3s
    2. Is this course for you?
      5m 35s
    3. Using the exercise files
      3m 30s
  2. 31m 24s
    1. The history of Java
      5m 19s
    2. Java compilation and syntax
      8m 54s
    3. Understanding the principles of Java
      8m 28s
    4. Choosing a development environment
      8m 43s
  3. 19m 5s
    1. Installing Java on Windows
      6m 42s
    2. Installing Eclipse on Windows
      3m 19s
    3. Exploring Java on Mac OS X Leopard and Snow Leopard
      2m 27s
    4. Installing Java on Mac OS X Lion
      3m 27s
    5. Installing Eclipse on Mac OS X
      3m 10s
  4. 46m 10s
    1. Creating a Hello World application
      11m 7s
    2. Exploring the Eclipse IDE
      8m 55s
    3. Compiling and running from the command line
      8m 2s
    4. Passing arguments to the application
      8m 17s
    5. Using the Java API documentation
      4m 5s
    6. Memory management and garbage collection
      5m 44s
  5. 58m 57s
    1. Everything is an object
      5m 59s
    2. Declaring and initializing variables
      9m 15s
    3. Working with numbers
      8m 32s
    4. Converting numeric values
      6m 40s
    5. Understanding operators
      7m 58s
    6. Working with character values
      5m 14s
    7. Working with boolean values
      5m 13s
    8. Outputting primitive values as strings
      5m 33s
    9. Creating a simple calculator application
      4m 33s
  6. 53m 40s
    1. Writing conditional code
      5m 35s
    2. Using the switch statement
      8m 50s
    3. Repeating code blocks with loops
      7m 35s
    4. Creating reusable code with methods
      6m 31s
    5. Declaring methods with arguments
      5m 41s
    6. Overloading method names with different signatures
      5m 53s
    7. Passing arguments by reference or by value
      5m 35s
    8. Creating a more complex calculator application
      8m 0s
  7. 20m 30s
    1. Using the String class
      5m 44s
    2. Building strings with StringBuilder
      3m 34s
    3. Parsing string values
      3m 19s
    4. Working with date values
      7m 53s
  8. 20m 44s
    1. Understanding compile-time vs. runtime errors
      4m 5s
    2. Handling exceptions with try/catch
      4m 55s
    3. Throwing exceptions in methods
      2m 50s
    4. Using the debugger
      8m 54s
  9. 32m 22s
    1. Using simple arrays
      4m 47s
    2. Using two-dimensional arrays
      6m 17s
    3. Managing resizable arrays with ArrayList
      7m 14s
    4. Managing unordered data with HashMap
      6m 5s
    5. Looping through collections with iterators
      7m 59s
  10. 52m 2s
    1. Understanding encapsulation
      5m 59s
    2. Creating and instantiating custom classes
      8m 8s
    3. Organizing classes with packages
      6m 47s
    4. Creating and using instance methods
      6m 52s
    5. Storing data in instance variables
      6m 56s
    6. Using constructor methods
      5m 40s
    7. Managing instance data with getter and setter methods
      8m 26s
    8. Using class variables and Enum classes
      3m 14s
  11. 41m 15s
    1. Understanding inheritance and polymorphism
      9m 12s
    2. Extending custom classes
      9m 1s
    3. Overriding superclass methods
      3m 8s
    4. Casting subclass objects
      5m 3s
    5. Understanding interfaces and implementing classes
      4m 2s
    6. Creating your own interfaces
      4m 14s
    7. Using abstract classes and methods
      6m 35s
  12. 32m 17s
    1. Managing files with the core class library
      7m 46s
    2. Managing files with Apache Commons FileUtils
      7m 32s
    3. Reading a text file from a networked resource
      7m 52s
    4. Parsing an XML file with DOM
      9m 7s
  13. 17m 39s
    1. Creating your own JAR files
      4m 54s
    2. Understanding the classpath
      5m 2s
    3. Documenting code with Javadoc
      7m 43s
  14. 47s
    1. Goodbye
      47s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
Java Essential Training
7h 17m Beginner Dec 14, 2011

Viewers: in countries Watching now:

Join author David Gassner as he explores Java SE (Standard Edition), the language used to build mobile apps for Android devices, enterprise server applications, and more. This course demonstrates how to install both Java and the Eclipse IDE and dives into the particulars of programming. The course also explains the fundamentals of Java, from creating simple variables, assigning values, and declaring methods to working with strings, arrays, and subclasses; reading and writing to text files; and implementing object oriented programming concepts.

Topics include:
  • Understanding the history and principles of Java
  • Installing Eclipse and Java
  • Compiling and running from the command line
  • Managing memory and performing garbage collection
  • Declaring and initializing variables
  • Writing conditional code
  • Building and parsing strings
  • Debugging and exception handling
  • Using simple arrays
  • Creating custom classes
  • Working with encapsulation, inheritance, and polymorphism
  • Managing files
  • Documenting code with Javadocs
Subjects:
Developer Programming Languages
Software:
Android Java Eclipse
Author:
David Gassner

Understanding operators

Every programming language supports operators, characters or sets of characters that execute particular operation. Java remember is C-style language and it uses the same set of operators as most such languages. If you already know JavaScript or ActionScript you will find that the operators in Java are almost identical. Here are some of the types of operators I'll discuss in this video. Assignment operators let you set values. There is a Simple Assignment Operator and then there were more Complex Assignment Operators that let you assignment and math in a single statement.

There are equality and relational operators that let you compare values to each other. There are mathematical operators that let you execute common mathematical process, Conditional operators that let you define complex conditional processes, and the ternary operator which is a special operator I'll describe in a later video when I discuss conditional processing. The most common operator that you'll find yourself using is the Assignment operator. The single equals character is the assignment operator. You put the variable you're assigning to on the left and the value on the right.

You can assign a literal value or a value return from a method or a reference to a complex object. Regardless of what you're assigning the single equals operator always is used. The simple math operators are the same as in JavaScript and ActionScript, the plus operators is used for math. So if I start with the value of 10 and I increment it by 5 with the + operator I get a value of 15, the - character is the traditional minus operator, the asterisk is used for multiplication and the forward slash is division.

There is another single character operator worth knowing about the modulus or remainder operator. Java uses the % character for this. If you take a value of 10 and you take the modulus of 5 that returns a reminder of 0. So those are the five primary math operators. You can combine these math operators with assignment too. Once again starting with an initial value of 10, let's take look at how you can increment and decrement values. The ++; operator means add one, so adding 1 to 10 gives you 11, the - -; operator goes in the other direction decrementing by one and that would give you a result of 9.

Here is how you can combine math operators with assignment, += means take the current value of this variable and add whatever is on the right side. So intValue +=5; would be 15. intValue -=5; would be 5, *= 5; equals 50 and /= 5; would result an intValue having a value of 2. Be aware that when you use the /= you need to make sure that you're assigning a value that matches the data type of the original variable.

When you use the increment and decrement operators you can place them either before or after the variable name, the operational result will be a little bit different depending on the position of the operator. Once again starting with the value of 10, a Postfix operator looks like this intValue ++, when you place the ++ operator after the variable you're saying first evaluate the variable and then execute the mathematical operation, because I've wrapped this inside a print line command I'm going to be outputting a value and changing it's value, but you need to know that with this Postfix syntax the evaluation happens first and only after that does the math happen.

The result would be an output of 10, but then after the statement is complete the new value of the variable would be 11. If you move the ++ operator before the variable name that's called a Prefix or a Unary operation, this would mean do the math then evaluate the variable. And in this case the output and the new value would be the same. Java's relational operators, that is the operators as you used to compare values to each other look exactly as you would expect. You have >, <, >= and <= values.

There is also a special operator called instanceof it's all lower case and all one word. You use the isntanceof operator to determine whether a variable is a member of particular class. Here is an example I declare a variable with a data type of String and I set it to some value. Now, I want to test that variable and ask whether it's an instance of a particular class. Typically when you use the instanceof operator you refer to the class by its fully qualified strength, its package, and its class name.

The String class is a member of the java.lang package, so the complete evaluation of (s instanceof java.lang. String) means is s a String and if so then I would output the String that's in the middle of if clause. One very important thing to know about comparisons is that you can't use the traditional comparison or relational operators when you're working with Strings. Let's take a look at this code, there are two Strings named s1 and s2, they have identical values of "Hello"; and now I put in some conditional code, I ask the question if (s1 ==s2) then output ("They match"); and otherwise output ("No match!);.

In some languages such as JavaScript you would get a match because in those languages they're comparing the values of the Strings, but in Java a String is a complex object and with complex objects the double equal operator is comparing whether they're the same object, not whether they have the same value and so this evaluation would result in the output No match!. If you want to compare two Strings you instead need to use a special method or function of the String class. Here is the correct example, once again I'm declaring two Strings named s1 and s2, now I'm going to use the equals function or method of the String class and I'm asking whether the values of these two variables match, not whether there the same object and this time the output is They match! With primitive variables you can use that double equal operator and you'll be able to match the values to each other, but with complex objects like the String you frequently have to use a method of the class to determine whether the values match.

Speaking of equality, here is how you compare values when you're working with primitives. The equality operator is double equal sign. Be sure you're using double equals not single equals, if you use single equals you'll be assigning the value and not comparing it. The inequality operator is an exclamation mark and the equal sign. So this syntax is asking if this value is not equal to that. And finally you can also use the exclamation mark on it's own to reverse the value of a Boolean Expression. A Boolean Expression evaluates to either true or false, when you apply the exclamation mark before it that reverses the value.

If it's started as true it becomes false and if it started as false it becomes true. You'll hear some developers refer to the exclamation mark as the bang character B-A-N-G. And so if they were reading this code it would be if bang this then do something regardless of what you call it bang or the exclamation it reverses the logic, changing a Boolean value from true to false or vice versa. Here are some conditional operators that you can use in complex logical operators.

The double ampersand is Conditional AND. In this code the output would only happen if both this and that are true. You can also do a Conditional OR using the double pipe character, in this code the output is going to happen if either of those variables equates to true. I'll show you more about how to combine these conditional operators with various types of conditional expressions in later videos, but you should now have a good sense of the kinds of operators that are available in Java and how similar they are to other C-style languages.

There are currently no FAQs about Java Essential Training.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Java Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.