You'll find as you program that it's difficult to tell certain characters from one another, so a good mono-spaced font meant for programming will help. Read the notes on Fonts and choose a font to download and install (instructions included).
For some reason, it's the default in Windows to not show file extensions. This is a huge pain for developers because application source and bytecode files have the same names, but different extensions. Hovering over a file will usually tell you the file type but many editors also use unrecognized extensions for their backups, and these might not have any meaningful information in the hovertext. Therefore, all developers turn on the file extensions so you can quickly differentiate between the different file types:
First, make sure you've created a directory/folder on your hard drive for this course (and you should have one for each of your other courses, also). DO NOT create this directory/folder in your Program Files/Java directory!!!
You will be using this directory to store class notes, programs you write in class, assignments, labs, and other files. Most students call the directory "prog10082" or "Java1".
After creating this folder, you need to add a "projects" sub-directory/sub-folder to the prog10082 directory. This is where each one of your Java projects/programs will go.
You might also wish to add a "notes" directory, "evaluations" directory for evaluations you get back, etc.
A compression utility allows you to bundle groups of files together and to unbundle groups of files. This is required for two reasons:
Any Zip/Rar utility will do. WinRAR, IZArc, and 7-Zip can be downloaded for free from the Internet. If you prefer, you can download 7-Zip from Sheridan College at Sheridan College AppsAnywhere. Just log in using your Sheridan credentials and follow any instructions. You'll see 7-Zip in the list of available applications.
That's all you need for this course. We'll be getting our Java install and our development environment in the next steps.
The Java API documentation is useful as you're learning about the different classes that make up the Java language. In many lessons we'll be looking at this documentation, so you should have it bookmarked. Your instructor or professor will let you know which version of Java you'll be using.
Using your preferred browser, go to the appropriate link below and bookmark it or add it to your "Favourites". Tip: in some browsers you can add frequently used bookmarks to one of the button bars at the top of your browser, or to the set of favourite links that appears when you open a new browser tab/window.
The next step is to download and install JavaSE.
Recall in the first lesson we talked about what the Java SE contains: The Java development environment, or JDK, which is needed by programmers to write and debug Java programs. It also contains the JRE, or Java Runtime Environment. The JRE contains the JVM (Java Virtual Machine) and other supporting files needed to run Java programs.
For this course, we will download and install the latest version of Java, but if you've already done some development with Java and have an older version, that's fine. However, if your current Java version is older than 11, I strongly recommend you get the latest version today. Note that if you have a version earlier than 15, you'll have to perform some extra setup steps. But otherwise, you won't be doing anything in this course that is significantly different between the Java versions mentioned above.
Java is updated regularly, so keep in mind that the version numbers or "Update" number you see in the examples below may not be the same. As long as you have the latest update, that's all that matters.
If you haven't already done so, create a folder somewhere on your hard drive for PROG10082. This is where you will store all your files for this course. Inside the PROG10082 directory, you should also create sub-directories for each session of the course. You will be writing a lot of programs in some classes and it's important to keep them separate from each other, and from the other files in your other courses.
Depending on the speed of the network and the number of connections, it make take some time for the file to download. Once you are able to open the file, the installation will begin.
The JDK is a collection of tools, utilities, and packages that allow you to write programs in the Java language. It does not come with a development environment, so we will be using Notepad++ as our editor. If you already have some experience with programming, you might want to play with IntelliJ. Instructions for both Notepad++ and IntelliJ are included in these notes.
Java is now installed on your system. Next, you need to set up some environment variables so that your editor knows where to find the Java compiler and interpreter.
This course uses Notepad++ as the main editor. It's very basic and easy to use and doesn't include code completion or templates, which will help you to learn the Java language. For those students who are more intermediate programmers (perhaps you've learned Java somewhere else and have used more complex IDEs already), I've also included instructions for IntelliJ IDEA from JetBrains. It's a more complex IDE that has some extra project management and debuggin features that students with some programming experience might find useful. You must install NotePad++, but installing and setting up IntelliJ is optional. You could even choose to come back later in the term when you're more comfortable and give it a try.
There are several choices for editors and IDEs (Integrated Development Environments) that you can use. For the first Java course in your program, we're going to use a very basic and simple-to use editor called Notepad++.
These instructions will take you through the installation and setup of Notepad++.
Notepad++ starts and the change log file is loaded. You can close this file, we don't need it for anything (it's only interesting to read if you've used Notepad++ before and want to know what's different in this newest version).
Some of you may wish to change the font size right away before you do anything else, so you can more easily read the Notepad++ screen. To edit your font size, go to the menu bar at the top and select Settings > Style Configurator. On the right side of the screen is a drop-down where you can change the font size. If you also decide to change the font name, make sure you stick with a mono-spaced or fixed-width font like Courier New. (Personally, I prefer Ubuntu Mono or Fira Code)
The last set of steps we need to complete today is to set up commands that will allow us to use Notepad++ to compile and execute Java programs we write. This isn't really mandatory, but it's very convenient, so we'll do it.
First, we need to install a special plugin in Notepad++ that allows us to run other programs from within Notepad++.
cd $(FULL_CURRENT_PATH) javac $(FILE_NAME)Make sure you add the line break between the two lines of code (press the ENTER key after typing the first line). The first command changes the directory to the current one where your source file has been saved. The second comman runs the Java compiler program (javac.exe) on your current source code file. This will compile your code and show you any syntax/compiliation errors. If you have no errors, it will create the bytecode file.
cd $(FULL_CURRENT_PATH) java $(NAME_PART)FOLLOW THE INSTRUCTIONS: this code is not the same as the code for the compile command!! The first line does the same thing as the first line of the previous script. It's probably not necessary most of the time, but if you compile a program, and then come back later to run it, your system directory might have changed, so it's a good idea to execute it anyway. The second line runs the interpreter program (java.exe) on the bytecode that was created from compiling the current file.
We now have two scripts that can comple and execute Java programs we write. However, to run these scripts, we'd have to come back to the Execute window each time. It's more convenient to add menu items and keyboard shortcuts to run these two scripts. Let's do this next.
Let's test everything out and see if it worked.
You should already have a new file open in Notepad++, but if not, just use the NEW icon in the button bar (it's the first button) or use the File > New menu items.
In your new, empty file, copy and paste the following code:
public class Testing { public static void main(String[] args) { System.out.println("Hello, World!"); } }
Use the SAVE option (File > Save or File > Save As, or you can use the SAVE button in the button bar (it's the third button)) to save your file as Testing.java
The file name is case-sensitive: the T must be upper-case and everything else must be lowercase. You must include the lowercase .java file extension.
DO NOT save your file in the Notepad++ directory, and DO NOT save it to your Desktop!!
Take the time to go and create a directory for this course and add a "projects" subdirectory to it, and then save your file there. You will be creating several files every lesson, and it's important to keep them organized so that you can easily find them at any time.
NOTE: Changing the console font If you find the font in the console area is too small, you can make it larger (and even change the actual font name/family. In the Notepad++ menu, select Plugins > NppExec > Change Console Font. The default font "System" has a limited size on some systems, so if you want a larger font size, just change to a different mono-spaced/fixed-width font such as Courier New, Lucida Console, Ubuntu Mono, or Fira Code. Then you can change to a larger size.
Now try your menu items:
Installing IntelliJ IDEA by JetBrains is optional. If you've never programmed before, you might want to skip this for now and wait until you're more comfortable. You'll be using an IDE such as IntelliJ or NetBeans in term 2, so there's no rush unless you want to try something more challenging. You can always come back later in the term and install it then if you feel like you want to give it a try.
IntelliJ is an IDE (Integrated Development Environment, rather than just a simple editor like Notepad++. It has many more features and tools that are common to more intermediate and advanced application development. This is a very popular IDE for students learning Java: it's project-based, yet also very simple to use compared to more professional IDEs such as NetBeans or Eclipse.
Follow the instructions to first download, and then install IntelliJ IDEA to your machine.
When you run IntelliJ for the first time, you'll be asked whether or not you want to import any settings from a previous installation. It's assumed you don't have a previous install, so just make sure "Do not import settings" is selected and click OK.
Next, you'll be asked to agree to the JetBrains privacy policy. This is standard. Scroll down to the bottom of the policy text (the ACCEPT button will remain disabled until you do so). Click the ACCEPT button once it has become enabled.
The next screen asks if you would like to share your usage stats with JetBrains (this is common for many companies where they want to track how/when users use their software). Personally, I never agree to these things, but it's really up to you. Click either button, depending on your preference.
Finally, IntelliJ IDEA starts up and you are asked to choose a default theme (you can change or customize this in the settings, later). Choose whether or not you want the darker theme or the lighter theme. You won't need to change any of the other options they're going to ask you about, so once you've made a choice, click "Skip Remaining and Set Defaults" on the bottom-left of the screen.
The splash screen appears while the program loads. When it disappears, you'll see the Welcome screen. This screen asks you what you'd like to do. We might as well start a new project!
You can create several different kinds of projects in IntelliJ. For this course, we'll primarily be creating simple Java projects. A Java project consists of one or more source code files that are then compiled into bytecode files. Bytecode files can then be run by any Java virtual machine.
After choosing to create a new project, you'll be asked what kind of project you want to create. Make sure Java is selected in the list on the left side of the screen.
To the right is the Project SDK field. This asks you to choose which Development Kit you want to use for your project. If it says "No SDK", you'll have to select the one you installed earlier. Click the NEW button.
A dialog opens asking you to choose the location of your SDK. You should see your C: drive listed there, so use the little tiny arrow on the left to expand it and browse to your Program Files / Java directory on your system.
In the Program Files / Java directory, you should see your JDK folder, e.g. jdk-10.0.2 but the numbers might be different for you. Select that directory and then click the OK button.
Now you're back in the New Project dialog box. Ignore the bottom part of the screen where it asks about libraries. Click the NEXT button.
The next screen asks what template you want to use. We won't be using templates at this time so just ignore this screen. Click NEXT.
The last screen asks you to name your project and choose a project location. Earlier today you created directories/folders for your courses, including a java1/projects folder (or you might have called it prog10082 instead of java1, it doesn't matter). This is where you should store all of your projects. A single project contains multiple files, so when you make a project in IntelliJ, it will create a new directory/folder to contain all those files (this is often called the project's root). The name of your project root is the same as the name of your project.
Next, we create a name for our project. The project name is important, since that's how you'll be able to tell one project from another. Project names should be "self-documenting" (you should be able to accurately guess what the project is for just by reading the project name). In the example below, I called the project "FirstJavaProject". Enter an appropriate project name for your new project.
Next, we choose a location for our project files. Each project you create goes inside its own directory/folder. For example, if you create a project called "MyFirstProject", and you store it in your java1/projects folder, your project files should be located in the directory java1/projects/MyFirstProject directory.
The "Project Location:" field determines where your project and its files will be stored. By default, your Project Location may be listed as some other directory, but wee need to make sure we set it to our projects directory we created earlier. Also, since the project's files should go inside a FirstJavaProject directory, we'll need to create that directory, too.
Beside the "Project Location:" field, there's a small button with 3 dots (ellipsis) on it. Click that button to open the file browser.
Now you have a file browser dialog open. Browse to your prog10082/projects directory and select it.
Then click the "New Folder" button in the button bar at the top.
Now a smaller dialog opens, asking you to enter a new folder name. For this example, I typed "FirstJavaProject" since that's the name I chose for this project. After you enter a folder name, click the OK button.
Now your file browser shows the new project directory inside your /projects directory. Make sure it's selected and then click OK.
You should now be back at the original new project dialog, and the Project Location field has been updated to your newly created project directory.
Each project you are working on in IntelliJ IDEA runs in its own instance of IntelliJ. In otherwords, if you have two projects open at the same time, you'll have two IntelliJ IDEA windows: one for each project (the program is running twice at the same time).
It's up to you whether or not you want to open your new project in the current window, or a new one. If you want to see both projects at the same time, then choose "New Window". If you only want the new project to be open, then choose "This Window". You will be prompted to save any unsaved work before the old project is replaced with the new one. (Don't worry, your old project is still on your computer, it's just not open anymore. You can always open it again later.)
Once your new project is created and loaded, you'll see the Tip screen. You can close it, view the next tip, choose not to see tips on startup, etc.
As you're learning to work in IntelliJ, you might wish to change some of your preferences such as colours/fonts, markers, etc. To find the settings, go to the File menu and choose Settings.
By default there should be a vertical line in your editor that shows you where column 80 is. It is standard in Java programming to make sure that lines of code do not go beyond column 80, so we need to make sure there's a visual guide there to let us know when we should press the RETURN key on a long line of code.
First, we need to make sure that guide is in fact at column 80 (often the default is set to something else).
In the settings, go to Editor > Code Style (just click on Code Style, don't expand it).
Change the following settings:
If you have trouble seeing the visual guide at column 80, you can change its colour by going to Editor > Colour Scheme > General. In the list in the top half of the screen, expand Editor > Guides and select "Visual Guides". To the right, you can then click the text field beside the "Foreground" check box to change the colour of the right margin marker. Unfortunately you can't change the thickness like you can in some other editors.
To change your default theme, go to Editor > Colour Scheme. Under Colour Scheme you'll also see several screens that allow you to customize the theme.
To change or enlarge the font, go to Editor > Font.