Start course
Overview
Difficulty
Intermediate
Duration
2h 7m
Students
24
Ratings
5/5
starstarstarstarstar
Description

This course explores the fundamentals of Java and puts them to use with some real-life examples looking at an average of three program and a mad libs project.

Learning Objectives

  • Learn how to print information out to the user, how to create and use variables, values, and constants, how these things have data types, and the differences and similarities among the data types
  • Learn about arithmetic, relational, and logical operators
  • Understand how to obtain input from the user of our programs

Intended Audience

  • Beginner coders or anyone new to Java
  • Experienced Java programmers who want to maintain their Java knowledge
  • Developers looking to upskill for a project or career change
  • College students and anyone else studying Java

Prerequisites

This is a beginner-level course and can be taken by anyone with an interest in learning about Java.

Transcript

In the last lecture, we solidified our understanding of data types by diving a little deeper into the two categories of data types: Primitive and Reference types. Knowing the difference between these two is very important in understanding what's going on in memory and often what is expected of you as the developer. A lot of that will make much more sense later on in the course. In this lecture, we will discuss one of the simplest forms of software engineering documentation by using comments. Documentation can cover a wide range of different types of media, but fundamentally documentation helps document what an application is supposed to do, what it is doing, and if there's any bugs in the code and a multitude of other qualitative and quantitative characteristics of the software application or system. Comments have simple syntax and go right into your code.

The two types that we will explore are single-line comments and multi-line comments. Let's create a new Java class to demonstrate comments. We'll call the class CommentFun. So, let's go over here and we will go to source, new, Java class, CommentFun. Here we go. And public static void main. I actually put a little comment at the end there too. So, that should give you another heads up that's what that is. So, comments again are ignored by the compiler. Now, what can I put in here? So, what are the different kinds of comments? We've got the multi-line comment right here. So, I can put say John Bough, Learning Some Java 101,  This is a multiline comment, and we'll say it's July 30, 2060. All right, little bit in the future.

So in here, inside main we'll put a println("Printing stuff"); //print stuff to console and then below we put //this doesn't print, //there are single, //these are single line comments. There we go. That's what I meant. Now, so here we have some very simple comments. Comments again are ignored by the compiler and therefore do not have to contain valid Java syntax. So, what good are they? Comments allow us to describe what is going on in code, leave reminders for future development, and ultimately provide a simple form of documentation. The first few lines inside /* and ending in */ right here comprises a multi-line comment. This style comment is actually older and it's sometimes called a C style comment due to coming from the C programming language. You can put multi-line comments anywhere in your code, and all you have to do is remember to use the delimiters, that is the symbols providing boundaries for the comment. So,  the /* starts a multi-line comment and the */ ends the multi-line comment.

The other type of comment is the single-line comment, sometimes called the Java style comment. These start with  // and are good for whatever the rest of the line is. They don't have delimiters at the beginning and the end like multi-line comments do. So right here, this is a single-line comment even though it's on the same line as executable code, since it starts here, this code is unaffected, and you can also put them on their own lines. I couldn't put code after this because then it would be part of the comment, as you can see. So before we move on, I have a short challenge for you. Using the same file CommentFun, I'd like you to write a multi-line comment inside the CommentFun class but above the main method. In that comment, I'd like you to say something like, main is the entry point to the application." So, pause the video and come back when you're done or if you need some help.

How did that go for you? Were you able to complete the challenge? Let's do it together. So again, inside the class but above the main method. Notice when I first do this, it comments out everything because I haven't delimited the end of it. But then when I hit 'Enter', the IntelliJ IDE and most IDE's will actually put the closing */, so that keeps it bound right here. So, main is the entry point to the application. There's our comment. Pretty awesome and it's simple, right? Comments, while they don't do anything as far as telling the computer to do something, are very important. They're often used to provide names, dates, and times, but even more importantly to provide explanations and clarifications of code segments. 

This is useful because someone else might have to work with your code later on and modify it or add to it. So, comments can give insight to what you were doing, especially if the code is complex. In addition to providing someone else with information about what you were doing with some code, they help you, yourself. If you leave code to work on other areas of a project or even a completely different project and I have to come back to the code that you were originally working on, comments are invaluable to help you remember what you were doing. In the next lecture, we will discuss the arithmetic operators available in Java. I'll see you there.

 

About the Author
Students
140
Courses
20
Learning Paths
3

John has a Ph.D. in Computer Science and is a professional software engineer and consultant, as well as a computer science university professor and department chair.

Covered Topics