Introduction to IntelliJ and Simple Data Definitions (2024)

8.13

contents← prevupnext →

Recitation 1: Introduction to IntelliJ and Simple Data Definitions🔗

Goals: The goals of this lab are to get familiar with our workenvironment: the IntelliJ IDE, the handin-server submission process, the basicsof running a program in Java, and program testing framework.

The second part of the lab will focus on practicing data definitions and examples in Java.

Related files:
tester.jar javalib.jar Shapes.java

1Gradescope Accounts🔗

You will useGradescope to submit yourhomework. You should have received an invitation at the beginning ofthe semester to join; accept and join our class, you should be able tosee the first assignment listed there.

2Introduction🔗

We start with designing data - designing classes of data that areconnected to each other in a systematic way, showing that theDesign recipe for Data Definitions can be used virually withoutchange in a completely different language than we have used in the first part.

The programs we provide give you examples of the progressivelymore complex data (class) definitions, and illustratethe design of methods for these class hierarchies.

3IntelliJ IDE🔗

IntelliJ is an integrated (program)development environment used by many professional Java programmers (as well as programmersusing other programming languages) developed by JetBrains. It’s one of the best out there, and theyhave designed it to maximize developer productivity by providing robust features thatsupport various programming languages and frameworks, especially Java and Kotlin.

The environment provides an editor, allows you to organize your work into severalfiles that together comprise a project, and has a compiler so you can run your programs.

Several projects can exist in one workspace. You can probably keep all the work until theend of the semester in one workspace, with one project for each programming problemor a recitation problem.

There are several steps in getting started:

  • Learn to install IntelliJ Ultimate linked to your SHU account.

  • Learn to set up your workspace and launch an IntelliJ project.

  • Learn to manage your files and save your work.

  • Learn how to edit your Java programs and run them, using our tester library.

Learn to set up your workspace.🔗
  • Start by identifying where you are going to store all of your files for the course.Navigate to this directory. If you do not have one, create a folder to store all of yourfiles. Anywhere to save your files is fine as long as the location path is remembered.A generic place would be somewhere such as your Desktop or your Documents directory.That would look something like this default on Windows.

    C:\Users\(YOURUSERNAME)\Documents\Intro2ProgramDesign

  • Create a new workspace folder in your directory where you will keep allyour Java files. A directory example would look like the following.

    C:\Users\(YOURUSERNAME)\Documents\Intro2ProgramDesign\IntelliJWorkSpace

    Note that C: is the drive that Windows boots to by default, and your drive may be identifiedby something else if your system is configured differently. The (YOURUSERNAME) would be yourunique username that you are signed in as. Anywhere to save your workspace is fine as long asyou can remember the location path.

  • Next, set up another folder inside of this same directory where you will keepall your Java library files. A continued example of this corresponding to the last examplewould look something like

    C:\Users\(YOURUSERNAME)\Documents\Intro2ProgramDesign\IntelliJJars

    We will refer to these two folders as IntelliJWorkspace and IntelliJJars.Make sure the two folders IntelliJWorkspace and IntelliJJars are subfoldersof the same folder.

  • Apply for your free student version of IntelliJ Ultimate

  • After downloading the IntelliJ Ultimate installation application, begin the IntelliJ installation.

    Check the box that asks if you want to update the PATH Variable (Restart Needed)for bin files to be able to be accessible from the kernel and click OK.

IntelliJ Setup🔗
  • Right click the following two libraries and select "Save link as..." Save them to yourIntelliJJars folder.

    The libraries you will need are:

    Related files:
    tester.jar javalib.jar

  • You will also need to download the latest JRE

  • Select Windows > x64 installer Download and install this.

  • Adjust the IntelliJ settings.

    The Code style section explains how to configure IntelliJ to only use spaces instead of tabs,and how to set the editor to show you the line numbers for all lines in the code. Do that now.

