0% found this document useful (0 votes)
30 views

Lesson 01 - Intro

This document provides an introduction to a Java course, including: - The course is based on a previous 'Java for Web' course. - The course creators are Alex, Vasya, and Yarik from SPD-Ukraine. - The course action plan covers Java core topics like OOP, exceptions, collections, and concurrency as well as web topics like Servlets, REST, and Spring Framework.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Lesson 01 - Intro

This document provides an introduction to a Java course, including: - The course is based on a previous 'Java for Web' course. - The course creators are Alex, Vasya, and Yarik from SPD-Ukraine. - The course action plan covers Java core topics like OOP, exceptions, collections, and concurrency as well as web topics like Servlets, REST, and Spring Framework.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 57

Lesson 1 - Intro


This course is based on the
‘Java for Web’ course
for GeekHub (Season 9)

2
Course creators

Alex (SPD-Ukraine) Vasya (SPD-Ukraine) Yarik (SPD-Ukraine)

3
Course action plan
▷ Core
○ Basics
○ OOP
○ Code testing
○ Exceptions
○ Collections, Generics
○ Functional Programming
○ IO
○ Concurrency
○ Database
▷ Web
○ Servlet API
○ REST
○ Spring Framework (MVC, Boot, JDBC, Security)
○ …

4
Lesson goals
▷ What is Java
▷ Basic Java
○ Variables
○ Datatypes
○ Operators
○ Structure
▷ Dev tools
○ VCS (Git)

5
JVM vs JRE vs JDK

6
Java Platform Editions
1. Standart Edition
2. Enterprise Edition
3. Midlet Edition

7
Java Evolution

199 199 199 2000 2002 2004 2006 201 201 201 201 201 2020 2021 2022 2023
6 7 8 1 4 7 8 9
2xxx

10 12 14 16 18
1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 9 20
11 13 15 17 19

8
How it works?

javac.exe java.exe

JVM
Hello.java Hello.class

9
Java pros
👍 Cross-platform

👍 Secure

👍 Powerful

👍 Multithreaded

👍…

10
Hello World
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!!!");
}
}

c:\> javac HelloWorld.java

c:\> java HelloWorld Arg1 Arg2 777

11
Program
int a = 1;
int b = 1;
Code int
int
c
D
=
=
6;
b * b - 4 * a * c; /* discriminant */

+ if (D >= 0) {
int x1 = (-b + Math.sqrt (D)) / (2 * a);

Whitespaces }
int x2 = (-b - Math.sqrt (D)) / (2 * a);

+
Comments The same to

int a=1,b=1,c=6;int D=b*b-4*a*c;if(D>=0) {int x1=(-


b+Math.sqrt(D))/(2*a);int x2=(-b-Math.sqrt(D))/(2*a);}

12
Java Syntax
▷ Static typed

▷ Case sensitive

▷ Statements separated by semicolon ;

▷ Wrap blocks in braces {}

▷ Spaces (4) vs tabulation

▷ Comments
○ // one line
○ /* multiline */
○ /**Java doc */
13
Code convention
Read. Remember. Follow.

▷ By Oracle
▷ By Google
▷ By Twitter

14
Variables
type value

int size = 41;

name

15
Primitive types

16
Operators

17
Keywords
Primitive types Reserved
Modifiers Declarations Control Flow Misc
and void Identifiers

exports, module,
boolean public class if, else this, super
non-sealed

byte protected interface try, catch, finally new open, opens, permits

provides, record,
char private enum do, while _ (underscore)
requires, sealed

to, transitive, uses,


short abstract extends continue, break, return import
var

int static implements throw instanceof with, yield

long final package default null

float transient throws for true, false

volatile,
double case assert
synchronized

strictfp, goto, const


void native switch
(unused)

18
What will be printed?
public class HelloWorld {
public static void main(String args[]) {
int a = 5;
int b = a;
a = 3;

System.out.println(b);
}
}

19
Object
public class Point {
private int x;
private int y;

// getters/serters

void draw() {
// …
}
}

20
What will be printed?
Point p1 = new Point(3,5);
Point p2 = p1;
p1.setX(7);
print(p2.getX());

Point p3 = new Point(3,5);


Point p4 = p3;
p3 = new Point(7,9);
print(p4.getX());

21
Null is not a Zero
Only objects can be null
Primitive types – cannot

String nullText = null;


String emptyText = “”;

22
Arrays
int array[] = new int[5]; //[0, 0, 0, 0, 0]
for (int i = 0; i < 5; i++) { // indexing starts from 0
array[i] = i * i; // [0, 1, 4, 9, 16]
}

Object array[] = new Object[3]; // [null, null, null]

String matrix[][] = {{"aaa", "bbb", "cde"}, {"1", "2"}};

23
Conditional operator if else
int n = readNumber();
if (n == 1) {
System.out.println("1");
} else if (n == 2 || n == 3) {
System.out.println("2 or 3");
} else if (n == 4) {
System.out.println("4");
} else {
System.out.println("5");
}

24
Conditional operator switch
int n = readNumber();
switch (n) {
case 1:
System.out.println("1");
break;
case 2:
case 3:
System.out.println("2 or 3");
break;
case 4:
System.out.println("4");
break;
default:
System.out.println("5");
}
25
Conditional operator switch
int n = readNumber();
String res = switch (n) {
case 1 -> "1";
case 2, 3 -> "2 or 3";
default -> "5";
};

