Introduction to Java and Eclipse 1 / 22
Total Page:16
File Type:pdf, Size:1020Kb
Introduction to Java and Eclipse 1 / 22 Introduction to Java and Eclipse Mustafa Haddara Department of Computing and Software McMaster University Week 1: Sept 12 - 16 Mustafa Haddara Introduction to Java and Eclipse 1 / 22 Introduction to Java and Eclipse 2 / 22 Outline Outline 1 Getting Started Getting Java Integrated Development Environments (IDEs) Setting Up IntelliJ Idea Downloading IntelliJ Idea Installing IntelliJ Idea Setting Up Eclipse Downloading Eclipse Installing Eclipse 2 Hello, World! 3 Examining a Program 4 Further Reading Mustafa Haddara Introduction to Java and Eclipse 2 / 22 Introduction to Java and Eclipse 3 / 22 Getting Started Getting Java Getting Java 1 Visit http://www.oracle.com/technetwork/java/ javase/downloads/index.html 2 Download and install the correct version of Java Platform (JDK) 8 for your system. Any version of Java 8 (ex 8u20, 8u72, 8u102, etc.) is acceptable for this course. Mustafa Haddara Introduction to Java and Eclipse 3 / 22 Introduction to Java and Eclipse 4 / 22 Getting Started Integrated Development Environments (IDEs) What is an IDE? What is an IDE? Mustafa Haddara Introduction to Java and Eclipse 4 / 22 Introduction to Java and Eclipse 5 / 22 Getting Started Integrated Development Environments (IDEs) What is an IDE? IDE = Integrated Development Environment Software application Usually includes: source code editor build automation tools debugger Mustafa Haddara Introduction to Java and Eclipse 5 / 22 Introduction to Java and Eclipse 6 / 22 Getting Started Integrated Development Environments (IDEs) Java IDEs Some popular Java IDEs: 1 Eclipse 2 IntelliJ 3 NetBeans 4 BlueJ Mustafa Haddara Introduction to Java and Eclipse 6 / 22 Introduction to Java and Eclipse 7 / 22 Getting Started Setting Up IntelliJ Idea Downloading IntelliJ Idea 1 Visit https://www.jetbrains.com/idea IntelliJ 16 comes in Community (ie. Free) and Ultimate (paid) versions...but as students you can get the Ultimate version for free! Visit https://www.jetbrains.com/student and sign up with your McMaster email address; you'll be e-mailed instructions for the Ultimate version. 2 Download the correct version of IntelliJ Idea 16 for your system. 3 For this course we'll be using Java 8, which IntelliJ Idea 16 supports by default. Mustafa Haddara Introduction to Java and Eclipse 7 / 22 Introduction to Java and Eclipse 8 / 22 Getting Started Setting Up IntelliJ Idea Installing IntelliJ Idea on a Mac Mac 1 Find .dmg le (probably in your Downloads folder) 2 Double-click on it to mount it. A window will open showing an application named IntelliJ Idea 3 Drag IntelliJ Idea into Applications folder 4 Drag it to your dock to make it easier to launch Mustafa Haddara Introduction to Java and Eclipse 8 / 22 Introduction to Java and Eclipse 9 / 22 Getting Started Setting Up IntelliJ Idea Installing IntelliJ Idea on a Linux Machine 1 Find .tar.gz le (probably in your Downloads folder) 2 Extract the idea-IC or idea-IU folder into your Applications folder 3 Open a terminal and type: cd /Applications/<name of intellij folder>/bin. Hit enter. 4 Type ./ideaIC.sh (or ./ideaIU.sh if you downloaded the ultimate edition). 5 After completing the setup, on the Welcome Screen click on Congure and then on Create Desktop Entry. This will let you start IntelliJ without typing in the terminal as we did earlier. Mustafa Haddara Introduction to Java and Eclipse 9 / 22 Introduction to Java and Eclipse 10 / 22 Getting Started Setting Up IntelliJ Idea Installing IntelliJ Idea on a PC Windows 1 Run the .exe le you downloaded. Follow all of the instructions. Mustafa Haddara Introduction to Java and Eclipse 10 / 22 Introduction to Java and Eclipse 11 / 22 Getting Started Setting Up IntelliJ Idea Creating a Project in IntelliJ Idea 1 Select Create New Project. Select Java and Java EE. 2 Click on the New.. button next to Project SDK eld at the top and select JDK to tell IntelliJ about an SDK. You will see a window pop up showing your le system. IntelliJ will try to guess where Java is installed. If it does not nd the Java 8 that you just installed, navigate to the correct folder: Windows: C:/Program Files/Java/jdk1.8.0_102 OS X: /Library/Java/JavaVirtualMachines/ jdk1.8.0_102.jdk/Contents/Home Linux: /usr/jdk/jdk1.8.0_102/ 3 Click Next. Choose a project name and location on your hard drive. 4 Click Finish. Mustafa Haddara Introduction to Java and Eclipse 11 / 22 Introduction to Java and Eclipse 12 / 22 Getting Started Setting Up Eclipse Downloading Eclipse 1 Visit http://www.eclipse.org/downloads/packages/ 2 Download the correct version of Eclipse IDE for Java Developers for your system. 3 For this course we'll be using Java 8, which Eclipse Neon supports by default. Mustafa Haddara Introduction to Java and Eclipse 12 / 22 Introduction to Java and Eclipse 13 / 22 Getting Started Setting Up Eclipse Installing Eclipse on a Mac Mac 1 Find .tar.gz le (probably in your Downloads folder) 2 Drag it to the Desktop 3 Double-click on it and nd a folder named eclipse 4 Drag eclipse folder into Applications folder 5 Inside eclipse folder nd application named Eclipse 6 Drag it to your dock to make it easier to launch Mustafa Haddara Introduction to Java and Eclipse 13 / 22 Introduction to Java and Eclipse 14 / 22 Getting Started Setting Up Eclipse Installing Eclipse on a Linux Machine Ubuntu Find and install Eclipse from the Ubuntu Software Center. Other Distributions Instructions should mirror Mac instructions. Mustafa Haddara Introduction to Java and Eclipse 14 / 22 Introduction to Java and Eclipse 15 / 22 Getting Started Setting Up Eclipse Installing Eclipse on a PC Windows 1 Find .zip le (probably in your Downloads folder) 2 Right-click on it 3 Select Extract All. and extract to C: (or whatever your root drive is) 4 After it is extracted, drag eclipse.exe to your Start menu to make it easier to launch Mustafa Haddara Introduction to Java and Eclipse 15 / 22 Introduction to Java and Eclipse 16 / 22 Getting Started Setting Up Eclipse Setting Java version to 8 (PC) 1 Once you have downloaded and installed the JDK, that eclipse is actually using this version and not an old one. 2 Navigate to window -> preferences -> Java 3 At this point it's possible that there is only one JRE (JDK) installed, which means you're ne 4 If there are two or more, you need to select Java 8 as the correct one. Mustafa Haddara Introduction to Java and Eclipse 16 / 22 Introduction to Java and Eclipse 17 / 22 Getting Started Setting Up Eclipse Creating a Project in Eclipse 1 Launch Eclipse. 2 Specify a Workspace (a directory where you would like Eclipse to save your work) and press OK. 3 Create a new Java Project: File ! New ! Java Project Project name: My First Project Click Finish You may have to click the small x to leave the Welcome screen. Mustafa Haddara Introduction to Java and Eclipse 17 / 22 Introduction to Java and Eclipse 18 / 22 Hello, World! Hello, World!I 1 Create a new Java Class: File ! New ! Java Class Name: HelloWorld Click Finish You should see the following: public class HelloWorld { } Mustafa Haddara Introduction to Java and Eclipse 18 / 22 Introduction to Java and Eclipse 19 / 22 Hello, World! Hello, World! II 2 Write Your Program: public class HelloWorld { public static void main(String[] args) { System.out. println("Hello , World"); } } Mustafa Haddara Introduction to Java and Eclipse 19 / 22 Introduction to Java and Eclipse 20 / 22 Hello, World! Hello, World! III 3 Run Your Program: Click the Run button (IntelliJ: Green triangle to the left of your code; Eclipse: a round green play button at the top). The Console at the bottom of the windows should display Hello, World!. Mustafa Haddara Introduction to Java and Eclipse 20 / 22 Introduction to Java and Eclipse 21 / 22 Examining a Program Examining a Program Source: http://introcs.cs.princeton.edu/java/11cheatsheet Mustafa Haddara Introduction to Java and Eclipse 21 / 22 Introduction to Java and Eclipse 22 / 22 Further Reading Further Reading Find a Java tutorial you like and go through it step-by-step. If you've programmed in Java before, take an hour to refresh. If you would like some practice, check out these programming practice websites: CoderByte: https://coderbyte.com HackerRank: https://www.hackerrank.com Mustafa Haddara Introduction to Java and Eclipse 22 / 22.