The Project Template🔗
  • Open IntelliJ and navigate to the directory when you are storing all your files.

    If you have a fresh installation ofIntelliJ click New Project in the upper right corner. If you had IntelliJ previously, in the File menu,select New then Java Project. In the window that appears, be sure to set this project’s location to beinside IntelliJWorkspace folder that we have created previously. Name the project 2123-template. The Languageto be selected is Java. Select JDK, make sure you select the version of OpenJDK you installed above. Finally, select Create, as the otherdefaults should be fine. We will re-use this template for many future projects

  • Make the libraries available to the project template.

    Go to the File menu and select Project Structure.Under the Project Settings section, click Project, and ensure that the SDK is that version of OpenJDK you installed.Under Language Level, choose 11 - local variable syntax for lambda parameters.Now, navigate to Libraries.To the right of the Project Settings column, click on the plus sign ’+’ for New Project Libraryand select Java. Navigate to the directory where the JAR files javalib.jar & tester.jarare located on your local file system. Select the JAR files that you want to add and click OK.Click Apply and then OK to close the dialog.This will make these JAR files known to IntelliJ, allowing you to use theclasses and methods defined in these libraries!

  • Template Run Configuration

    Go to the Run menu and select Edit Configurations.Click Add new run configuration, and select Application. Change the name to Template and click Store as project file. Under Build and run, click the drop-down menu and make sure that Java version from the OpenJDK you downloaded is selected. In the next box over, write tester.Main. (If this causes you to need to re-enter your configuration name, do so.) Click Apply and then OK to close the dialog.

    Now, you can select File then choose New Project Setup then Save Project as Template.We are now finished with this one.

3.1The First Project🔗
  • We are now going to set up your first real project. Now that youhave all that prepared, this is what it will look like for you tocode a Java file for the forseeable future.

    Once again, in the File menu, select New thenJava Project. In the window that appears, you should now beable to scroll down to the bottom and select 2123-template.Name the project Shapes.

  • Add the Shapes.java file to your project.

    Related files:
    Shapes.java

    • Download the file Shapes.java to a temporary directory or the desktop.

    • Place that Shapes.java file in the blue src directory on the right-hand side, the project pane. You can drag and drop it into src within IntelliJ, or you can use File Explorer to move it under IntelliJWorkspace Shapes src. It does not matter. IntelliJjust has to be able to read a Shapes.java file inside of your project file.

    • After completion of these steps, Shapes.java should be included inside of your Recitation1 > src.

  • View the file Shapes.java.

    • In the Projects pane, under Shapes, there should be a blue src, and if you click on the dropdown arrow, it will reveal Shapes.java.

    • Double click on Shapes.java. The file should open in the main pane of IntelliJ.

      You can now edit it in the usual way. Notice that the Outline pane lists all classesdefined in this file as well as all fields and methods. It is almost as if someone wasbuilding our templates for us.

Ready to run🔗
  • In the Run menu tab select Edit Configurations....

  • In the left column, beneath Application, you should see Template, the name of the configuration we began to set up.

  • Click on the Program Arguments entry box. In the Program Arguments text fieldenter ExamplesShapes which will be the name of your examples class for testing.

    Later, when you define your own program, you will use the class name of your Examples...class instead of ExamplesShapes.

  • At the bottom of the Run/Debug Configurations window select Apply then OK.

    To run this project, make sure Shapes.java is shownin the main pane (and is currently selected), then hit the green circle with the white triangleon the top left side of the main menu.

Interface? Implements?🔗

As we fondly remember from CS1114, one of our favorite types of data is union data: enumerations,itemizations, etc. You’ll learn more about this in lecture on Wednesday, but to define union datain Java, we define that union as an interface and say each branch of the dataimplements the interface. Read the code in your shapes file: you’ll notice the IShape interfaceis defined at the top, and that each class implements it. In the examples section, the examplesare given the type of the interface, and are created with the constructor of the specific class.Follow suit when defining your own examples.

Making examples🔗

Add examples of shapes found in the following image (ignore the colors):

Introduction to IntelliJ and Simple Data Definitions (1)

Simple Data Definitions🔗

Problem 1

Here is a data definition in DrRacket:

;;torepresentaperson
;;APersonis(make-personStringNumberString)
(define-structperson[nameagegender])
(definetim(make-person"Tim"23"Male"))
(definekate(make-person"Kate"22"Female"))
(definerebecca(make-person"Rebecca"31"Non-binary"))

Draw the class diagram that represents this data.

Define the class Person that implements this datadefinition and the class ExamplesPerson that contains theexamples defined above. You should do this in a new Person.java file.Right click the default package under Lab1 and select New > Class. Name itPerson.

Run your program to make sure it works.

Data Definitions with Containment🔗

Problem 2

