Programming

Writing and Running Python Code Option 1 – PyCharm IDE

  • Open the PyCharm IDE:
    • Click on the “Applications” menu at the top left of the screen.
    • Hold the mouse over “Programming”.
    • Move the mouse into the menu on the right and click on “PyCharm”.
  • Open your cs106 folder (created above) as a “Project”:
    • In the welcome screen, choose “Open”;
    • Or in the menu (stacked horizontal bars in upper left of PyCharm window) choose “File”, then “Open…”, then choose your folder.
  • The files currently in your cs106 folder will be listed in the Project window. Double click on a file name to open the file in the PyCharm editor.
  • To create a new file:
    • Right click on your folder in the PyCharm Project window.
    • Select “New”, then click on “Python File”.
    • Enter the file name (the .py extension will be automatically added when creating a new Python file).
    • This new file will open in the PyCharm editor. Type your code here.
  • To run your code: click the green triangle in the top right of the PyCharm window. The output will display in the console window at the bottom of the window.
  • To stop a running program: click the red square in the top left of the console window.

Writing and Running Python Code Option 2 – Text Editor and Command Line

  • Use a text editor. Some text editors available on the Linux computers are: Sublime Text, Visual Studio Code, Idle, gedit, emacs, vi. Some of these are also IDEs.
  • Right click on a Python file in your file browser, select the “Open With Other Application” option, and then choose your favorite text editor. Write and save your code.
  • Open a terminal window. You can find the terminal window program in the menu at the top left of the computer desktop.
  • Use the change directory (cd) command to move from your home folder into your class folder.
  • Run your program using the python3 command followed by the program file name. For example if your program is my_prog.py:
    python3 my_prog.py
  • Some shortcuts in the Linux terminal:
    • Use the up arrow key to access a previous command. Keep pushing the up arrow to scroll through the list of previous commands. When you find the command you wish to run, hit the enter key.
    • Use the tab key to autocomplete a file name.

How to Write and Run a Java Program

  • Use Visual Studio Code (VSCode) as the text editor to write your Java code.
  • Build and run your program from a terminal window (command line prompt):
    • You can use the terminal built into VSCode or use the Terminal program on the Linux Workstation.
    • You must change to the folder (directory) where your files are located.
      • The VSCode terminal may open in the correct directory.
      • From the file browser, right click on the folder where your Java file(s) are located and choose “Open in Terminal”.
      • Or use the “cd” command to navigate to the directory.
      • The “pwd” command will print the working directory (your current folder).
    • Use the javac command to build your program. Follow the instructions given with the program or assignment. All files that are part of the program must be built.
    • Use the java command to run the class that contains the main method.
  • Eclipse and other IDEs are available on the Linux Workstations. You may use one of these IDEs if you are familiar with them, however this is not the recommended way to write and run Java programs for this class. In order to use some of the Java frameworks and tools for this class you may need to run your Java programs from a terminal.