deploy: 48765d2c69
This commit is contained in:
parent
3eae1e8e08
commit
5ae60533a4
|
@ -0,0 +1,612 @@
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="de" class="no-js">
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="icon" href="assets/images/favicon.png">
|
||||||
|
<meta name="generator" content="mkdocs-1.3.1, mkdocs-material-8.4.2">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<title>01: Hello World - Markdown Docs</title>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="assets/stylesheets/main.69437709.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="assets/stylesheets/palette.cbb835fc.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
|
||||||
|
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-enum-headings1.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-enum-headings2.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-enum-headings3.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-material.css">
|
||||||
|
|
||||||
|
<script>__md_scope=new URL(".",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
|
||||||
|
|
||||||
|
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||||
|
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||||
|
<label class="md-overlay" for="__drawer"></label>
|
||||||
|
<div data-md-component="skip">
|
||||||
|
|
||||||
|
|
||||||
|
<a href="#01-hello-world" class="md-skip">
|
||||||
|
Zum Inhalt
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div data-md-component="announce">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<header class="md-header" data-md-component="header">
|
||||||
|
<nav class="md-header__inner md-grid" aria-label="Header">
|
||||||
|
<a href="index.html" title="Markdown Docs" class="md-header__button md-logo" aria-label="Markdown Docs" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
<label class="md-header__button md-icon" for="__drawer">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-header__title" data-md-component="header-title">
|
||||||
|
<div class="md-header__ellipsis">
|
||||||
|
<div class="md-header__topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Markdown Docs
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="md-header__topic" data-md-component="header-topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
|
||||||
|
01: Hello World
|
||||||
|
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form class="md-header__option" data-md-component="palette">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_1">
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 6H7c-3.31 0-6 2.69-6 6s2.69 6 6 6h10c3.31 0 6-2.69 6-6s-2.69-6-6-6zm0 10H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h10c2.21 0 4 1.79 4 4s-1.79 4-4 4zM7 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/></svg>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="indigo" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_2">
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 7H7a5 5 0 0 0-5 5 5 5 0 0 0 5 5h10a5 5 0 0 0 5-5 5 5 0 0 0-5-5m0 8a3 3 0 0 1-3-3 3 3 0 0 1 3-3 3 3 0 0 1 3 3 3 3 0 0 1-3 3Z"/></svg>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" for="__search">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-search" data-md-component="search" role="dialog">
|
||||||
|
<label class="md-search__overlay" for="__search"></label>
|
||||||
|
<div class="md-search__inner" role="search">
|
||||||
|
<form class="md-search__form" name="search">
|
||||||
|
<input type="text" class="md-search__input" name="query" aria-label="Suche" placeholder="Suche" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
|
||||||
|
<label class="md-search__icon md-icon" for="__search">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||||
|
</label>
|
||||||
|
<nav class="md-search__options" aria-label="Suche">
|
||||||
|
|
||||||
|
<button type="reset" class="md-search__icon md-icon" aria-label="Zurücksetzen" tabindex="-1">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
<div class="md-search__output">
|
||||||
|
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||||
|
<div class="md-search-result" data-md-component="search-result">
|
||||||
|
<div class="md-search-result__meta">
|
||||||
|
Suche wird initialisiert
|
||||||
|
</div>
|
||||||
|
<ol class="md-search-result__list"></ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-header__source">
|
||||||
|
<a href="https://github.com/YamiDoesDev/algodat-java-intro" title="Quellcode" class="md-source" data-md-component="source">
|
||||||
|
<div class="md-source__icon md-icon">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.1.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
|
||||||
|
</div>
|
||||||
|
<div class="md-source__repository">
|
||||||
|
GitHub
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="md-container" data-md-component="container">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<main class="md-main" data-md-component="main">
|
||||||
|
<div class="md-main__inner md-grid">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
|
||||||
|
<label class="md-nav__title" for="__drawer">
|
||||||
|
<a href="index.html" title="Markdown Docs" class="md-nav__button md-logo" aria-label="Markdown Docs" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
Markdown Docs
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="md-nav__source">
|
||||||
|
<a href="https://github.com/YamiDoesDev/algodat-java-intro" title="Quellcode" class="md-source" data-md-component="source">
|
||||||
|
<div class="md-source__icon md-icon">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.1.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
|
||||||
|
</div>
|
||||||
|
<div class="md-source__repository">
|
||||||
|
GitHub
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="index.html" class="md-nav__link">
|
||||||
|
Crashkurs Java im Modul Algorithmen und Datenstrukturen
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item md-nav__item--active">
|
||||||
|
|
||||||
|
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||||
|
01: Hello World
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<a href="01_hello_world.html" class="md-nav__link md-nav__link--active">
|
||||||
|
01: Hello World
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Inhaltsverzeichnis">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__title" for="__toc">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Inhaltsverzeichnis
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#approach-1-simple-string-output" class="md-nav__link">
|
||||||
|
Approach 1: Simple String Output
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#approach-2-using-console-arguments" class="md-nav__link">
|
||||||
|
Approach 2: Using Console Arguments
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="02_basics.html" class="md-nav__link">
|
||||||
|
02: Basics
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="03_coding_style.html" class="md-nav__link">
|
||||||
|
03: Coding Style
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="04_introduction_to_objects.html" class="md-nav__link">
|
||||||
|
04: Einführung in Objekte
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="05_types_of_objects.html" class="md-nav__link">
|
||||||
|
05: Typen von Objekten
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="06_java_docs.html" class="md-nav__link">
|
||||||
|
06: JavaDoc
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="print_page.html" class="md-nav__link">
|
||||||
|
Print as PDF
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Inhaltsverzeichnis">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__title" for="__toc">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Inhaltsverzeichnis
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#approach-1-simple-string-output" class="md-nav__link">
|
||||||
|
Approach 1: Simple String Output
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#approach-2-using-console-arguments" class="md-nav__link">
|
||||||
|
Approach 2: Using Console Arguments
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-content" data-md-component="content">
|
||||||
|
<article class="md-content__inner md-typeset">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a href="https://github.com/YamiDoesDev/algodat-java-intro/edit/main/docs/01_hello_world.md" title="Seite editieren" class="md-content__button md-icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25Z"/></svg>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h1 id="01-hello-world">01: Hello World</h1>
|
||||||
|
<h2 id="approach-1-simple-string-output">Approach 1: Simple String Output</h2>
|
||||||
|
<p><div class="highlight"><pre><span></span><code><span class="c1">// main.java</span><span class="w"></span>
|
||||||
|
<span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">main</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"Hello, World!"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<div class="highlight"><pre><span></span><code>>> javac main.java
|
||||||
|
>> java main
|
||||||
|
Hello, World!
|
||||||
|
</code></pre></div></p>
|
||||||
|
<p>Was sagt dieser Code nun aus?
|
||||||
|
* Eine Klasse "main" ist öffentlich
|
||||||
|
* Dem Compiler wird die statische Methode <code>main</code> vorlegt
|
||||||
|
* Diese wird bei jedem Java Code genutzt
|
||||||
|
* Wir rufen die Klasse System auf und führen einen <code>println</code>-Befehl aus
|
||||||
|
* <code>Hello, World!</code> wird in der Konsole ausgegeben</p>
|
||||||
|
<h2 id="approach-2-using-console-arguments">Approach 2: Using Console Arguments</h2>
|
||||||
|
<p><div class="highlight"><pre><span></span><code><span class="c1">// main.java</span><span class="w"></span>
|
||||||
|
<span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">main</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">args</span><span class="o">[</span><span class="mi">0</span><span class="o">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">" "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">args</span><span class="o">[</span><span class="mi">1</span><span class="o">]</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<div class="highlight"><pre><span></span><code>>> javac main.java
|
||||||
|
>> java main Hello, World!
|
||||||
|
Hello, World!
|
||||||
|
</code></pre></div></p>
|
||||||
|
<p>Was ist nun anders?
|
||||||
|
* Die Main-Methode übergibt standardmäßig Konsolenargumente als Array vom Typ String mit dem Namen <code>args</code>
|
||||||
|
* Jedes Argument hat einen Index im Array
|
||||||
|
* Für 2 Argumente rufen wir die ersten zwei Indexes auf, beginnend bei <code>0</code></p>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<div class="md-source-file">
|
||||||
|
<small>
|
||||||
|
|
||||||
|
Letztes Update:
|
||||||
|
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">November 2, 2022 20:46:05</span>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
Erstellt:
|
||||||
|
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">November 2, 2022 20:46:05</span>
|
||||||
|
|
||||||
|
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-source-date">
|
||||||
|
<small>
|
||||||
|
Authors: <span class='git-page-authors git-authors'><a href='mailto:yamidoesdev@gmail.com'>YamiDoesDev</a></span>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</article>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="md-footer">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-footer__inner md-grid" aria-label="Footer" >
|
||||||
|
|
||||||
|
|
||||||
|
<a href="index.html" class="md-footer__link md-footer__link--prev" aria-label="Zurück: Crashkurs Java im Modul Algorithmen und Datenstrukturen" rel="prev">
|
||||||
|
<div class="md-footer__button md-icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||||
|
</div>
|
||||||
|
<div class="md-footer__title">
|
||||||
|
<div class="md-ellipsis">
|
||||||
|
<span class="md-footer__direction">
|
||||||
|
Zurück
|
||||||
|
</span>
|
||||||
|
Crashkurs Java im Modul Algorithmen und Datenstrukturen
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a href="02_basics.html" class="md-footer__link md-footer__link--next" aria-label="Weiter: 02: Basics" rel="next">
|
||||||
|
<div class="md-footer__title">
|
||||||
|
<div class="md-ellipsis">
|
||||||
|
<span class="md-footer__direction">
|
||||||
|
Weiter
|
||||||
|
</span>
|
||||||
|
02: Basics
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="md-footer__button md-icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4Z"/></svg>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="md-footer-meta md-typeset">
|
||||||
|
<div class="md-footer-meta__inner md-grid">
|
||||||
|
<div class="md-copyright">
|
||||||
|
|
||||||
|
|
||||||
|
Made with
|
||||||
|
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
|
||||||
|
Material for MkDocs
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="md-dialog" data-md-component="dialog">
|
||||||
|
<div class="md-dialog__inner md-typeset"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script id="__config" type="application/json">{"base": ".", "features": [], "search": "assets/javascripts/workers/search.ecf98df9.min.js", "translations": {"clipboard.copied": "In Zwischenablage kopiert", "clipboard.copy": "In Zwischenablage kopieren", "search.config.lang": "de", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Suche", "search.result.more.one": "1 weiteres Suchergebnis auf dieser Seite", "search.result.more.other": "# weitere Suchergebnisse auf dieser Seite", "search.result.none": "Keine Suchergebnisse", "search.result.one": "1 Suchergebnis", "search.result.other": "# Suchergebnisse", "search.result.placeholder": "Suchbegriff eingeben", "search.result.term.missing": "Es fehlt", "select.version.title": "Version ausw\u00e4hlen"}}</script>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="https://unpkg.com/iframe-worker/polyfill"></script>
|
||||||
|
<script src="search/search_index.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script src="assets/javascripts/bundle.9c69f0bc.min.js"></script>
|
||||||
|
|
||||||
|
<script src="js/print-site.js"></script>
|
||||||
|
|
||||||
|
<script src="js/arithmatex.config.js"></script>
|
||||||
|
|
||||||
|
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,48 @@
|
||||||
|
# 01: Hello World
|
||||||
|
|
||||||
|
## Approach 1: Simple String Output
|
||||||
|
|
||||||
|
```java
|
||||||
|
// main.java
|
||||||
|
public class main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello, World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
```shell
|
||||||
|
>> javac main.java
|
||||||
|
>> java main
|
||||||
|
Hello, World!
|
||||||
|
```
|
||||||
|
|
||||||
|
Was sagt dieser Code nun aus?
|
||||||
|
* Eine Klasse "main" ist öffentlich
|
||||||
|
* Dem Compiler wird die statische Methode `main` vorlegt
|
||||||
|
* Diese wird bei jedem Java Code genutzt
|
||||||
|
* Wir rufen die Klasse System auf und führen einen `println`-Befehl aus
|
||||||
|
* `Hello, World!` wird in der Konsole ausgegeben
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Approach 2: Using Console Arguments
|
||||||
|
|
||||||
|
```java
|
||||||
|
// main.java
|
||||||
|
public class main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(args[0] + " " + args[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
```shell
|
||||||
|
>> javac main.java
|
||||||
|
>> java main Hello, World!
|
||||||
|
Hello, World!
|
||||||
|
```
|
||||||
|
|
||||||
|
Was ist nun anders?
|
||||||
|
* Die Main-Methode übergibt standardmäßig Konsolenargumente als Array vom Typ String mit dem Namen `args`
|
||||||
|
* Jedes Argument hat einen Index im Array
|
||||||
|
* Für 2 Argumente rufen wir die ersten zwei Indexes auf, beginnend bei `0`
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,421 @@
|
||||||
|
# 02: Basics
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
1. [Nutzung der Konsole](#nutzung-der-konsole)
|
||||||
|
2. [Primitive Datentypen](#primitive-datentypen)
|
||||||
|
3. [Nicht Primitive Datentypen](#)
|
||||||
|
4. [Operatoren](#)
|
||||||
|
5. [Bedingungen](#)
|
||||||
|
6. [Schleifen](#)
|
||||||
|
7. [Exceptions](#exceptions)
|
||||||
|
|
||||||
|
## Nutzung der Konsole
|
||||||
|
|
||||||
|
### Ausgabe
|
||||||
|
```java
|
||||||
|
|
||||||
|
System.out.println("print me and create a new line");
|
||||||
|
System.out.println(); // prints nothing but creates new line afterwards
|
||||||
|
|
||||||
|
System.out.print("print me without a new line | ");
|
||||||
|
System.out.print("print me but add a new line \n");
|
||||||
|
System.out.print("yeah, this is on the new line! \n");
|
||||||
|
System.out.println(); // prints nothing but creates new line afterwards
|
||||||
|
|
||||||
|
// https://www.digitalocean.com/community/tutorials/java-printf-method
|
||||||
|
System.out.printf("%s %s \n", "parameter 1", "parameter 2");
|
||||||
|
System.out.printf("%s %e %f", "10.50", 10.50, 10.50);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Eingabe
|
||||||
|
```java
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
// class and method : start
|
||||||
|
Scanner myScanner = new Scanner(System.in);
|
||||||
|
System.out.print("Enter Username: ");
|
||||||
|
String username = myScanner.nextLine();
|
||||||
|
System.out.print("Enter Password: ");
|
||||||
|
String password = myScanner.nextLine();
|
||||||
|
System.out.println("your Username: " + username + "\nyour password: " + password );
|
||||||
|
// class and method : end
|
||||||
|
```
|
||||||
|
|
||||||
|
## Primitive Datentypen
|
||||||
|
|
||||||
|
Quelle: [w3schools.com](https://www.w3schools.com/java/java_data_types.asp)
|
||||||
|
|
||||||
|
| Data Type | Size | Description |
|
||||||
|
|-----------|---------|-------------------------------------------------------------------------------------|
|
||||||
|
| byte | 1 byte | Stores whole numbers from -128 to 127 |
|
||||||
|
| short | 2 bytes | Stores whole numbers from -32,768 to 32,767 |
|
||||||
|
| int | 4 bytes | Stores whole numbers from -2,147,483,648 to 2,147,483,647 |
|
||||||
|
| long | 8 bytes | Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
|
||||||
|
| float | 4 bytes | Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits |
|
||||||
|
| double | 8 bytes | Stores fractional numbers. Sufficient for storing 15 decimal digits |
|
||||||
|
| boolean | 1 bit | Stores true or false values |
|
||||||
|
| char | 2 bytes | Stores a single character/letter or ASCII values |
|
||||||
|
|
||||||
|
### Type Casting
|
||||||
|
|
||||||
|
Bei Type Casting handelt es sich um das überführen eines primitiven Datentypen
|
||||||
|
in einen anderen.
|
||||||
|
|
||||||
|
Quelle: [w3schools.com](https://www.w3schools.com/java/java_type_casting.asp)
|
||||||
|
|
||||||
|
#### Widening Casting (automatically)
|
||||||
|
|
||||||
|
Hier wird ein kleinerer Typ in einen größeren Typ konvertiert
|
||||||
|
|
||||||
|
`byte` -> `short` -> `char` -> `int` -> `long` -> `float` -> `double`
|
||||||
|
|
||||||
|
```java
|
||||||
|
int myInt = 9;
|
||||||
|
double myDouble = myInt; // Automatic casting: int to double
|
||||||
|
|
||||||
|
System.out.println(myInt); // Outputs 9
|
||||||
|
System.out.println(myDouble); // Outputs 9.0
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Narrowing Casting (manually)
|
||||||
|
|
||||||
|
Hier wird ein größerer Typ in einen kleineren Typ konvertiert
|
||||||
|
|
||||||
|
`double` -> `float` -> `long` -> `int` -> `char` -> `short` -> `byte`
|
||||||
|
|
||||||
|
```java
|
||||||
|
double myDouble = 9.78d;
|
||||||
|
int myInt = (int) myDouble; // Manual casting: double to int
|
||||||
|
|
||||||
|
System.out.println(myDouble); // Outputs 9.78
|
||||||
|
System.out.println(myInt); // Outputs 9
|
||||||
|
```
|
||||||
|
|
||||||
|
## Nicht Primitive Datentypen
|
||||||
|
|
||||||
|
### String
|
||||||
|
|
||||||
|
String ist eine Wrapperklasse, welche eine Zeichenkette aus einzelnen chars
|
||||||
|
zusammenbaut. In manchen Programmiersprachen (z.B. C++) ist ein String
|
||||||
|
vergleichbar mit einem char-Array.
|
||||||
|
|
||||||
|
```java
|
||||||
|
String myString = "this is a text";
|
||||||
|
System.out.println("myString: " + myString);
|
||||||
|
|
||||||
|
String concatString = "hello" + "World";
|
||||||
|
System.out.println("concatString: " + concatString);
|
||||||
|
```
|
||||||
|
|
||||||
|
Methoden der Standardbibliothek:
|
||||||
|
```java
|
||||||
|
myString.charAt(); // Returns the char value at the specified index.
|
||||||
|
myString.indexOf(); // Returns the index within this string of the first occurrence of the specified substring.
|
||||||
|
myString.substring(); // Returns a string that is a substring of this string.
|
||||||
|
myString.equals(); // Compares this string to the specified object.
|
||||||
|
myString.toLowerCase(); // Converts all of the characters in this String to lower case.
|
||||||
|
myString.toUpperCase(); // Converts all of the characters in this String to upper case.
|
||||||
|
myString.contains(); // Returns true if and only if this string contains the specified sequence of char values.
|
||||||
|
myString.replaceAll(); // Replaces each substring of this string that matches the given regular expression with the given replacement.
|
||||||
|
myString.compareTo(); // Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings.
|
||||||
|
```
|
||||||
|
|
||||||
|
### Numeric Datatypes
|
||||||
|
|
||||||
|
Im Gegensatz zu den primitiven Datentypen werden hier "Wrapper" verwendet, um
|
||||||
|
dynamisch mit den Werten arbeiten zu können. Das erlaubt auch die Erweiterung
|
||||||
|
um verschiedene Methoden in der Standardbibliothek.
|
||||||
|
|
||||||
|
Integer:
|
||||||
|
```java
|
||||||
|
Integer myNumber = 10;
|
||||||
|
Integer.parseInt(); // Parses the string argument as a signed decimal integer.
|
||||||
|
Integer.parseUnsignedInt(); // Parses the string argument as an unsigned decimal integer.
|
||||||
|
Integer.valueOf(); // Returns an Integer object holding the value of the specified String.
|
||||||
|
```
|
||||||
|
|
||||||
|
Float and Double:
|
||||||
|
```java
|
||||||
|
Double myDouble = 10.0;
|
||||||
|
myDouble.isNaN(); // Returns true if this Double value is a Not-a-Number (NaN), false otherwise.
|
||||||
|
|
||||||
|
Float myFloat = (float)10.0;
|
||||||
|
myFloat.isNaN(); // Returns true if this Float value is a Not-a-Number (NaN), false otherwise
|
||||||
|
```
|
||||||
|
|
||||||
|
Funktionen für alle Numerischen Datentypen (Nicht Primitiv):
|
||||||
|
```java
|
||||||
|
myNumber.compareTo(); // Compares two Integer objects numerically.
|
||||||
|
myNumber.toString(); // Returns a String object representing this Integer's value.
|
||||||
|
myNumber.intValue(); // Returns the value of this Integer as an int.
|
||||||
|
myNumber.floatValue(); // Returns the value of this Integer as a float after a widening primitive conversion.
|
||||||
|
myNumber.doubleValue(); // Returns the value of this Integer as a double after a widening primitive conversion.
|
||||||
|
myNumber.shortValue(); // Returns the value of this Integer as a short after a narrowing primitive conversion.
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arrays
|
||||||
|
Bei Arrays handelt es sich um Schleifen eines bestimmten Datentypen. Sie werden
|
||||||
|
verwendet, um mehrere Werte in einer Variable zu speichern.
|
||||||
|
|
||||||
|
```java
|
||||||
|
String[] myStringArray = new String[3];
|
||||||
|
myStringArray[0] = "ROT";
|
||||||
|
myStringArray[1] = "GRÜN";
|
||||||
|
myStringArray[2] = "BLAU";
|
||||||
|
|
||||||
|
int[] myIntArray = {0,1,2};
|
||||||
|
|
||||||
|
System.out.println(myIntArray.length); // 3
|
||||||
|
System.out.println(Arrays.toString(myIntArray)); // [0,1,2]
|
||||||
|
```
|
||||||
|
|
||||||
|
multidimensionale Arrays:
|
||||||
|
```java
|
||||||
|
int[][] my2DArray = {
|
||||||
|
{1, 2},
|
||||||
|
{3, 4, 5},
|
||||||
|
{6, 7, 8, 9},
|
||||||
|
};
|
||||||
|
|
||||||
|
System.out.println(my2DArray.length);
|
||||||
|
System.out.println(my2DArray[0].length);
|
||||||
|
|
||||||
|
for(int row = 0; row < my2DArray.length; row++) {
|
||||||
|
System.out.print("[");
|
||||||
|
for(int column = 0; column < my2DArray[row].length; column++) {
|
||||||
|
if (column == (my2DArray[row].length - 1) ) {
|
||||||
|
System.out.print(my2DArray[row][column]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
System.out.print(my2DArray[row][column] + ", ");
|
||||||
|
}
|
||||||
|
System.out.println("]");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Methoden:
|
||||||
|
```java
|
||||||
|
Arrays.toString(myArray); // a string representation of the object.
|
||||||
|
Arrays.copyOf(myArray, 3); // Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
|
||||||
|
Arrays.compare(myArray, myArray); // Compares two int arrays lexicographically.
|
||||||
|
Arrays.equals(myArray, myArray); // Returns true if the two specified arrays of ints are equal to one another.
|
||||||
|
Arrays.sort(myArray); // Sorts the specified array into ascending numerical order
|
||||||
|
Arrays.fill(myArray, 0); // Assigns the specified int value to each element of the specified array of ints.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Operatoren
|
||||||
|
|
||||||
|
### Arithmetic Operators
|
||||||
|
```java
|
||||||
|
int calcAddition = 20 + 10; // = 30
|
||||||
|
int calcSubstraction = 20 - 10; // = 10
|
||||||
|
int calcMultiplication = 20 * 10; // = 200
|
||||||
|
int calcDivision = 20 / 10; // = 2
|
||||||
|
int calcModulus = 20 % 3; // = 2
|
||||||
|
|
||||||
|
int myNumber = 10;
|
||||||
|
myNumber++; // myNumber = 11
|
||||||
|
myNumber--; // myNumber = 10
|
||||||
|
myNumber--; // myNumber = 9
|
||||||
|
```
|
||||||
|
|
||||||
|
### Comparison Operators
|
||||||
|
```java
|
||||||
|
int biggerNumber = 20;
|
||||||
|
int biggerNumberAgain = 20;
|
||||||
|
int smallerNumber = 10;
|
||||||
|
|
||||||
|
// (20 == 20) => true
|
||||||
|
// (20 != 20) => false
|
||||||
|
// (20 > 10) => true
|
||||||
|
// (20 < 10) => false
|
||||||
|
// (20 >= 10) => true
|
||||||
|
// (20 >= 10) => true
|
||||||
|
```
|
||||||
|
|
||||||
|
## Bedingungen
|
||||||
|
|
||||||
|
wir verwenden folgende Variablen:
|
||||||
|
```java
|
||||||
|
int biggerNumber = 20;
|
||||||
|
int biggerNumberAgain = 20;
|
||||||
|
int smallerNumber = 10;
|
||||||
|
```
|
||||||
|
|
||||||
|
### if-condition (better version)
|
||||||
|
```java
|
||||||
|
if (biggerNumber > smallerNumber) {
|
||||||
|
System.out.println("the left number is bigger!");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### if-condition (worse version)
|
||||||
|
```java
|
||||||
|
// prefer to not write it down like this!
|
||||||
|
if (biggerNumber == biggerNumberAgain)
|
||||||
|
System.out.println("We don't do this here...");
|
||||||
|
```
|
||||||
|
|
||||||
|
### if-else-condition
|
||||||
|
```java
|
||||||
|
if (biggerNumber < smallerNumber) {
|
||||||
|
System.out.println("the left number is smaller!");
|
||||||
|
} else if (biggerNumber < biggerNumberAgain) {
|
||||||
|
System.out.println("but this time, the left number is smaller!");
|
||||||
|
} else {
|
||||||
|
System.out.println("the left number is just too big!");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### switch-case
|
||||||
|
```java
|
||||||
|
int luckyNumber = 69;
|
||||||
|
switch (luckyNumber) {
|
||||||
|
case 13:
|
||||||
|
System.out.println("some people consider 13 to be a lucky number");
|
||||||
|
break; // we need this to avoid default!
|
||||||
|
case 7:
|
||||||
|
System.out.println("slot machines value this number high");
|
||||||
|
break; // we need this to avoid default!
|
||||||
|
default:
|
||||||
|
System.out.println("seems, your number was not lucky enough...");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Schleifen
|
||||||
|
|
||||||
|
### while-loop
|
||||||
|
```java
|
||||||
|
int whileNumber = 3;
|
||||||
|
while (whileNumber > 0) {
|
||||||
|
System.out.println(whileNumber);
|
||||||
|
whileNumber --;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### do-while-loop
|
||||||
|
```java
|
||||||
|
System.out.println("--- doWhileNumber:");
|
||||||
|
int doWhileNumber = 3;
|
||||||
|
do {
|
||||||
|
System.out.println(doWhileNumber);
|
||||||
|
doWhileNumber--;
|
||||||
|
} while(doWhileNumber > 0);
|
||||||
|
```
|
||||||
|
|
||||||
|
### for-loop
|
||||||
|
```java
|
||||||
|
System.out.println("--- forNumber:");
|
||||||
|
for(int iterator = 0; iterator <= 5; iterator++) {
|
||||||
|
System.out.println(iterator);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Beispiel Ausführung
|
||||||
|
```java
|
||||||
|
int myNumber = 1;
|
||||||
|
// count, how many times we can add 2 until we reach 16,
|
||||||
|
// but we pretend, 13 doesn't exist for reasons
|
||||||
|
for(int counter = 0; counter <= 10; counter++) {
|
||||||
|
myNumber += 2;
|
||||||
|
if (myNumber == 13) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
System.out.println(counter);
|
||||||
|
if (myNumber >= 16) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hinweis
|
||||||
|
Vermeidet einfache Variablennamen wie i, u, usw.m um die Lesbarkeit einfach zu halten
|
||||||
|
```java
|
||||||
|
//
|
||||||
|
for(int i = 0; i < 10; i++) {
|
||||||
|
for(int u = 30; i > 15; u++) {
|
||||||
|
myArray[u][i] = i + u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### for-each-loop
|
||||||
|
|
||||||
|
#### arrays
|
||||||
|
```java
|
||||||
|
int[] myArray = {1, 2, 3};
|
||||||
|
|
||||||
|
for(int selectedValue: myArray) {
|
||||||
|
System.out.println("myArray: " + selectedValue);
|
||||||
|
selectedValue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(Arrays.toString(myArray));
|
||||||
|
|
||||||
|
for(int selection: myArray) {
|
||||||
|
System.out.println(selection);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### lists
|
||||||
|
```java
|
||||||
|
LinkedList<String> myLinkedList = new LinkedList<>();
|
||||||
|
myLinkedList.add("List_1");
|
||||||
|
myLinkedList.add("List_2");
|
||||||
|
myLinkedList.add("List_3");
|
||||||
|
|
||||||
|
for(int selectedValue: myArray) {
|
||||||
|
System.out.println(selectedValue);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### maps
|
||||||
|
|
||||||
|
```java
|
||||||
|
HashMap<Integer, String> myHashMap = new HashMap<>();
|
||||||
|
myHashMap.put(1, "Larry");
|
||||||
|
myHashMap.put(2, "Steve");
|
||||||
|
myHashMap.put(3, "James");
|
||||||
|
|
||||||
|
myHashMap.forEach((key, value) -> {
|
||||||
|
System.out.println(key + " " + value);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Exceptions
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// simple exception handling
|
||||||
|
try {
|
||||||
|
int[] myNumbers = {1, 2, 3};
|
||||||
|
System.out.println(myNumbers[10]);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
System.out.println(exception);
|
||||||
|
System.out.println("---");
|
||||||
|
}
|
||||||
|
|
||||||
|
// extended exception handling
|
||||||
|
try {
|
||||||
|
int[] myNumbers = {1, 2, 3};
|
||||||
|
printTenthIndex(myNumbers);
|
||||||
|
} catch (RuntimeException exception) {
|
||||||
|
System.out.println("class: " + exception.getClass()); // class: class java.lang.RuntimeException
|
||||||
|
System.out.println("cause: " + exception.getCause()); // cause: java.lang.RuntimeException: array is not big enough
|
||||||
|
System.out.println("message: " + exception.getMessage()); // message: index was not found
|
||||||
|
} finally {
|
||||||
|
System.out.println("finally! The 'try catch' is finished.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void printTenthIndex(int[] array) throws RuntimeException {
|
||||||
|
Exception r = new RuntimeException("array is not big enough"); // not every exception supports causes
|
||||||
|
if (array.length < 11) {
|
||||||
|
throw new RuntimeException("index was not found", r);
|
||||||
|
}
|
||||||
|
System.out.println(array[10]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
|
@ -0,0 +1,822 @@
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="de" class="no-js">
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="icon" href="assets/images/favicon.png">
|
||||||
|
<meta name="generator" content="mkdocs-1.3.1, mkdocs-material-8.4.2">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<title>03: Coding Style - Markdown Docs</title>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="assets/stylesheets/main.69437709.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="assets/stylesheets/palette.cbb835fc.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
|
||||||
|
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-enum-headings1.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-enum-headings2.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-enum-headings3.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-material.css">
|
||||||
|
|
||||||
|
<script>__md_scope=new URL(".",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
|
||||||
|
|
||||||
|
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||||
|
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||||
|
<label class="md-overlay" for="__drawer"></label>
|
||||||
|
<div data-md-component="skip">
|
||||||
|
|
||||||
|
|
||||||
|
<a href="#03-coding-style" class="md-skip">
|
||||||
|
Zum Inhalt
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div data-md-component="announce">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<header class="md-header" data-md-component="header">
|
||||||
|
<nav class="md-header__inner md-grid" aria-label="Header">
|
||||||
|
<a href="index.html" title="Markdown Docs" class="md-header__button md-logo" aria-label="Markdown Docs" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
<label class="md-header__button md-icon" for="__drawer">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-header__title" data-md-component="header-title">
|
||||||
|
<div class="md-header__ellipsis">
|
||||||
|
<div class="md-header__topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Markdown Docs
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="md-header__topic" data-md-component="header-topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
|
||||||
|
03: Coding Style
|
||||||
|
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form class="md-header__option" data-md-component="palette">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_1">
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 6H7c-3.31 0-6 2.69-6 6s2.69 6 6 6h10c3.31 0 6-2.69 6-6s-2.69-6-6-6zm0 10H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h10c2.21 0 4 1.79 4 4s-1.79 4-4 4zM7 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/></svg>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="indigo" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_2">
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 7H7a5 5 0 0 0-5 5 5 5 0 0 0 5 5h10a5 5 0 0 0 5-5 5 5 0 0 0-5-5m0 8a3 3 0 0 1-3-3 3 3 0 0 1 3-3 3 3 0 0 1 3 3 3 3 0 0 1-3 3Z"/></svg>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" for="__search">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-search" data-md-component="search" role="dialog">
|
||||||
|
<label class="md-search__overlay" for="__search"></label>
|
||||||
|
<div class="md-search__inner" role="search">
|
||||||
|
<form class="md-search__form" name="search">
|
||||||
|
<input type="text" class="md-search__input" name="query" aria-label="Suche" placeholder="Suche" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
|
||||||
|
<label class="md-search__icon md-icon" for="__search">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||||
|
</label>
|
||||||
|
<nav class="md-search__options" aria-label="Suche">
|
||||||
|
|
||||||
|
<button type="reset" class="md-search__icon md-icon" aria-label="Zurücksetzen" tabindex="-1">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
<div class="md-search__output">
|
||||||
|
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||||
|
<div class="md-search-result" data-md-component="search-result">
|
||||||
|
<div class="md-search-result__meta">
|
||||||
|
Suche wird initialisiert
|
||||||
|
</div>
|
||||||
|
<ol class="md-search-result__list"></ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-header__source">
|
||||||
|
<a href="https://github.com/YamiDoesDev/algodat-java-intro" title="Quellcode" class="md-source" data-md-component="source">
|
||||||
|
<div class="md-source__icon md-icon">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.1.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
|
||||||
|
</div>
|
||||||
|
<div class="md-source__repository">
|
||||||
|
GitHub
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="md-container" data-md-component="container">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<main class="md-main" data-md-component="main">
|
||||||
|
<div class="md-main__inner md-grid">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
|
||||||
|
<label class="md-nav__title" for="__drawer">
|
||||||
|
<a href="index.html" title="Markdown Docs" class="md-nav__button md-logo" aria-label="Markdown Docs" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
Markdown Docs
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="md-nav__source">
|
||||||
|
<a href="https://github.com/YamiDoesDev/algodat-java-intro" title="Quellcode" class="md-source" data-md-component="source">
|
||||||
|
<div class="md-source__icon md-icon">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.1.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
|
||||||
|
</div>
|
||||||
|
<div class="md-source__repository">
|
||||||
|
GitHub
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="index.html" class="md-nav__link">
|
||||||
|
Crashkurs Java im Modul Algorithmen und Datenstrukturen
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="01_hello_world.html" class="md-nav__link">
|
||||||
|
01: Hello World
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="02_basics.html" class="md-nav__link">
|
||||||
|
02: Basics
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item md-nav__item--active">
|
||||||
|
|
||||||
|
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||||
|
03: Coding Style
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<a href="03_coding_style.html" class="md-nav__link md-nav__link--active">
|
||||||
|
03: Coding Style
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Inhaltsverzeichnis">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__title" for="__toc">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Inhaltsverzeichnis
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#1-selbsterklarend" class="md-nav__link">
|
||||||
|
1. Selbsterklärend
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<nav class="md-nav" aria-label="1. Selbsterklärend">
|
||||||
|
<ul class="md-nav__list">
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#11-kommentare" class="md-nav__link">
|
||||||
|
1.1 Kommentare
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#4-benennung" class="md-nav__link">
|
||||||
|
4. Benennung
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<nav class="md-nav" aria-label="4. Benennung">
|
||||||
|
<ul class="md-nav__list">
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#41-camelcase-fur-variablen-und-funktionen" class="md-nav__link">
|
||||||
|
4.1 camelCase für Variablen und Funktionen
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#42-unterstrich-vor-formalen-parametern" class="md-nav__link">
|
||||||
|
4.2 Unterstrich vor formalen Parametern
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#43-pascalcase-fur-klassen-und-interfaces" class="md-nav__link">
|
||||||
|
4.3 PascalCase für Klassen und Interfaces
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#44-groschreibung-fur-enumeratoren" class="md-nav__link">
|
||||||
|
4.4 Großschreibung für Enumeratoren
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#5-doppelte-und-einfache-anfuhrungszeichen" class="md-nav__link">
|
||||||
|
5. Doppelte und einfache Anführungszeichen
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#6-formatierung" class="md-nav__link">
|
||||||
|
6. Formatierung
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#8-magische-zahlen" class="md-nav__link">
|
||||||
|
8. "Magische" Zahlen
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#9-dateinamen-und-aufteilung" class="md-nav__link">
|
||||||
|
9. Dateinamen und -aufteilung
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#10-wiederholungen-sind-schlecht" class="md-nav__link">
|
||||||
|
10. Wiederholungen sind schlecht
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="04_introduction_to_objects.html" class="md-nav__link">
|
||||||
|
04: Einführung in Objekte
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="05_types_of_objects.html" class="md-nav__link">
|
||||||
|
05: Typen von Objekten
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="06_java_docs.html" class="md-nav__link">
|
||||||
|
06: JavaDoc
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="print_page.html" class="md-nav__link">
|
||||||
|
Print as PDF
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Inhaltsverzeichnis">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__title" for="__toc">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Inhaltsverzeichnis
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#1-selbsterklarend" class="md-nav__link">
|
||||||
|
1. Selbsterklärend
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<nav class="md-nav" aria-label="1. Selbsterklärend">
|
||||||
|
<ul class="md-nav__list">
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#11-kommentare" class="md-nav__link">
|
||||||
|
1.1 Kommentare
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#4-benennung" class="md-nav__link">
|
||||||
|
4. Benennung
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<nav class="md-nav" aria-label="4. Benennung">
|
||||||
|
<ul class="md-nav__list">
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#41-camelcase-fur-variablen-und-funktionen" class="md-nav__link">
|
||||||
|
4.1 camelCase für Variablen und Funktionen
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#42-unterstrich-vor-formalen-parametern" class="md-nav__link">
|
||||||
|
4.2 Unterstrich vor formalen Parametern
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#43-pascalcase-fur-klassen-und-interfaces" class="md-nav__link">
|
||||||
|
4.3 PascalCase für Klassen und Interfaces
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#44-groschreibung-fur-enumeratoren" class="md-nav__link">
|
||||||
|
4.4 Großschreibung für Enumeratoren
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#5-doppelte-und-einfache-anfuhrungszeichen" class="md-nav__link">
|
||||||
|
5. Doppelte und einfache Anführungszeichen
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#6-formatierung" class="md-nav__link">
|
||||||
|
6. Formatierung
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#8-magische-zahlen" class="md-nav__link">
|
||||||
|
8. "Magische" Zahlen
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#9-dateinamen-und-aufteilung" class="md-nav__link">
|
||||||
|
9. Dateinamen und -aufteilung
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#10-wiederholungen-sind-schlecht" class="md-nav__link">
|
||||||
|
10. Wiederholungen sind schlecht
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-content" data-md-component="content">
|
||||||
|
<article class="md-content__inner md-typeset">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a href="https://github.com/YamiDoesDev/algodat-java-intro/edit/main/docs/03_coding_style.md" title="Seite editieren" class="md-content__button md-icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25Z"/></svg>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h1 id="03-coding-style">03: Coding Style</h1>
|
||||||
|
<p>Programme können sehr schnell sehr komplex werden.
|
||||||
|
Daher ist es wichtig, sich an Stil-Regeln zu halten, um sie möglichst
|
||||||
|
verständlich zu schreiben.</p>
|
||||||
|
<h2 id="1-selbsterklarend">1. Selbsterklärend</h2>
|
||||||
|
<p>Code sollte sich so gut wie möglich selbst erklären.
|
||||||
|
Dazu sind sprechende Variablen-, Funktions-, Klassennamen etc. erforderlich.
|
||||||
|
Kurze Namen sind nur in kleinen Gültigkeitsbereichen oder bei klarer Bedeutung
|
||||||
|
(z.B. <code>i</code> für for-Schleifen Iteratoren, <code>y</code> für vertikale Position) erlaubt.</p>
|
||||||
|
<h3 id="11-kommentare">1.1 Kommentare</h3>
|
||||||
|
<p>Kommentare sind in diesem Zusammenhang vorallem zur Strukturierung/Abgrenzung
|
||||||
|
des Codes empfohlen, und um die
|
||||||
|
Verständlichkeit zu erhöhen.
|
||||||
|
Kommentare sollten nicht das Offensichtliche wiederholen (siehe Bild).</p>
|
||||||
|
<p><img alt="Cat labeled Cat" src="https://i.redd.it/iuy9fxt300811.png" /></p>
|
||||||
|
<p>Selbstverständlich kann Code zum besseren eigenen Verständnis kommentiert
|
||||||
|
werden.
|
||||||
|
Denken Sie aber daran, dass bei Code Änderungen auch die Kommentare mit gepflegt
|
||||||
|
werden müssen.</p>
|
||||||
|
<h2 id="4-benennung">4. Benennung</h2>
|
||||||
|
<p>Die folgenden Regelungen sind empfohlen und in keinster Weise verpflichtend.</p>
|
||||||
|
<h3 id="41-camelcase-fur-variablen-und-funktionen">4.1 camelCase für Variablen und Funktionen</h3>
|
||||||
|
<p>Variablen- und Funktionsnamen beginnen mit Kleinbuchstaben und folgen der
|
||||||
|
camelCase Notation, d.h. bei zusammengesetzten
|
||||||
|
Namen beginnen die Wortteile im Inneren mit einem Großbuchstaben.<br />
|
||||||
|
Funktionsnamen beschreiben dabei eine Aktivität (
|
||||||
|
z.B. <code>calculateHorizontalPosition()</code>) oder eine Frage (z.B. <code>isHit()</code>).</p>
|
||||||
|
<p>Gleiches gilt für Attribute und Methoden.</p>
|
||||||
|
<h3 id="42-unterstrich-vor-formalen-parametern">4.2 Unterstrich vor formalen Parametern</h3>
|
||||||
|
<p>Formale Parameter folgen dem Variablen-Benennungs-Schema, mit dem Zusatz eines
|
||||||
|
Unterstriches am Anfang.
|
||||||
|
(z.B. <code>moveTo(_x: number, _y: number)</code>).</p>
|
||||||
|
<h3 id="43-pascalcase-fur-klassen-und-interfaces">4.3 PascalCase für Klassen und Interfaces</h3>
|
||||||
|
<p>Die Namen von Klassen und Interfaces beginnen mit einem Großbuchstaben und
|
||||||
|
folgen sonst der Kamelnotation (also
|
||||||
|
PascalCase).<br />
|
||||||
|
Klassen und Interfaces beschreiben im Normalfall ein bestimmtes Objekt, nicht
|
||||||
|
eine Gruppe von Objekten.
|
||||||
|
Dies sollte sich im Namen wiederspiegeln (<code>Produkt</code> statt <code>Produkte</code>).</p>
|
||||||
|
<h3 id="44-groschreibung-fur-enumeratoren">4.4 Großschreibung für Enumeratoren</h3>
|
||||||
|
<p>Die Namen von Enumerationen und deren Elemente werden durchgehend mit
|
||||||
|
Großbuchstaben geschreiben. Wortteile werden bei
|
||||||
|
Bedarf mit Unterstrich getrennt.</p>
|
||||||
|
<h2 id="5-doppelte-und-einfache-anfuhrungszeichen">5. Doppelte und einfache Anführungszeichen</h2>
|
||||||
|
<p>Es empfielt sich, einfache Anführungszeichen <code>' '</code> für char und doppelte
|
||||||
|
Anführungszeichen <code>" "</code> für Strings zu verwenden.</p>
|
||||||
|
<h2 id="6-formatierung">6. Formatierung</h2>
|
||||||
|
<p>Code ist sinnvoll Formatiert mit Einschüben etc.
|
||||||
|
Im Regelfall unterstützt VSCode dies Automatisch. Machen Sie Gebrauch von der
|
||||||
|
automatischen Formatierungsfunktion.</p>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://www.jetbrains.com/help/idea/reformat-and-rearrange-code.html#reformat_file">Anleitung für IntelliJ</a></li>
|
||||||
|
<li><a href="https://stackoverflow.com/questions/29973357/how-do-you-format-code-in-visual-studio-code-vscode">Anleitung für Visual Studio Code</a></li>
|
||||||
|
<li><a href="https://praxistipps.chip.de/eclipse-autoformat-code-so-gehts_98369">Anleitung für Eclipse</a></li>
|
||||||
|
</ul>
|
||||||
|
<h2 id="8-magische-zahlen">8. "Magische" Zahlen</h2>
|
||||||
|
<p>Der Gebrauch von "magischen" Zahlen sollte vermieden werden. Solange es nicht
|
||||||
|
extrem offensichtlich ist, wofür eine Zahl
|
||||||
|
steht (z.B. <code>Math.pow(x, 5)</code>), sollte eine Variable (nach den oben genannten
|
||||||
|
Guidelines) angelegt werden, welcher die
|
||||||
|
Zahl als Wert zugewiesen wird. So entsteht der Zusammenhang zwischen der
|
||||||
|
Variablen und ihrer Bedeutung, und der Wert
|
||||||
|
kann an einer zentralen Stelle angepasst werden.</p>
|
||||||
|
<h2 id="9-dateinamen-und-aufteilung">9. Dateinamen und -aufteilung</h2>
|
||||||
|
<p>Dateinamen dürfen keine Leerzeichen oder Umlaute enthalten, sind sonst aber frei
|
||||||
|
wählbar (s.u. für Einschränkungen). Es
|
||||||
|
wird empfohlen, die Zeichenwahl auf a-z, A-Z, 0-9 und _ zu beschränken.<br />
|
||||||
|
Code kann auf mehrere Dateien aufgeteilt werden, sofern dies sinnvoll
|
||||||
|
erscheint (z.B. um eine Trennung von Funktion und
|
||||||
|
Daten zu erreichen). Wenn Klassen verwendet werden, sollte jede ihre eigene
|
||||||
|
Datei bekommen. Sofern eine Datei eine
|
||||||
|
bestimmte Klasse enthält, soll die Datei mit dem Namen der Klasse benannt sein.</p>
|
||||||
|
<h2 id="10-wiederholungen-sind-schlecht">10. Wiederholungen sind schlecht</h2>
|
||||||
|
<p>Code der sich ohne oder nur mit minimalen Änderungen wiederholt, kann in den
|
||||||
|
allermeisten Fällen besser geschrieben
|
||||||
|
werden, z.B. über eine Funktion mit Übergabeparametern, oder indem man nur den
|
||||||
|
geänderten Teil implementiert oder
|
||||||
|
überschreibt, während der Rest für alles gleich generiert wird.<br />
|
||||||
|
Dies hat viele Vorteile: Es macht den Code generell übersichtlicher (und damit
|
||||||
|
besser verständlich), kürzer, und
|
||||||
|
wartungsfreundlicher.</p>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<div class="md-source-file">
|
||||||
|
<small>
|
||||||
|
|
||||||
|
Letztes Update:
|
||||||
|
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">November 2, 2022 20:46:05</span>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
Erstellt:
|
||||||
|
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">November 2, 2022 20:46:05</span>
|
||||||
|
|
||||||
|
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-source-date">
|
||||||
|
<small>
|
||||||
|
Authors: <span class='git-page-authors git-authors'><a href='mailto:yamidoesdev@gmail.com'>YamiDoesDev</a></span>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</article>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="md-footer">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-footer__inner md-grid" aria-label="Footer" >
|
||||||
|
|
||||||
|
|
||||||
|
<a href="02_basics.html" class="md-footer__link md-footer__link--prev" aria-label="Zurück: 02: Basics" rel="prev">
|
||||||
|
<div class="md-footer__button md-icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||||
|
</div>
|
||||||
|
<div class="md-footer__title">
|
||||||
|
<div class="md-ellipsis">
|
||||||
|
<span class="md-footer__direction">
|
||||||
|
Zurück
|
||||||
|
</span>
|
||||||
|
02: Basics
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a href="04_introduction_to_objects.html" class="md-footer__link md-footer__link--next" aria-label="Weiter: 04: Einführung in Objekte" rel="next">
|
||||||
|
<div class="md-footer__title">
|
||||||
|
<div class="md-ellipsis">
|
||||||
|
<span class="md-footer__direction">
|
||||||
|
Weiter
|
||||||
|
</span>
|
||||||
|
04: Einführung in Objekte
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="md-footer__button md-icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4Z"/></svg>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="md-footer-meta md-typeset">
|
||||||
|
<div class="md-footer-meta__inner md-grid">
|
||||||
|
<div class="md-copyright">
|
||||||
|
|
||||||
|
|
||||||
|
Made with
|
||||||
|
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
|
||||||
|
Material for MkDocs
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="md-dialog" data-md-component="dialog">
|
||||||
|
<div class="md-dialog__inner md-typeset"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script id="__config" type="application/json">{"base": ".", "features": [], "search": "assets/javascripts/workers/search.ecf98df9.min.js", "translations": {"clipboard.copied": "In Zwischenablage kopiert", "clipboard.copy": "In Zwischenablage kopieren", "search.config.lang": "de", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Suche", "search.result.more.one": "1 weiteres Suchergebnis auf dieser Seite", "search.result.more.other": "# weitere Suchergebnisse auf dieser Seite", "search.result.none": "Keine Suchergebnisse", "search.result.one": "1 Suchergebnis", "search.result.other": "# Suchergebnisse", "search.result.placeholder": "Suchbegriff eingeben", "search.result.term.missing": "Es fehlt", "select.version.title": "Version ausw\u00e4hlen"}}</script>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="https://unpkg.com/iframe-worker/polyfill"></script>
|
||||||
|
<script src="search/search_index.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script src="assets/javascripts/bundle.9c69f0bc.min.js"></script>
|
||||||
|
|
||||||
|
<script src="js/print-site.js"></script>
|
||||||
|
|
||||||
|
<script src="js/arithmatex.config.js"></script>
|
||||||
|
|
||||||
|
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,108 @@
|
||||||
|
# 03: Coding Style
|
||||||
|
|
||||||
|
Programme können sehr schnell sehr komplex werden.
|
||||||
|
Daher ist es wichtig, sich an Stil-Regeln zu halten, um sie möglichst
|
||||||
|
verständlich zu schreiben.
|
||||||
|
|
||||||
|
## 1. Selbsterklärend
|
||||||
|
|
||||||
|
Code sollte sich so gut wie möglich selbst erklären.
|
||||||
|
Dazu sind sprechende Variablen-, Funktions-, Klassennamen etc. erforderlich.
|
||||||
|
Kurze Namen sind nur in kleinen Gültigkeitsbereichen oder bei klarer Bedeutung
|
||||||
|
(z.B. `i` für for-Schleifen Iteratoren, `y` für vertikale Position) erlaubt.
|
||||||
|
|
||||||
|
### 1.1 Kommentare
|
||||||
|
|
||||||
|
Kommentare sind in diesem Zusammenhang vorallem zur Strukturierung/Abgrenzung
|
||||||
|
des Codes empfohlen, und um die
|
||||||
|
Verständlichkeit zu erhöhen.
|
||||||
|
Kommentare sollten nicht das Offensichtliche wiederholen (siehe Bild).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Selbstverständlich kann Code zum besseren eigenen Verständnis kommentiert
|
||||||
|
werden.
|
||||||
|
Denken Sie aber daran, dass bei Code Änderungen auch die Kommentare mit gepflegt
|
||||||
|
werden müssen.
|
||||||
|
|
||||||
|
## 4. Benennung
|
||||||
|
|
||||||
|
Die folgenden Regelungen sind empfohlen und in keinster Weise verpflichtend.
|
||||||
|
|
||||||
|
### 4.1 camelCase für Variablen und Funktionen
|
||||||
|
|
||||||
|
Variablen- und Funktionsnamen beginnen mit Kleinbuchstaben und folgen der
|
||||||
|
camelCase Notation, d.h. bei zusammengesetzten
|
||||||
|
Namen beginnen die Wortteile im Inneren mit einem Großbuchstaben.
|
||||||
|
Funktionsnamen beschreiben dabei eine Aktivität (
|
||||||
|
z.B. `calculateHorizontalPosition()`) oder eine Frage (z.B. `isHit()`).
|
||||||
|
|
||||||
|
Gleiches gilt für Attribute und Methoden.
|
||||||
|
|
||||||
|
### 4.2 Unterstrich vor formalen Parametern
|
||||||
|
|
||||||
|
Formale Parameter folgen dem Variablen-Benennungs-Schema, mit dem Zusatz eines
|
||||||
|
Unterstriches am Anfang.
|
||||||
|
(z.B. `moveTo(_x: number, _y: number)`).
|
||||||
|
|
||||||
|
### 4.3 PascalCase für Klassen und Interfaces
|
||||||
|
|
||||||
|
Die Namen von Klassen und Interfaces beginnen mit einem Großbuchstaben und
|
||||||
|
folgen sonst der Kamelnotation (also
|
||||||
|
PascalCase).
|
||||||
|
Klassen und Interfaces beschreiben im Normalfall ein bestimmtes Objekt, nicht
|
||||||
|
eine Gruppe von Objekten.
|
||||||
|
Dies sollte sich im Namen wiederspiegeln (`Produkt` statt `Produkte`).
|
||||||
|
|
||||||
|
### 4.4 Großschreibung für Enumeratoren
|
||||||
|
|
||||||
|
Die Namen von Enumerationen und deren Elemente werden durchgehend mit
|
||||||
|
Großbuchstaben geschreiben. Wortteile werden bei
|
||||||
|
Bedarf mit Unterstrich getrennt.
|
||||||
|
|
||||||
|
## 5. Doppelte und einfache Anführungszeichen
|
||||||
|
|
||||||
|
Es empfielt sich, einfache Anführungszeichen `' '` für char und doppelte
|
||||||
|
Anführungszeichen `" "` für Strings zu verwenden.
|
||||||
|
|
||||||
|
## 6. Formatierung
|
||||||
|
|
||||||
|
Code ist sinnvoll Formatiert mit Einschüben etc.
|
||||||
|
Im Regelfall unterstützt VSCode dies Automatisch. Machen Sie Gebrauch von der
|
||||||
|
automatischen Formatierungsfunktion.
|
||||||
|
|
||||||
|
* [Anleitung für IntelliJ](https://www.jetbrains.com/help/idea/reformat-and-rearrange-code.html#reformat_file)
|
||||||
|
* [Anleitung für Visual Studio Code](https://stackoverflow.com/questions/29973357/how-do-you-format-code-in-visual-studio-code-vscode)
|
||||||
|
* [Anleitung für Eclipse](https://praxistipps.chip.de/eclipse-autoformat-code-so-gehts_98369)
|
||||||
|
|
||||||
|
## 8. "Magische" Zahlen
|
||||||
|
|
||||||
|
Der Gebrauch von "magischen" Zahlen sollte vermieden werden. Solange es nicht
|
||||||
|
extrem offensichtlich ist, wofür eine Zahl
|
||||||
|
steht (z.B. `Math.pow(x, 5)`), sollte eine Variable (nach den oben genannten
|
||||||
|
Guidelines) angelegt werden, welcher die
|
||||||
|
Zahl als Wert zugewiesen wird. So entsteht der Zusammenhang zwischen der
|
||||||
|
Variablen und ihrer Bedeutung, und der Wert
|
||||||
|
kann an einer zentralen Stelle angepasst werden.
|
||||||
|
|
||||||
|
## 9. Dateinamen und -aufteilung
|
||||||
|
|
||||||
|
Dateinamen dürfen keine Leerzeichen oder Umlaute enthalten, sind sonst aber frei
|
||||||
|
wählbar (s.u. für Einschränkungen). Es
|
||||||
|
wird empfohlen, die Zeichenwahl auf a-z, A-Z, 0-9 und _ zu beschränken.
|
||||||
|
Code kann auf mehrere Dateien aufgeteilt werden, sofern dies sinnvoll
|
||||||
|
erscheint (z.B. um eine Trennung von Funktion und
|
||||||
|
Daten zu erreichen). Wenn Klassen verwendet werden, sollte jede ihre eigene
|
||||||
|
Datei bekommen. Sofern eine Datei eine
|
||||||
|
bestimmte Klasse enthält, soll die Datei mit dem Namen der Klasse benannt sein.
|
||||||
|
|
||||||
|
## 10. Wiederholungen sind schlecht
|
||||||
|
|
||||||
|
Code der sich ohne oder nur mit minimalen Änderungen wiederholt, kann in den
|
||||||
|
allermeisten Fällen besser geschrieben
|
||||||
|
werden, z.B. über eine Funktion mit Übergabeparametern, oder indem man nur den
|
||||||
|
geänderten Teil implementiert oder
|
||||||
|
überschreibt, während der Rest für alles gleich generiert wird.
|
||||||
|
Dies hat viele Vorteile: Es macht den Code generell übersichtlicher (und damit
|
||||||
|
besser verständlich), kürzer, und
|
||||||
|
wartungsfreundlicher.
|
|
@ -0,0 +1,932 @@
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="de" class="no-js">
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="icon" href="assets/images/favicon.png">
|
||||||
|
<meta name="generator" content="mkdocs-1.3.1, mkdocs-material-8.4.2">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<title>04: Einführung in Objekte - Markdown Docs</title>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="assets/stylesheets/main.69437709.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="assets/stylesheets/palette.cbb835fc.min.css">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
|
||||||
|
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-enum-headings1.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-enum-headings2.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-enum-headings3.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site.css">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/print-site-material.css">
|
||||||
|
|
||||||
|
<script>__md_scope=new URL(".",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
|
||||||
|
|
||||||
|
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||||
|
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||||
|
<label class="md-overlay" for="__drawer"></label>
|
||||||
|
<div data-md-component="skip">
|
||||||
|
|
||||||
|
|
||||||
|
<a href="#04-einfuhrung-in-objekte" class="md-skip">
|
||||||
|
Zum Inhalt
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div data-md-component="announce">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<header class="md-header" data-md-component="header">
|
||||||
|
<nav class="md-header__inner md-grid" aria-label="Header">
|
||||||
|
<a href="index.html" title="Markdown Docs" class="md-header__button md-logo" aria-label="Markdown Docs" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
<label class="md-header__button md-icon" for="__drawer">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-header__title" data-md-component="header-title">
|
||||||
|
<div class="md-header__ellipsis">
|
||||||
|
<div class="md-header__topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
Markdown Docs
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="md-header__topic" data-md-component="header-topic">
|
||||||
|
<span class="md-ellipsis">
|
||||||
|
|
||||||
|
04: Einführung in Objekte
|
||||||
|
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form class="md-header__option" data-md-component="palette">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_1">
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 6H7c-3.31 0-6 2.69-6 6s2.69 6 6 6h10c3.31 0 6-2.69 6-6s-2.69-6-6-6zm0 10H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h10c2.21 0 4 1.79 4 4s-1.79 4-4 4zM7 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/></svg>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="indigo" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_2">
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 7H7a5 5 0 0 0-5 5 5 5 0 0 0 5 5h10a5 5 0 0 0 5-5 5 5 0 0 0-5-5m0 8a3 3 0 0 1-3-3 3 3 0 0 1 3-3 3 3 0 0 1 3 3 3 3 0 0 1-3 3Z"/></svg>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-header__button md-icon" for="__search">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
|
||||||
|
</label>
|
||||||
|
<div class="md-search" data-md-component="search" role="dialog">
|
||||||
|
<label class="md-search__overlay" for="__search"></label>
|
||||||
|
<div class="md-search__inner" role="search">
|
||||||
|
<form class="md-search__form" name="search">
|
||||||
|
<input type="text" class="md-search__input" name="query" aria-label="Suche" placeholder="Suche" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
|
||||||
|
<label class="md-search__icon md-icon" for="__search">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||||
|
</label>
|
||||||
|
<nav class="md-search__options" aria-label="Suche">
|
||||||
|
|
||||||
|
<button type="reset" class="md-search__icon md-icon" aria-label="Zurücksetzen" tabindex="-1">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
<div class="md-search__output">
|
||||||
|
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||||
|
<div class="md-search-result" data-md-component="search-result">
|
||||||
|
<div class="md-search-result__meta">
|
||||||
|
Suche wird initialisiert
|
||||||
|
</div>
|
||||||
|
<ol class="md-search-result__list"></ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-header__source">
|
||||||
|
<a href="https://github.com/YamiDoesDev/algodat-java-intro" title="Quellcode" class="md-source" data-md-component="source">
|
||||||
|
<div class="md-source__icon md-icon">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.1.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
|
||||||
|
</div>
|
||||||
|
<div class="md-source__repository">
|
||||||
|
GitHub
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="md-container" data-md-component="container">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<main class="md-main" data-md-component="main">
|
||||||
|
<div class="md-main__inner md-grid">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
|
||||||
|
<label class="md-nav__title" for="__drawer">
|
||||||
|
<a href="index.html" title="Markdown Docs" class="md-nav__button md-logo" aria-label="Markdown Docs" data-md-component="logo">
|
||||||
|
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>
|
||||||
|
|
||||||
|
</a>
|
||||||
|
Markdown Docs
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="md-nav__source">
|
||||||
|
<a href="https://github.com/YamiDoesDev/algodat-java-intro" title="Quellcode" class="md-source" data-md-component="source">
|
||||||
|
<div class="md-source__icon md-icon">
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.1.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
|
||||||
|
</div>
|
||||||
|
<div class="md-source__repository">
|
||||||
|
GitHub
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="md-nav__list" data-md-scrollfix>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="index.html" class="md-nav__link">
|
||||||
|
Crashkurs Java im Modul Algorithmen und Datenstrukturen
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="01_hello_world.html" class="md-nav__link">
|
||||||
|
01: Hello World
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="02_basics.html" class="md-nav__link">
|
||||||
|
02: Basics
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="03_coding_style.html" class="md-nav__link">
|
||||||
|
03: Coding Style
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item md-nav__item--active">
|
||||||
|
|
||||||
|
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||||
|
04: Einführung in Objekte
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<a href="04_introduction_to_objects.html" class="md-nav__link md-nav__link--active">
|
||||||
|
04: Einführung in Objekte
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Inhaltsverzeichnis">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__title" for="__toc">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Inhaltsverzeichnis
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#kurze-begriffserklarung" class="md-nav__link">
|
||||||
|
Kurze Begriffserklärung
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<nav class="md-nav" aria-label="Kurze Begriffserklärung">
|
||||||
|
<ul class="md-nav__list">
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#declaration" class="md-nav__link">
|
||||||
|
Declaration
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#initialization" class="md-nav__link">
|
||||||
|
Initialization
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#instantiation" class="md-nav__link">
|
||||||
|
Instantiation
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#1-einfache-objekte-und-veerbung" class="md-nav__link">
|
||||||
|
#1 Einfache Objekte und Veerbung
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#2-komplexere-vererbung-von-klassen" class="md-nav__link">
|
||||||
|
#2 komplexere Vererbung von Klassen
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#3-static-in-einer-klasse" class="md-nav__link">
|
||||||
|
#3 static in einer Klasse
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="05_types_of_objects.html" class="md-nav__link">
|
||||||
|
05: Typen von Objekten
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="06_java_docs.html" class="md-nav__link">
|
||||||
|
06: JavaDoc
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="print_page.html" class="md-nav__link">
|
||||||
|
Print as PDF
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
|
||||||
|
<div class="md-sidebar__scrollwrap">
|
||||||
|
<div class="md-sidebar__inner">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-nav md-nav--secondary" aria-label="Inhaltsverzeichnis">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<label class="md-nav__title" for="__toc">
|
||||||
|
<span class="md-nav__icon md-icon"></span>
|
||||||
|
Inhaltsverzeichnis
|
||||||
|
</label>
|
||||||
|
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#kurze-begriffserklarung" class="md-nav__link">
|
||||||
|
Kurze Begriffserklärung
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<nav class="md-nav" aria-label="Kurze Begriffserklärung">
|
||||||
|
<ul class="md-nav__list">
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#declaration" class="md-nav__link">
|
||||||
|
Declaration
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#initialization" class="md-nav__link">
|
||||||
|
Initialization
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#instantiation" class="md-nav__link">
|
||||||
|
Instantiation
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#1-einfache-objekte-und-veerbung" class="md-nav__link">
|
||||||
|
#1 Einfache Objekte und Veerbung
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#2-komplexere-vererbung-von-klassen" class="md-nav__link">
|
||||||
|
#2 komplexere Vererbung von Klassen
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="#3-static-in-einer-klasse" class="md-nav__link">
|
||||||
|
#3 static in einer Klasse
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-content" data-md-component="content">
|
||||||
|
<article class="md-content__inner md-typeset">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a href="https://github.com/YamiDoesDev/algodat-java-intro/edit/main/docs/04_introduction_to_objects.md" title="Seite editieren" class="md-content__button md-icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25Z"/></svg>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h1 id="04-einfuhrung-in-objekte">04: Einführung in Objekte</h1>
|
||||||
|
<h2 id="kurze-begriffserklarung">Kurze Begriffserklärung</h2>
|
||||||
|
<p>Quelle: <a href="https://stackhowto.com/difference-between-instantiating-declaring-and-initializing/">stackhowto.com</a></p>
|
||||||
|
<h3 id="declaration">Declaration</h3>
|
||||||
|
<blockquote>
|
||||||
|
<p>Declaring a variable means the first “mention” of the variable, which tells the compiler “Hello, I am here and can be used”.
|
||||||
|
In a statically typed language like Java, this also means that the declared type of the variable is determined.
|
||||||
|
The value itself is not determined during the declaration.
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="n">String</span><span class="w"> </span><span class="n">name</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="kt">int</span><span class="w"> </span><span class="n">nbr</span><span class="p">;</span><span class="w"></span>
|
||||||
|
</code></pre></div></p>
|
||||||
|
</blockquote>
|
||||||
|
<h3 id="initialization">Initialization</h3>
|
||||||
|
<blockquote>
|
||||||
|
<p>The term initialization usually means the first assignment of a value to a variable.
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="n">String</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"Thomas"</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="kt">int</span><span class="w"> </span><span class="n">nbr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span><span class="w"></span>
|
||||||
|
</code></pre></div></p>
|
||||||
|
</blockquote>
|
||||||
|
<h3 id="instantiation">Instantiation</h3>
|
||||||
|
<blockquote>
|
||||||
|
<p>The term instantiation actually has nothing to do with assigning a value to a variable, even if a new object is sometimes instantiated when a variable is initialized.
|
||||||
|
The term simply means the creation of a new object, i.e. an instance, from a class.
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="n">String</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">String</span><span class="p">(</span><span class="s">"Thomas"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
</code></pre></div></p>
|
||||||
|
</blockquote>
|
||||||
|
<h2 id="1-einfache-objekte-und-veerbung">#1 Einfache Objekte und Veerbung</h2>
|
||||||
|
<p><strong>Lernziele:</strong>
|
||||||
|
* eine Klasse erzeugen
|
||||||
|
* eine Klasse aufrufen
|
||||||
|
* einfache Veerbung
|
||||||
|
* Polymorphie (Überschreiben von Methoden)
|
||||||
|
* die Verwendung von <code>this</code>
|
||||||
|
* die Verwendung von <code>super</code></p>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="c1">// main.java</span><span class="w"></span>
|
||||||
|
<span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Main</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">Animal</span><span class="w"> </span><span class="n">myAnimal</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Animal</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">myAnimal</span><span class="p">.</span><span class="na">makeSound</span><span class="p">();</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="n">Dog</span><span class="w"> </span><span class="n">myDog</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Dog</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">myDog</span><span class="p">.</span><span class="na">makeSound</span><span class="p">();</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="n">Cat</span><span class="w"> </span><span class="n">myCat</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Cat</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">myCat</span><span class="p">.</span><span class="na">makeSound</span><span class="p">();</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="n">myCat</span><span class="p">.</span><span class="na">compareToAnimal</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="c1">// Animal.java</span><span class="w"></span>
|
||||||
|
<span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Animal</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">boolean</span><span class="w"> </span><span class="n">isPet</span><span class="p">;</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="nf">Animal</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"## in constructor of Animal"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">isPet</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span><span class="w"> </span><span class="c1">// it doesn't exist for our cats or dogs</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">makeSound</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"Yes, animal usually make sounds"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<p><div class="highlight"><pre><span></span><code><span class="c1">// Cat.java</span><span class="w"></span>
|
||||||
|
<span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Cat</span><span class="w"> </span><span class="kd">extends</span><span class="w"> </span><span class="n">Animal</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="nf">Cat</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"## in constructor of Cat"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">isPet</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="nd">@Override</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">makeSound</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"meow meow"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">compareToAnimal</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"--- Animal ---"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">super</span><span class="p">.</span><span class="na">makeSound</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"is alive: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="kd">super</span><span class="p">.</span><span class="na">isPet</span><span class="p">);</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"--- Cat ---"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">makeSound</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"is alive: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">isPet</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="c1">// Dog.java</span><span class="w"></span>
|
||||||
|
<span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Dog</span><span class="w"> </span><span class="kd">extends</span><span class="w"> </span><span class="n">Animal</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="nf">Dog</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"## in constructor of Dog"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">isPet</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="nd">@Override</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">makeSound</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"woof woof"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">isPet</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">compareToAnimal</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"--- Animal ---"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">super</span><span class="p">.</span><span class="na">makeSound</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"is alive: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="kd">super</span><span class="p">.</span><span class="na">isPet</span><span class="p">);</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"--- Cat ---"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">makeSound</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"is alive: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">isPet</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div></p>
|
||||||
|
<h2 id="2-komplexere-vererbung-von-klassen">#2 komplexere Vererbung von Klassen</h2>
|
||||||
|
<p><strong>Lernziele:</strong>
|
||||||
|
* Erweiterte Veerbung
|
||||||
|
* Modifikatoren für Attribute
|
||||||
|
* Getter und Setter
|
||||||
|
* Konstruktorverkettung</p>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="c1">// main.java</span><span class="w"></span>
|
||||||
|
<span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Main</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">Vehicle</span><span class="w"> </span><span class="n">myVehicle</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Vehicle</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"-- myVehicle:"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"number of wheels: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">myVehicle</span><span class="p">.</span><span class="na">getNumberOfWheels</span><span class="p">());</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"max Speed: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">myVehicle</span><span class="p">.</span><span class="na">getMaxSpeed</span><span class="p">());</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">myVehicle</span><span class="p">.</span><span class="na">setMaxSpeed</span><span class="p">(</span><span class="mi">150</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"max Speed: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">myVehicle</span><span class="p">.</span><span class="na">getMaxSpeed</span><span class="p">());</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="n">Car</span><span class="w"> </span><span class="n">myCar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Car</span><span class="p">(</span><span class="s">"blue"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"-- myCar:"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"number of wheels: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">myCar</span><span class="p">.</span><span class="na">getNumberOfWheels</span><span class="p">());</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"max Speed: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">myCar</span><span class="p">.</span><span class="na">getMaxSpeed</span><span class="p">());</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">myVehicle</span><span class="p">.</span><span class="na">setMaxSpeed</span><span class="p">(</span><span class="mi">150</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"max Speed: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">myCar</span><span class="p">.</span><span class="na">getMaxSpeed</span><span class="p">());</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Vehicle</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">protected</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">numberOfWheels</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">protected</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">maxSpeed</span><span class="p">;</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="nf">Vehicle</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"## in default constructor of Vehicle"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">numberOfWheels</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">maxSpeed</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">100</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="nf">Vehicle</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">numberOfWheels</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">maxSpeed</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"## in constructor of Vehicle"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">numberOfWheels</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">numberOfWheels</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">maxSpeed</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">maxSpeed</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">getNumberOfWheels</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">numberOfWheels</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">getMaxSpeed</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">maxSpeed</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="nf">printMaxSpeed</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">maxSpeed</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">" km/h"</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setMaxSpeed</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">newMaxSpeed</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">newMaxSpeed</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">return</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">maxSpeed</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">newMaxSpeed</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Car</span><span class="w"> </span><span class="kd">extends</span><span class="w"> </span><span class="n">Vehicle</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">color</span><span class="p">;</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="nf">Car</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">color</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">super</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">200</span><span class="p">);</span><span class="w"> </span><span class="c1">// always needs to be the first statement</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"## in constructor of Car"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">color</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="nd">@Override</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setMaxSpeed</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">newMaxSpeed</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">newMaxSpeed</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">1000</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"No car shall be this slow tbh"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">return</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">maxSpeed</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">newMaxSpeed</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Car</span><span class="w"> </span><span class="kd">extends</span><span class="w"> </span><span class="n">Vehicle</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">color</span><span class="p">;</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="nf">Car</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">color</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">super</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">200</span><span class="p">);</span><span class="w"> </span><span class="c1">// always needs to be the first statement</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"## in constructor of Car"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">color</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">color</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="nd">@Override</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">setMaxSpeed</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">newMaxSpeed</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">newMaxSpeed</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">1000</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"No car shall be this slow tbh"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">return</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">maxSpeed</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">newMaxSpeed</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Truck</span><span class="w"> </span><span class="kd">extends</span><span class="w"> </span><span class="n">Vehicle</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="kt">boolean</span><span class="w"> </span><span class="n">isFireTruck</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="kd">final</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">hornSound</span><span class="p">;</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="nf">Truck</span><span class="p">(</span><span class="kt">boolean</span><span class="w"> </span><span class="n">isFireTruck</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">super</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">200</span><span class="p">);</span><span class="w"> </span><span class="c1">// always needs to be the first statement</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"## in constructor of Truck"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">isFireTruck</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">isFireTruck</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">hornSound</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"test"</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">boolean</span><span class="w"> </span><span class="nf">getIsFireTruck</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">isFireTruck</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<h2 id="3-static-in-einer-klasse">#3 <code>static</code> in einer Klasse</h2>
|
||||||
|
<p><strong>Lernziele:</strong>
|
||||||
|
* statische und dynamische Variablen
|
||||||
|
* statische und dynamische Methoden</p>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="c1">// main.java</span><span class="w"></span>
|
||||||
|
<span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Main</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">Counter</span><span class="p">.</span><span class="na">printCounterStatic</span><span class="p">(</span><span class="s">"Static"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">Counter</span><span class="p">.</span><span class="na">increaseCounterStatic</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">Counter</span><span class="p">.</span><span class="na">printCounterStatic</span><span class="p">(</span><span class="s">"Static"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="n">Counter</span><span class="w"> </span><span class="n">myCounter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Counter</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">Counter</span><span class="p">.</span><span class="na">increaseCounterStatic</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">myCounter</span><span class="p">.</span><span class="na">increaseCounterDynamic</span><span class="p">();</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">myCounter</span><span class="p">.</span><span class="na">printCounterDynamic</span><span class="p">(</span><span class="s">"Dynamic"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Counter</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">counterValueStatic</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">counterValueDynamic</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">increaseCounterStatic</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">counterValueStatic</span><span class="o">++</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">increaseCounterDynamic</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">counterValueDynamic</span><span class="o">++</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">printCounterDynamic</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">classID</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">">> execute printCounterDynamic of class "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">classID</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"static: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">counterValueStatic</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"dynamic: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">counterValueDynamic</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">printCounterStatic</span><span class="p">(</span><span class="n">String</span><span class="w"> </span><span class="n">classID</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">">> execute printCounterStatic of class "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">classID</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">"dynamic: "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">counterValueStatic</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<div class="md-source-file">
|
||||||
|
<small>
|
||||||
|
|
||||||
|
Letztes Update:
|
||||||
|
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">November 2, 2022 20:46:05</span>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
Erstellt:
|
||||||
|
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">November 2, 2022 20:46:05</span>
|
||||||
|
|
||||||
|
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="md-source-date">
|
||||||
|
<small>
|
||||||
|
Authors: <span class='git-page-authors git-authors'><a href='mailto:yamidoesdev@gmail.com'>YamiDoesDev</a></span>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</article>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="md-footer">
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="md-footer__inner md-grid" aria-label="Footer" >
|
||||||
|
|
||||||
|
|
||||||
|
<a href="03_coding_style.html" class="md-footer__link md-footer__link--prev" aria-label="Zurück: 03: Coding Style" rel="prev">
|
||||||
|
<div class="md-footer__button md-icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||||
|
</div>
|
||||||
|
<div class="md-footer__title">
|
||||||
|
<div class="md-ellipsis">
|
||||||
|
<span class="md-footer__direction">
|
||||||
|
Zurück
|
||||||
|
</span>
|
||||||
|
03: Coding Style
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a href="05_types_of_objects.html" class="md-footer__link md-footer__link--next" aria-label="Weiter: 05: Typen von Objekten" rel="next">
|
||||||
|
<div class="md-footer__title">
|
||||||
|
<div class="md-ellipsis">
|
||||||
|
<span class="md-footer__direction">
|
||||||
|
Weiter
|
||||||
|
</span>
|
||||||
|
05: Typen von Objekten
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="md-footer__button md-icon">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4Z"/></svg>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="md-footer-meta md-typeset">
|
||||||
|
<div class="md-footer-meta__inner md-grid">
|
||||||
|
<div class="md-copyright">
|
||||||
|
|
||||||
|
|
||||||
|
Made with
|
||||||
|
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
|
||||||
|
Material for MkDocs
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="md-dialog" data-md-component="dialog">
|
||||||
|
<div class="md-dialog__inner md-typeset"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script id="__config" type="application/json">{"base": ".", "features": [], "search": "assets/javascripts/workers/search.ecf98df9.min.js", "translations": {"clipboard.copied": "In Zwischenablage kopiert", "clipboard.copy": "In Zwischenablage kopieren", "search.config.lang": "de", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Suche", "search.result.more.one": "1 weiteres Suchergebnis auf dieser Seite", "search.result.more.other": "# weitere Suchergebnisse auf dieser Seite", "search.result.none": "Keine Suchergebnisse", "search.result.one": "1 Suchergebnis", "search.result.other": "# Suchergebnisse", "search.result.placeholder": "Suchbegriff eingeben", "search.result.term.missing": "Es fehlt", "select.version.title": "Version ausw\u00e4hlen"}}</script>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="https://unpkg.com/iframe-worker/polyfill"></script>
|
||||||
|
<script src="search/search_index.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script src="assets/javascripts/bundle.9c69f0bc.min.js"></script>
|
||||||
|
|
||||||
|
<script src="js/print-site.js"></script>
|
||||||
|
|
||||||
|
<script src="js/arithmatex.config.js"></script>
|
||||||
|
|
||||||
|
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,302 @@
|
||||||
|
# 04: Einführung in Objekte
|
||||||
|
|
||||||
|
## Kurze Begriffserklärung
|
||||||
|
|
||||||
|
Quelle: [stackhowto.com](https://stackhowto.com/difference-between-instantiating-declaring-and-initializing/)
|
||||||
|
|
||||||
|
### Declaration
|
||||||
|
> Declaring a variable means the first “mention” of the variable, which tells the compiler “Hello, I am here and can be used”.
|
||||||
|
> In a statically typed language like Java, this also means that the declared type of the variable is determined.
|
||||||
|
> The value itself is not determined during the declaration.
|
||||||
|
```java
|
||||||
|
String name;
|
||||||
|
int nbr;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Initialization
|
||||||
|
> The term initialization usually means the first assignment of a value to a variable.
|
||||||
|
```java
|
||||||
|
String name = "Thomas";
|
||||||
|
int nbr = 5;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Instantiation
|
||||||
|
> The term instantiation actually has nothing to do with assigning a value to a variable, even if a new object is sometimes instantiated when a variable is initialized.
|
||||||
|
> The term simply means the creation of a new object, i.e. an instance, from a class.
|
||||||
|
```java
|
||||||
|
String name = new String("Thomas");
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## #1 Einfache Objekte und Veerbung
|
||||||
|
**Lernziele:**
|
||||||
|
* eine Klasse erzeugen
|
||||||
|
* eine Klasse aufrufen
|
||||||
|
* einfache Veerbung
|
||||||
|
* Polymorphie (Überschreiben von Methoden)
|
||||||
|
* die Verwendung von `this`
|
||||||
|
* die Verwendung von `super`
|
||||||
|
|
||||||
|
```java
|
||||||
|
// main.java
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Animal myAnimal = new Animal();
|
||||||
|
myAnimal.makeSound();
|
||||||
|
|
||||||
|
Dog myDog = new Dog();
|
||||||
|
myDog.makeSound();
|
||||||
|
|
||||||
|
Cat myCat = new Cat();
|
||||||
|
myCat.makeSound();
|
||||||
|
|
||||||
|
myCat.compareToAnimal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Animal.java
|
||||||
|
public class Animal {
|
||||||
|
public boolean isPet;
|
||||||
|
|
||||||
|
public Animal() {
|
||||||
|
System.out.println("## in constructor of Animal");
|
||||||
|
this.isPet = false; // it doesn't exist for our cats or dogs
|
||||||
|
}
|
||||||
|
|
||||||
|
public void makeSound() {
|
||||||
|
System.out.println("Yes, animal usually make sounds");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Cat.java
|
||||||
|
public class Cat extends Animal {
|
||||||
|
|
||||||
|
public Cat() {
|
||||||
|
System.out.println("## in constructor of Cat");
|
||||||
|
this.isPet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void makeSound() {
|
||||||
|
System.out.println("meow meow");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void compareToAnimal() {
|
||||||
|
System.out.println("--- Animal ---");
|
||||||
|
super.makeSound();
|
||||||
|
System.out.println("is alive: " + super.isPet);
|
||||||
|
|
||||||
|
System.out.println("--- Cat ---");
|
||||||
|
this.makeSound();
|
||||||
|
System.out.println("is alive: " + this.isPet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
```java
|
||||||
|
// Dog.java
|
||||||
|
public class Dog extends Animal {
|
||||||
|
|
||||||
|
public Dog() {
|
||||||
|
System.out.println("## in constructor of Dog");
|
||||||
|
this.isPet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void makeSound() {
|
||||||
|
System.out.println("woof woof");
|
||||||
|
this.isPet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void compareToAnimal() {
|
||||||
|
System.out.println("--- Animal ---");
|
||||||
|
super.makeSound();
|
||||||
|
System.out.println("is alive: " + super.isPet);
|
||||||
|
|
||||||
|
System.out.println("--- Cat ---");
|
||||||
|
this.makeSound();
|
||||||
|
System.out.println("is alive: " + this.isPet);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## #2 komplexere Vererbung von Klassen
|
||||||
|
|
||||||
|
**Lernziele:**
|
||||||
|
* Erweiterte Veerbung
|
||||||
|
* Modifikatoren für Attribute
|
||||||
|
* Getter und Setter
|
||||||
|
* Konstruktorverkettung
|
||||||
|
|
||||||
|
```java
|
||||||
|
// main.java
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Vehicle myVehicle = new Vehicle();
|
||||||
|
System.out.println("-- myVehicle:");
|
||||||
|
System.out.println("number of wheels: " + myVehicle.getNumberOfWheels());
|
||||||
|
System.out.println("max Speed: " + myVehicle.getMaxSpeed());
|
||||||
|
myVehicle.setMaxSpeed(150);
|
||||||
|
System.out.println("max Speed: " + myVehicle.getMaxSpeed());
|
||||||
|
|
||||||
|
Car myCar = new Car("blue");
|
||||||
|
System.out.println("-- myCar:");
|
||||||
|
System.out.println("number of wheels: " + myCar.getNumberOfWheels());
|
||||||
|
System.out.println("max Speed: " + myCar.getMaxSpeed());
|
||||||
|
myVehicle.setMaxSpeed(150);
|
||||||
|
System.out.println("max Speed: " + myCar.getMaxSpeed());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Vehicle {
|
||||||
|
protected int numberOfWheels;
|
||||||
|
protected int maxSpeed;
|
||||||
|
|
||||||
|
public Vehicle() {
|
||||||
|
System.out.println("## in default constructor of Vehicle");
|
||||||
|
this.numberOfWheels = 4;
|
||||||
|
this.maxSpeed = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vehicle(int numberOfWheels, int maxSpeed) {
|
||||||
|
System.out.println("## in constructor of Vehicle");
|
||||||
|
this.numberOfWheels = numberOfWheels;
|
||||||
|
this.maxSpeed = maxSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumberOfWheels() {
|
||||||
|
return this.numberOfWheels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxSpeed() {
|
||||||
|
return this.maxSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String printMaxSpeed() {
|
||||||
|
return this.maxSpeed + " km/h";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxSpeed(int newMaxSpeed) {
|
||||||
|
if (newMaxSpeed < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.maxSpeed = newMaxSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Car extends Vehicle {
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
public Car(String color) {
|
||||||
|
super(4, 200); // always needs to be the first statement
|
||||||
|
System.out.println("## in constructor of Car");
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMaxSpeed(int newMaxSpeed) {
|
||||||
|
if (newMaxSpeed < 1000) {
|
||||||
|
System.out.println("No car shall be this slow tbh");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.maxSpeed = newMaxSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Car extends Vehicle {
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
public Car(String color) {
|
||||||
|
super(4, 200); // always needs to be the first statement
|
||||||
|
System.out.println("## in constructor of Car");
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMaxSpeed(int newMaxSpeed) {
|
||||||
|
if (newMaxSpeed < 1000) {
|
||||||
|
System.out.println("No car shall be this slow tbh");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.maxSpeed = newMaxSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Truck extends Vehicle {
|
||||||
|
private boolean isFireTruck;
|
||||||
|
private final String hornSound;
|
||||||
|
|
||||||
|
public Truck(boolean isFireTruck) {
|
||||||
|
super(4, 200); // always needs to be the first statement
|
||||||
|
System.out.println("## in constructor of Truck");
|
||||||
|
this.isFireTruck = isFireTruck;
|
||||||
|
this.hornSound = "test";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getIsFireTruck() {
|
||||||
|
return this.isFireTruck;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## #3 `static` in einer Klasse
|
||||||
|
|
||||||
|
**Lernziele:**
|
||||||
|
* statische und dynamische Variablen
|
||||||
|
* statische und dynamische Methoden
|
||||||
|
|
||||||
|
```java
|
||||||
|
// main.java
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Counter.printCounterStatic("Static");
|
||||||
|
Counter.increaseCounterStatic();
|
||||||
|
Counter.printCounterStatic("Static");
|
||||||
|
|
||||||
|
Counter myCounter = new Counter();
|
||||||
|
Counter.increaseCounterStatic();
|
||||||
|
myCounter.increaseCounterDynamic();
|
||||||
|
myCounter.printCounterDynamic("Dynamic");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Counter {
|
||||||
|
static int counterValueStatic = 0;
|
||||||
|
int counterValueDynamic = 0;
|
||||||
|
|
||||||
|
public static void increaseCounterStatic() {
|
||||||
|
counterValueStatic++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void increaseCounterDynamic() {
|
||||||
|
this.counterValueDynamic++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printCounterDynamic(String classID) {
|
||||||
|
System.out.println(">> execute printCounterDynamic of class " + classID);
|
||||||
|
System.out.println("static: " + counterValueStatic);
|
||||||
|
System.out.println("dynamic: " + this.counterValueDynamic);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void printCounterStatic(String classID) {
|
||||||
|
System.out.println(">> execute printCounterStatic of class " + classID);
|
||||||
|
System.out.println("dynamic: " + counterValueStatic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,286 @@
|
||||||
|
# 05: Typen von Objekten
|
||||||
|
|
||||||
|
## Enumerations
|
||||||
|
|
||||||
|
```java
|
||||||
|
// SecurityLevel.java
|
||||||
|
public enum SecurityLevel {
|
||||||
|
LOW,
|
||||||
|
MEDIUM,
|
||||||
|
HIGH;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Main.java
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SecurityLevel networkSecurity = SecurityLevel.MEDIUM;
|
||||||
|
|
||||||
|
// comparing enum items
|
||||||
|
System.out.println(networkSecurity == SecurityLevel.HIGH); // false
|
||||||
|
System.out.println(networkSecurity.compareTo(SecurityLevel.LOW)); // 1
|
||||||
|
System.out.println(networkSecurity.compareTo(SecurityLevel.MEDIUM)); // 0
|
||||||
|
System.out.println(networkSecurity.compareTo(SecurityLevel.HIGH)); // -1
|
||||||
|
|
||||||
|
// print all possible values
|
||||||
|
for(SecurityLevel value : SecurityLevel.values()) {
|
||||||
|
System.out.println(value.ordinal() + " " + value.name() + " " + value);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (networkSecurity) {
|
||||||
|
case LOW:
|
||||||
|
System.out.println("The network security MUST be increased!");
|
||||||
|
break;
|
||||||
|
case MEDIUM:
|
||||||
|
System.out.println("The network security needs improvements");
|
||||||
|
break;
|
||||||
|
case HIGH:
|
||||||
|
System.out.println("The network security is good so far");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Generics
|
||||||
|
|
||||||
|
```java
|
||||||
|
// Main.java
|
||||||
|
public class Main /*extends Language implements Regex*/ {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
SaveState<String> stateFirst = new SaveState<String>("Begin of the story");
|
||||||
|
SaveState<String> stateSecond = new SaveState<String>("Near last boss fight");
|
||||||
|
|
||||||
|
System.out.println(stateFirst);
|
||||||
|
System.out.println(stateSecond);
|
||||||
|
|
||||||
|
System.out.println("second state bigger? " + stateSecond.compareTo(stateFirst));
|
||||||
|
System.out.println("first state bigger? " + stateFirst.compareTo(stateSecond));
|
||||||
|
|
||||||
|
stateFirst.setSaveState("Finished tutorial");
|
||||||
|
System.out.println(stateFirst.getSaveState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Abstract and Interface
|
||||||
|
```java
|
||||||
|
// Regex.java
|
||||||
|
public interface Regex {
|
||||||
|
public String concatStrings(String left, String right);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
```java
|
||||||
|
// Main.java
|
||||||
|
abstract class Language {
|
||||||
|
public void showLanguage() {
|
||||||
|
System.out.println("This text is presented to you by Java");
|
||||||
|
}
|
||||||
|
public abstract void sayHelloWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main.java
|
||||||
|
public class Main extends Language implements Regex {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Language myLanguage = new Language();
|
||||||
|
// 'Language' is abstract; cannot be instantiated
|
||||||
|
|
||||||
|
Main myObject = new Main();
|
||||||
|
myObject.sayHelloWorld();
|
||||||
|
|
||||||
|
String wortwitz = myObject.concatStrings("du", "schlampe");
|
||||||
|
System.out.println(wortwitz); // duschlampe
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sayHelloWorld() {
|
||||||
|
System.out.println("I refuse to say that!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String concatStrings(String left, String right) {
|
||||||
|
return left + right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
```java
|
||||||
|
// SaveState.java
|
||||||
|
|
||||||
|
import java.security.InvalidParameterException;
|
||||||
|
|
||||||
|
public class SaveState<T> implements Comparable<SaveState> {
|
||||||
|
private T saveEntry;
|
||||||
|
private int saveID = 0;
|
||||||
|
private static int staticSaveID;
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
SaveState(T saveEntry) throws InvalidParameterException {
|
||||||
|
if(saveEntry == null) throw new InvalidParameterException("entry shall not be null");
|
||||||
|
this.saveEntry = saveEntry;
|
||||||
|
this.saveID = staticSaveID;
|
||||||
|
staticSaveID++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSaveID() {
|
||||||
|
return this.saveID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getSaveState() {
|
||||||
|
return this.saveEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSaveState(T saveEntry) throws InvalidParameterException {
|
||||||
|
if(saveEntry == null) throw new InvalidParameterException("entry shall not be null");
|
||||||
|
this.saveEntry = saveEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
try {
|
||||||
|
return this.saveID + ": " + this.saveEntry.toString();
|
||||||
|
} catch (Exception exception) {
|
||||||
|
System.out.println("T.toString() for Class " + saveEntry.getClass() + " does not exist");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(SaveState object) {
|
||||||
|
if (this.saveID > object.getSaveID()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (this.saveID < object.getSaveID()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Collections
|
||||||
|
|
||||||
|
```java
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
// Main.java
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String[] alphabet = {
|
||||||
|
"bee",
|
||||||
|
"apple",
|
||||||
|
"clown"
|
||||||
|
};
|
||||||
|
System.out.println( Arrays.toString(alphabet) );
|
||||||
|
|
||||||
|
ArrayList<String> myArrayList = new ArrayList<String>();
|
||||||
|
TreeSet<String> myTreeSet = new TreeSet<String>();
|
||||||
|
HashMap<Integer, String> myHashMap = new HashMap<>();
|
||||||
|
|
||||||
|
for(String selection: alphabet) {
|
||||||
|
myArrayList.add(selection);
|
||||||
|
myTreeSet.add(selection);
|
||||||
|
myHashMap.put(myHashMap.size(), selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Integer> mapKeys = myHashMap.keySet();
|
||||||
|
System.out.println(mapKeys);
|
||||||
|
|
||||||
|
Collection<String> mapValues = myHashMap.values();
|
||||||
|
System.out.println(mapValues);
|
||||||
|
|
||||||
|
Iterator<String> arrayListIterator = myArrayList.iterator();
|
||||||
|
Iterator<String> treeSetIterator = myTreeSet.iterator();
|
||||||
|
Iterator<String> hashMapIterator = myHashMap.values().iterator();
|
||||||
|
|
||||||
|
System.out.println("--- arrayList ---");
|
||||||
|
for (String selectedValue: myArrayList) {
|
||||||
|
System.out.println(selectedValue);
|
||||||
|
}
|
||||||
|
System.out.println("--- arrayListIterator ---");
|
||||||
|
while (arrayListIterator.hasNext()) {
|
||||||
|
System.out.println(arrayListIterator.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("--- treeSet ---");
|
||||||
|
for (String selectedValue: myTreeSet) {
|
||||||
|
ystem.out.println(selectedValue);
|
||||||
|
}
|
||||||
|
System.out.println("--- treeSetIterator ---");
|
||||||
|
while (treeSetIterator.hasNext()) {
|
||||||
|
System.out.println(treeSetIterator.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("--- hashMap ---");
|
||||||
|
for (Map.Entry<Integer, String> pair : myHashMap.entrySet()) {
|
||||||
|
System.out.println(pair.getKey() + ": " + pair.getValue());
|
||||||
|
}
|
||||||
|
System.out.println("--- hashMapIterator ---");
|
||||||
|
while (hashMapIterator.hasNext()) {
|
||||||
|
System.out.println(hashMapIterator.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* List - für beliebig große Listen, deren Elemente auch über einen Index zugegriffen werden können,
|
||||||
|
* `ArrayList` - Indizierte Liste, deren Größe dynamisch verändert werden kann. Indexzugriffe sind schnell, Größenänderungen sind aufwändig.
|
||||||
|
* `LinkedList` - Verkettete Liste. Indexzugriffe sind langsam, Einfügen und Löschen ist schnell.
|
||||||
|
* Set - zur Darstellung von Mengen
|
||||||
|
* `HashSet` - ungeordnete Datenmenge (ohne Duplikate)
|
||||||
|
* `TreeSet` - Sortierte Menge.
|
||||||
|
* Map - für Paare von Daten verschiedenen Typs.
|
||||||
|
* `HashMap` - Menge von (Schlüssel,Wert)-Paaren
|
||||||
|
* `TreeMap` - nach Schlüsseln sortierte Menge von (Schlüssel,Wert)-Paaren
|
||||||
|
|
||||||
|
### Collection Interface (List, Set, Map)
|
||||||
|
|
||||||
|
| Methode | Beschreibung |
|
||||||
|
|---------------------------------|---------------------------------------------------------------|
|
||||||
|
| int size() | liefert die Anzahl der Einträge |
|
||||||
|
| boolean isEmpty() | prüft, ob keine Einträge vorhanden sind |
|
||||||
|
| boolean contains(Object o) | prüft, ob o eingetragen ist |
|
||||||
|
| boolean add(Object o) | prüft, ob alle Elemente aus c enthalten sind |
|
||||||
|
| boolean addAll(Collection c) | trägt alle Elemente aus c ein (optional) |
|
||||||
|
| boolean remove(Object o) | entfernt o (optional) |
|
||||||
|
| boolean removeAll(Collection c) | entfernt die in c angegebenen Elemente (optional) |
|
||||||
|
| boolean retainAll(Collection c) | entfernt alle Elemente, außer die in c angegebenen (optional) |
|
||||||
|
| boolean equals(Object o) | prüft, ob o mit der Collection übereinstimmt |
|
||||||
|
| Iterator iterator() | erzeugt einen Iterator |
|
||||||
|
| void clear() | entfernt alle Elemente (optional) |
|
||||||
|
|
||||||
|
### List Interface
|
||||||
|
|
||||||
|
| Methode | Beschreibung |
|
||||||
|
|-----------------------|----------------------------------------------------------|
|
||||||
|
| Object get(int i) | liefert das Element an Position i (ohne es zu entfernen) |
|
||||||
|
| int indexOf(Object o) | liefert den Index des ersten Vorkommens von o oder -1 |
|
||||||
|
|
||||||
|
### Map Interface
|
||||||
|
|
||||||
|
| Methode | Beschreibung |
|
||||||
|
|--------------------------------------|-----------------------------------------------------------|
|
||||||
|
| boolean containsKey(Object key) | prüft, ob ein Datenpaar mit Schlüssel key eingetragen ist |
|
||||||
|
| boolean containsValue(Object value) | prüft, ob ein Datenpaar mit Wert value eingetragen ist |
|
||||||
|
| Object get(Object key) | liefert den eingetragenen Wert zum Schlüssen key |
|
||||||
|
| Object put(Object key, Object value) | trägt das Datenpaar(key,value) ein (optional) |
|
||||||
|
| boolean remove(Object key) | entfernt das Datenpaar mit Schlüssel key (optional) |
|
||||||
|
|
||||||
|
### Iteratoren (List, Set)
|
||||||
|
|
||||||
|
| Methode | Beschreibung |
|
||||||
|
|-------------------|-------------------------------------------------|
|
||||||
|
| boolean hasNext() | prüft, ob ein weiteres Element existiert |
|
||||||
|
| Object next() | liefert das nächste Element und schaltet weiter |
|
||||||
|
| void remove() | löscht das aktuelle Element |
|
||||||
|
|
||||||
|
### ListIterator (List)
|
||||||
|
|
||||||
|
| Methode | Beschreibung |
|
||||||
|
|-----------------------|-----------------------------------------------------------|
|
||||||
|
| boolean hasPrevious() | prüft, ob ein Vorgänger existiert |
|
||||||
|
| Object previous() | liefert das vorherige Element |
|
||||||
|
| void add(Object o) | fügt ein neues Element o hinter dem aktuellen Element ein |
|
||||||
|
| void set(Object o) | ersetzt das aktuelle Element durch o |
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<title>Xx java docs - Markdown Docs</title>
|
<title>06: JavaDoc - Markdown Docs</title>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,6 +73,11 @@
|
||||||
<label class="md-overlay" for="__drawer"></label>
|
<label class="md-overlay" for="__drawer"></label>
|
||||||
<div data-md-component="skip">
|
<div data-md-component="skip">
|
||||||
|
|
||||||
|
|
||||||
|
<a href="#06-javadoc" class="md-skip">
|
||||||
|
Zum Inhalt
|
||||||
|
</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div data-md-component="announce">
|
<div data-md-component="announce">
|
||||||
|
|
||||||
|
@ -102,7 +107,7 @@
|
||||||
<div class="md-header__topic" data-md-component="header-topic">
|
<div class="md-header__topic" data-md-component="header-topic">
|
||||||
<span class="md-ellipsis">
|
<span class="md-ellipsis">
|
||||||
|
|
||||||
Xx java docs
|
06: JavaDoc
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -248,6 +253,81 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="01_hello_world.html" class="md-nav__link">
|
||||||
|
01: Hello World
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="02_basics.html" class="md-nav__link">
|
||||||
|
02: Basics
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="03_coding_style.html" class="md-nav__link">
|
||||||
|
03: Coding Style
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="04_introduction_to_objects.html" class="md-nav__link">
|
||||||
|
04: Einführung in Objekte
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="05_types_of_objects.html" class="md-nav__link">
|
||||||
|
05: Typen von Objekten
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<li class="md-nav__item md-nav__item--active">
|
<li class="md-nav__item md-nav__item--active">
|
||||||
|
@ -256,8 +336,10 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a href="xx_java_docs.html" class="md-nav__link md-nav__link--active">
|
|
||||||
Xx java docs
|
|
||||||
|
<a href="06_java_docs.html" class="md-nav__link md-nav__link--active">
|
||||||
|
06: JavaDoc
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
@ -297,6 +379,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -308,23 +392,56 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a href="https://github.com/YamiDoesDev/algodat-java-intro/edit/main/docs/xx_java_docs.md" title="Seite editieren" class="md-content__button md-icon">
|
<a href="https://github.com/YamiDoesDev/algodat-java-intro/edit/main/docs/06_java_docs.md" title="Seite editieren" class="md-content__button md-icon">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25Z"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25Z"/></svg>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h1>Xx java docs</h1>
|
<h1 id="06-javadoc">06: JavaDoc</h1>
|
||||||
|
<p>Quelle: <a href="https://binfalse.de/2015/10/05/javadoc-cheats-sheet/">JavaDoc Cheatsheet</a></p>
|
||||||
|
<p>Output as PDF: <a href="https://github.com/YamiDoesDev/algodat-java-intro/blob/main/media/javadoc_main.pdf">JavaDoc from class Main</a></p>
|
||||||
|
<div class="highlight"><pre><span></span><code><span class="cm">/**</span>
|
||||||
|
<span class="cm"> * This is the Main class</span>
|
||||||
|
<span class="cm"> * @version 1.0.1</span>
|
||||||
|
<span class="cm"> * @author Justin Drtvic</span>
|
||||||
|
<span class="cm"> */</span><span class="w"></span>
|
||||||
|
<span class="c1">// Main.java</span><span class="w"></span>
|
||||||
|
<span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Main</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="cm">/**</span>
|
||||||
|
<span class="cm"> * this is the main function, which is needed to execute the code</span>
|
||||||
|
<span class="cm"> * @param args params passed by the command line</span>
|
||||||
|
<span class="cm"> */</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="w"> </span><span class="n">addition</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
|
||||||
<iframe width="100%" height="800px" src="../media/javadoc_main.pdf">
|
<span class="w"> </span><span class="cm">/**</span>
|
||||||
</iframe>
|
<span class="cm"> * addition of two integer numbers</span>
|
||||||
|
<span class="cm"> * @param left number for left side</span>
|
||||||
|
<span class="cm"> * @param right number for right side</span>
|
||||||
|
<span class="cm"> * @return sum of two numbers</span>
|
||||||
|
<span class="cm"> * @throws IllegalArgumentException for numbers smaller than 0</span>
|
||||||
|
<span class="cm"> * @see Math</span>
|
||||||
|
<span class="cm"> * @see <a href="https://www.mathebibel.de/addition/">Mathebibel Addition</a></span>
|
||||||
|
<span class="cm"> * @since Java API 7</span>
|
||||||
|
<span class="cm"> * @deprecated deprecated since 3.0.0</span>
|
||||||
|
<span class="cm"> */</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">addition</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">right</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">left</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">right</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">throw</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">IllegalArgumentException</span><span class="p">(</span><span class="s">"we don't like numbers smaller than 0"</span><span class="p">);</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">left</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">right</span><span class="p">;</span><span class="w"></span>
|
||||||
|
<span class="w"> </span><span class="p">}</span><span class="w"></span>
|
||||||
|
<span class="p">}</span><span class="w"></span>
|
||||||
|
</code></pre></div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<div class="md-source-file">
|
<div class="md-source-file">
|
||||||
<small>
|
<small>
|
||||||
|
|
||||||
Letztes Update:
|
Letztes Update:
|
||||||
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">November 2, 2022 20:16:34</span>
|
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-datetime">November 2, 2022 20:46:05</span>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
Erstellt:
|
Erstellt:
|
||||||
|
@ -360,7 +477,7 @@
|
||||||
<nav class="md-footer__inner md-grid" aria-label="Footer" >
|
<nav class="md-footer__inner md-grid" aria-label="Footer" >
|
||||||
|
|
||||||
|
|
||||||
<a href="index.html" class="md-footer__link md-footer__link--prev" aria-label="Zurück: Crashkurs Java im Modul Algorithmen und Datenstrukturen" rel="prev">
|
<a href="05_types_of_objects.html" class="md-footer__link md-footer__link--prev" aria-label="Zurück: 05: Typen von Objekten" rel="prev">
|
||||||
<div class="md-footer__button md-icon">
|
<div class="md-footer__button md-icon">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
|
||||||
</div>
|
</div>
|
||||||
|
@ -369,7 +486,7 @@
|
||||||
<span class="md-footer__direction">
|
<span class="md-footer__direction">
|
||||||
Zurück
|
Zurück
|
||||||
</span>
|
</span>
|
||||||
Crashkurs Java im Modul Algorithmen und Datenstrukturen
|
05: Typen von Objekten
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
|
@ -0,0 +1,41 @@
|
||||||
|
# 06: JavaDoc
|
||||||
|
|
||||||
|
Quelle: [JavaDoc Cheatsheet](https://binfalse.de/2015/10/05/javadoc-cheats-sheet/)
|
||||||
|
|
||||||
|
Output as PDF: [JavaDoc from class Main](https://github.com/YamiDoesDev/algodat-java-intro/blob/main/media/javadoc_main.pdf)
|
||||||
|
|
||||||
|
```java
|
||||||
|
/**
|
||||||
|
* This is the Main class
|
||||||
|
* @version 1.0.1
|
||||||
|
* @author Justin Drtvic
|
||||||
|
*/
|
||||||
|
// Main.java
|
||||||
|
public class Main {
|
||||||
|
/**
|
||||||
|
* this is the main function, which is needed to execute the code
|
||||||
|
* @param args params passed by the command line
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println( addition(1,2) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* addition of two integer numbers
|
||||||
|
* @param left number for left side
|
||||||
|
* @param right number for right side
|
||||||
|
* @return sum of two numbers
|
||||||
|
* @throws IllegalArgumentException for numbers smaller than 0
|
||||||
|
* @see Math
|
||||||
|
* @see <a href="https://www.mathebibel.de/addition/">Mathebibel Addition</a>
|
||||||
|
* @since Java API 7
|
||||||
|
* @deprecated deprecated since 3.0.0
|
||||||
|
*/
|
||||||
|
public static int addition(int left, int right) {
|
||||||
|
if (left < 0 || right < 0) {
|
||||||
|
throw new IllegalArgumentException("we don't like numbers smaller than 0");
|
||||||
|
}
|
||||||
|
return left + right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
83
index.html
83
index.html
|
@ -264,8 +264,83 @@
|
||||||
|
|
||||||
|
|
||||||
<li class="md-nav__item">
|
<li class="md-nav__item">
|
||||||
<a href="xx_java_docs.html" class="md-nav__link">
|
<a href="01_hello_world.html" class="md-nav__link">
|
||||||
Xx java docs
|
01: Hello World
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="02_basics.html" class="md-nav__link">
|
||||||
|
02: Basics
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="03_coding_style.html" class="md-nav__link">
|
||||||
|
03: Coding Style
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="04_introduction_to_objects.html" class="md-nav__link">
|
||||||
|
04: Einführung in Objekte
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="05_types_of_objects.html" class="md-nav__link">
|
||||||
|
05: Typen von Objekten
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<li class="md-nav__item">
|
||||||
|
<a href="06_java_docs.html" class="md-nav__link">
|
||||||
|
06: JavaDoc
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
@ -373,13 +448,13 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a href="xx_java_docs.html" class="md-footer__link md-footer__link--next" aria-label="Weiter: Xx java docs" rel="next">
|
<a href="01_hello_world.html" class="md-footer__link md-footer__link--next" aria-label="Weiter: 01: Hello World" rel="next">
|
||||||
<div class="md-footer__title">
|
<div class="md-footer__title">
|
||||||
<div class="md-ellipsis">
|
<div class="md-ellipsis">
|
||||||
<span class="md-footer__direction">
|
<span class="md-footer__direction">
|
||||||
Weiter
|
Weiter
|
||||||
</span>
|
</span>
|
||||||
Xx java docs
|
01: Hello World
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="md-footer__button md-icon">
|
<div class="md-footer__button md-icon">
|
||||||
|
|
1344
print_page.html
1344
print_page.html
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
25
sitemap.xml
25
sitemap.xml
|
@ -10,4 +10,29 @@
|
||||||
<lastmod>2022-11-02</lastmod>
|
<lastmod>2022-11-02</lastmod>
|
||||||
<changefreq>daily</changefreq>
|
<changefreq>daily</changefreq>
|
||||||
</url>
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>None</loc>
|
||||||
|
<lastmod>2022-11-02</lastmod>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>None</loc>
|
||||||
|
<lastmod>2022-11-02</lastmod>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>None</loc>
|
||||||
|
<lastmod>2022-11-02</lastmod>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>None</loc>
|
||||||
|
<lastmod>2022-11-02</lastmod>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>None</loc>
|
||||||
|
<lastmod>2022-11-02</lastmod>
|
||||||
|
<changefreq>daily</changefreq>
|
||||||
|
</url>
|
||||||
</urlset>
|
</urlset>
|
BIN
sitemap.xml.gz
BIN
sitemap.xml.gz
Binary file not shown.
|
@ -1,4 +0,0 @@
|
||||||
https://binfalse.de/2015/10/05/javadoc-cheats-sheet/
|
|
||||||
|
|
||||||
<iframe width="100%" height="800px" src="../media/javadoc_main.pdf">
|
|
||||||
</iframe>
|
|
Loading…
Reference in New Issue