Modify your data definitions so that for each person we alsorecord the person’s address. For each person’s address we onlyrecord the city and the state; each of these should be its own field.Create an Address class to contain the address information, thenmodify the Person data definition to include an Address.

  • Draw the class diagram for this data definition

  • Define Java classes that represent this data definition.

  • Tim lives in Boston, MA, Kate lives in Warwick, RI,and Rebecca lives in Nashua, NH.

    Make examples of these data and add two more people.

Data Definitions for Unions of Data🔗

Problem 3

A deli menu includes soups, salads, and sandwiches.Every item has a name and a price (in cents - so we have whole numbers only).

For each soup and salad we note whether it is vegetarian or not.

Salads also specify the name of any dressing being used.

For a sandwich we note the kind of bread, and two fillings (e.g peanut butter and jelly;or ham and cheese). Assume that every sandwich will have two fillings, and ignore extras (mayo,mustard, tomatoes, lettuce, etc.)

Define classes to represent each of these kinds of menu items. Think carefully about what typeeach field of each class should be. Do you need to define any interfaces?Construct at least two examples each of soups, salads, and sandwiches.

Self-Referential Data🔗

The HtDP book includes the data definition for Ancestor Trees:

;;AnAncestorTree(AT)isoneof
;;--'unknown
;;--(make-treePersonATAT)
;;APersonisdefinedasabove

Convert this data definition into Java classes and interfaces. What options doyou have for how to translate this into Java? Make examples of ancestor treesthat in at least one branch cover at least three generations.

contents← prevupnext →

Introduction to IntelliJ and Simple Data Definitions (2024)

FAQs

Is IntelliJ good for beginners? ›

Ultimately, it's up to you which IDE you prefer- they both have pros and cons. IntelliJ is probably the best choice for beginners, but Eclipse may be better if you need more power and flexibility. Both IDEs are popular Java development environments, and they have a lot of similarities but also some key differences.

How do I get definition in IntelliJ? ›

Place the caret at a symbol in the editor and press Ctrl Shift 0I (or click View | Quick Definition in the main menu).

How to use IntelliJ for beginners? ›

First steps
  1. Install IntelliJ IDEA. Install and run IntelliJ IDEA for the first time.
  2. Create your first Java application. Create, run, and package a simple Java application in IntelliJ IDEA.
  3. Learn IDE features. ...
  4. Learn keyboard shortcuts. ...
  5. Install plugins. ...
  6. Configure your project. ...
  7. Write the source code. ...
  8. Get support and assistance.

How to speed up IntelliJ indexing? ›

Exclude files and folders

Marking dynamically generated files as excluded can speed up the indexing and overall IDE performance. For example, it's recommended that you exclude compilation output folders.

Is IntelliJ no longer free? ›

Community Edition is free and open-source, licensed under Apache 2.0. It provides all the basic features for JVM and Android development. IntelliJ IDEA Ultimate is commercial, distributed with a 30-day trial period.

Is IntelliJ worth paying for? ›

I like using the tools for any personal projects, and it's worth the price for the individual use subscription.

How to do coding in IntelliJ? ›

Right-click the main toolbar and select Customize Toolbar. From the available options, select Main Toolbar | Right | Code With Me. Open the Code With Me Call Actions node and select the action to which you want to make changes. Click OK to save the changes.

How do you write step definition in IntelliJ? ›

IntelliJ IDEA detects and highlights the steps where definitions are missing and suggests a quick-fix to generate them. Place the caret at the step without a definition, press Alt Enter , and select Create step definition or Create all step definitions. Alternatively, hover over the step and use the links in the popup.

How to build using IntelliJ? ›

Build a project with IntelliJ IDEA

Go to Build | Build Project. Alternatively, press Ctrl F9 to build your project. IntelliJ IDEA compiles all the classes inside your build target and places them inside the output directory. You can check the result in the Build tool window.

How do I write the first code in IntelliJ? ›

New Java project with onboarding tips
  1. Launch IntelliJ IDEA. If the Welcome screen opens, click New Project. ...
  2. From the list on the left, select New Project. ...
  3. Select the Add sample code checkbox and enable Generate code with onboarding tips.
  4. Click Create.
Aug 9, 2024

How do I start typing in IntelliJ? ›

Start typing. By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl Shift Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl Shift Space once again.

How to use IntelliJ effectively? ›

