Skip to content

Tag 02 Programmierung Day 2

CodingRobIT edited this page Mar 14, 2023 · 1 revision

Switch

A Java switch case is like a multi-nested if statement. It's a jump instruction based on fixed values.

switch(i) {
   // after the : comes what has to happen 
   case 1:
       System.out.println("a");
       break;
   case 2:
       System.out.println("c");
       break;
   //and so on.. 
   //otherwise this happens
   default:
       System.out.println("z");
       break;
}

Example: Write a code that tells you the menu of cafeteria based on the weekday.

int weekday = 1;
switch (weekday) {
  case 1:
  System.out.println ("Today we have ravioli.");
  break;
  case 2:
  System.out.println ("Today we have spinach soup");
  break;
  //and so on
  default:
  System.out.println ("Unfortunately, the cafeteria is closed today and there is nothing to eat.");
  break;
}

Shell basics

The servers on which software developers work mostly do not have a graphical user interface. Most software runs on a server and most servers run Linux. As a developer, you must therefore be able to operate Linux in the terminal.

Unix Syntax

<command> -- <option> <parameter>

commands

  • ls
  • cd path/to/something
  • cd ...
  • touchcreates an empty file
  • echo "Hello" >> text.txt creates a new file text.txt with the entry "Hello"
  • mkdir my-folder
  • rm -rf my-folder
  • pwd print working directory, it's the directory in which the user is currently working in
  • mv /home/user/text.txt /destination/ moves text.txt from source folder to a destination folder
  • mv text.txt text2.txt renames text.txt into test2.txt

Script

A script is a file containing a sequence of commands that you can run to save you from constantly typing.

****editors:

vim script.sh (opens script.sh with editor vim) nano script.sh (opens script.sh with editor nano)


Machen es möglich, einmal geschriebenen Code mehrfach zu verwenden und ihn zu strukturieren.

Tool zur Versionierung, das kolaboratives Coding ermöglicht.

Links

Shortcuts (IntelliJ)

  • Code automatisch formatieren: Opt + Cmd + L

  • System.out.println: sout + Enter

  • public static void main(String[] args): main oder psvm + Enter

  • Cmd + D: Duplicate Codeline

  • Shift + Opt + Arrow Up : Move Codeline

  • Cmd + N: Generate Code

  • Opt + Shift + 7 : Backslash

  • Opt + Shift + 4 : Auswahlwerkzeug für Screenshot

Clone this wiki locally