26
Loop while “do”
while (condition) {
statement;
}

int count = 0;
while (count < 5) {
System.out.println(count);
count++;
}

27
Loop while “do”
do {
statement;
} while (condition);

int count = 0;
do {
System.out.println(count);
count++;
} while (count < 5);

28
Conditional loop for
for (initialization; condition; increment){
statement;
}

for (int count = 0; count < 5; count++) {


System.out.println(count);
}

29
Branching statement break
int maxRetries = 10;

for(int i = 0;;) {
if(i > maxRetries){
break; // stop iteration
}
doSomething();
i++;
}
30
Branching statement continue
for(int i=0;; i++) {
if(i % 5 == 0){
doSomethingAnother();
continue; // continue iteration
}
doSomething();
}

31
Branching statement return
for(int i = 0; i < 10; i++) {
if(i > 5) {
return -1; // stop iteration and exit from method
}
doSomething();
}
return result;

32
Packages

33
Imports
import <package.name>.<classname>;

java.lang is imported by default

Importing a Package Member Importing an Entire Package


import java.util.Map; import java.util.*;
import java.util.HashMap; ….
….
Map map = new HashMap(); Map map = new HashMap();

34
Garbage Collector

Java Garbage Collection (GC) is a process that runs in the background of a Java program and
automatically manages the memory used by the program. In other words, when a Java program
creates objects or data in memory, the GC keeps track of which objects are no longer being
used by the program and frees up the memory used by those objects so it can be reused by the
program.

35
Debugging

36
Literature
▷ Java Basics:
○ Getting started
○ Language Basics
○ Classes and Objects
▷ Java Code Convention:
○ By Oracle
○ By Google
○ By Twitter
▷ Books:
○ “Clean Code” by Robert Martin
○ “Java: The Complete Reference” by Herbert Schildt
37
Homework
Complete implementation of encoding/decoding system provided in
GitLab. Alphabets and rules available on site

public interface Encoder {


String encode(String input);
}

public interface Decoder {


String decode(String input);
}

38

Quality is more important than amount
Thanks!
Questions?
Version Control System (VCS)

41
Cloud repository

42
Register on Gitlab.com
• Go to https://gitlab.com

• Register using your Full Name (ex. Oleksandr Kucher) or use


already existing account

43
Fork repository

• Login to
https://gitlab.com
• Go to
https://gitlab.com/olexand
r.kucher/chnu-java-lectur
es
• Click Fork button

44
Fork repository

1. Select your user as


namespace to fork the
project
2. Make your project
Private
3. Click Fork project

45
Fork repository

46
Fork repository

1. Click Project information


2. Click Members
3. Click Invite members
4. Add olexandr.kucher
5. Make them Reporters
6. Click Invite

47
Import project into IDEA

• Open your project in


GitLab
• Click Clone
• Choose and copy HTTPS
link (you can use SSH link
too, if you know how to
work with it)

48
Import project into IDEA
• Install Git (https://git-scm.com)
• Open IntelliJ IDEA
1. Choose Get from VCS
2. Paste link to project copied in
GitLab
3. Click Clone
4. Type and save your credentials
(username/password or SSH
passphrase) if required

49
Fork repository
1. Clone your project using Git Bash or IDE
2. Open Git Bash and navigate to folder with
cloned project
3. Execute next command (it will setup
upstream to sync your repository with the
original one): git remote add upstream
https://gitlab.com/olexandr.kucher/chnu-java-
lectures.git || true && git fetch upstream &&
git checkout main && git pull upstream main
&& git push origin main
4. You can find additional details here:
https://forum.gitlab.com/t/refreshing-a-fork/32
469/2#git-cli-2

50
Fork repository
• Open your project in the IDE
• main (origin/main) branch will be your
working branch (commit and push into it)
• upstream/main branch will be used to
sync your repository with original one
• To get updates from original repository:
1. Click on Git Branches control in IDE
2. Select upstream/main branch
3. Click Pull into ‘main’ Using Merge
4. Same or similar notification will be shown

51
Fork repository

1. Press Ctrl+Shift+K
hotkey (if you are using
Windows)
2. You will see the same
window as on the
screenshot
3. Click Push button

52
Import project into IDEA
• Choose your project and press Ctrl+Enter
1. Choose Project tab
2. Click on SDK dropdown
3. Click Add SDK
4. Click Download JDK…
5. Choose version 17
6. Choose Eclipse Temurin
7. Click Download (wait until JDK
downloaded, select it)
8. Click OK

53
Import project into IDEA
• Choose your project and press
Ctrl+Enter
• Choose Project tab
• This tab should be like the tab
on the screenshot
• Project should be imported
automatically by the IDE (we’ll
discuss how it happened later)

54
First Commit and Push to Git
• You have made some changes, it’s
time to commit and push
• Press Ctrl+K to make commit
1. Choose files that should be
committed
2. Type understandable and informative
comment: “L## | Commit Message”
3. Click Commit and Push…
4. Click Push

55
First Commit and Push to Git

• Do not commit anything if you got some error or warning message


• Check these messages carefully
• Fix described problems
• Commit changes to the repository

56
Literature
• https://git-scm.com

• https://git-scm.com/book/en/v2

• https://try.github.io

• https://gitlab.com/help

• https://forum.gitlab.com/t/refreshing-a-fork/32469/2#git-cli-2

57

You might also like