IntelliJ IDEA has many developer tools integrated and working out of the box. If a tool you need is not integrated, but you'd like to use it via a shortcut, go to Settings | Tools | External Tools, and configure how to run this tool. Then you'll be able to run this tool via the Tools | External Tools main menu.

Why is IntelliJ being so slow? ›

IntelliJ requires quite a lot of memory. If you don't give it enough memory it will become slow.

How do I navigate faster in IntelliJ? ›

To navigate backwards, press Ctrl Alt 0← . To navigate forward, press Ctrl Alt 0→ . To navigate to the last edited location, press Ctrl Shift Backspace . To find the current caret location in the editor, press Ctrl+M .

What does indexing mean in IntelliJ? ›

Indexing examines the code of your project to create a virtual map of classes, methods, objects, and other code elements that make up your application. This is necessary to provide the coding assistance functionality, search, and navigation instantaneously. After indexing, the IDE is aware of your code.

Should I use IntelliJ or Visual Studio? ›

IntelliJ IDEA has several benefits over vs code when it comes to Java applications, including in-built Java compilers, Maven lifecycle support, Lombok preprocessing, and sonar integration. While vs code is largely generic, IntelliJ IDEA has focused primarily on Java …

Which is easier IntelliJ or Eclipse? ›

IntelliJ is much easier to use as compared to Eclipse. The learning curve is far faster in IntelliJ, which makes developing easier and more natural. Code completion, Dropdowns, quick view, project wizards, etc. are all possible in both Eclipse and IntelliJ, but the user experience in IntelliJ is much more satisfying.

What is IntelliJ best for? ›

Some IDEs stand out, in particular Intellij IDEA, which is an IDE primarily used for Java development, but also supports other languages, including Kotlin, Groovy, Scala, JavaScript, TypeScript and more.

Why do people use IntelliJ? ›

IntelliJ IDEA comes with one of the most powerful code editors in the industry. It understands the ins and outs of your code thanks to initial indexing, which allows it to detect errors on the fly, suggest code completion options with precise context awareness, perform safe refactoring, and much more.

Top Articles
The Paducah Sun from Paducah, Kentucky
Wishing You’ll Be Mine - LadyShadowDancer
Northern Counties Soccer Association Nj
NYT Mini Crossword today: puzzle answers for Tuesday, September 17 | Digital Trends
Txtvrfy Sheridan Wy
Osrs But Damage
Deshret's Spirit
Geometry Escape Challenge A Answer Key
OnTrigger Enter, Exit ...
Daniela Antury Telegram
Delectable Birthday Dyes
Helloid Worthington Login
Calmspirits Clapper
Leader Times Obituaries Liberal Ks
St Maries Idaho Craigslist
Plan Z - Nazi Shipbuilding Plans
Healthier Homes | Coronavirus Protocol | Stanley Steemer - Stanley Steemer | The Steem Team
Tyrone Unblocked Games Bitlife
Rs3 Ushabti
Silky Jet Water Flosser
Craigslist Wilkes Barre Pa Pets
Used Patio Furniture - Craigslist
Victory for Belron® company Carglass® Germany and ATU as European Court of Justice defends a fair and level playing field in the automotive aftermarket
Cognitive Science Cornell
Malluvilla In Malayalam Movies Download
Lcsc Skyward
R/Mp5
Stubhub Elton John Dodger Stadium
Plasma Donation Racine Wi
DIY Building Plans for a Picnic Table
Pfcu Chestnut Street
Workboy Kennel
24 slang words teens and Gen Zers are using in 2020, and what they really mean
Scioto Post News
Cheap Motorcycles Craigslist
Save on Games, Flamingo, Toys Games & Novelties
T&J Agnes Theaters
Metro 72 Hour Extension 2022
Delaware judge sets Twitter, Elon Musk trial for October
Mohave County Jobs Craigslist
Craigslist Ludington Michigan
The Banshees Of Inisherin Showtimes Near Reading Cinemas Town Square
Dogs Craiglist
More News, Rumors and Opinions Tuesday PM 7-9-2024 — Dinar Recaps
Gfs Ordering Online
Who Is Responsible for Writing Obituaries After Death? | Pottstown Funeral Home & Crematory
Dwc Qme Database
1Tamilmv.kids
Joe Bartosik Ms
Otter Bustr
Ubg98.Github.io Unblocked
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 5875

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.