diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..47d5cac0 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,45 @@ +name: Deploy Quartz site to GitHub Pages + +on: + push: + branches: + - v4 + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Fetch all history for git info + - uses: actions/setup-node@v3 + with: + node-version: 18.14 + - name: Install Dependencies + run: npm ci + - name: Build Quartz + run: npx quartz build + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: public + + deploy: + needs: build + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 \ No newline at end of file diff --git a/content/.gitkeep b/content/Booleans.md similarity index 100% rename from content/.gitkeep rename to content/Booleans.md diff --git a/content/Conditionals or Selections.md b/content/Conditionals or Selections.md new file mode 100644 index 00000000..be47c350 --- /dev/null +++ b/content/Conditionals or Selections.md @@ -0,0 +1,25 @@ +if statements n stuff + +### Short-circuit evaluation +```java +int x = 10; +int y = 0; +// It will skip the second condition b/c the first condition is true +if (x < 20 || x / y == 0) { + // It will print this; no runtime error +} +if (x < 20 && x / y == 0) { +// This will throw a run-time error because && will run both conditionals. +// The conditional for x / y will give an arithmetic error +} + +``` + +### Syntactic sugar +```java +// Will call the line directly after if there's no curly brackets '{}' +if (true) System.out.println("This will print if true!"); + +System.out.println("This will print regardless!"); + +``` \ No newline at end of file diff --git a/content/De Morgan's Law.md b/content/De Morgan's Law.md new file mode 100644 index 00000000..8ba804f9 --- /dev/null +++ b/content/De Morgan's Law.md @@ -0,0 +1,4 @@ +# NOOOOooooo ! + +![[Pasted image 20240220132055.png]]![[Pasted image 20240220132805.png]] +![[Pasted image 20240220133100.png]] \ No newline at end of file diff --git a/content/Flow charts for conditionals.md b/content/Flow charts for conditionals.md new file mode 100644 index 00000000..1c933008 --- /dev/null +++ b/content/Flow charts for conditionals.md @@ -0,0 +1,24 @@ +flow charts yay +* Oval = beginning +* parallelogram + * Assigning variables + * Getting user input + * Output +* Diamond = conditions +* Square + * Describes a condition (true / false arrow) + + +Note: +* Do not write exact code + + + +The top image is an oval that says "start" +![[Pasted image 20240221144302.png]] + +(newer) +![[Pasted image 20240222132119.png]] + +- The point of the parallelogram is to specify input and output. +- \ No newline at end of file diff --git a/content/For loops.md b/content/For loops.md new file mode 100644 index 00000000..127da1c6 --- /dev/null +++ b/content/For loops.md @@ -0,0 +1,43 @@ + +```java +// This will loop so long as i, which is declared *inside* the for loop, is less than 10. If it isn't, the loop will not continue. +for (int i = 0; i < 10; i++) { + // I will be the values between [0, 9] +} +``` + +```java +int i; +// This for loop doesn't have a body, so it just makes i equal to 9 at the end of the loop. +for (i = 0; i < 10; i++); +s.o.p(i); // Will print 9 +``` + +```java +// Similarly to conditionals, if you don't add the curly braces or semicolon, it will only loop the line right after it. +for (int i = 0; i < 10; i++) + s.o.p(i); // Prints 0 to 9 + s.o.p("This is only printed once!"); +``` + +## Semantics with ++ +The "++" operator can be written two ways: +```java +int variable = 0; +variable++; // First way +++variable; // Second way +``` +...and there is a big difference between the two of them!1 +1. `var++` will get the value of `var`, and *then* increment by one +2. `++var` will increment the value, and then will give that incremented value of `var` +>[!help] Yes. it doesn't make much sense at first. Bear with me + +```java +int first = 0; +System.out.println(first++); // "0" is printed, then "first" increments by 1. + +int second = 0; +System.out.println(++second); // "second" will be incremented, and then "1" is printed. +``` +>In both cases, `first` and `second` increment by 1, but the time at which the variables "update" is different + diff --git a/content/GUI's.md b/content/GUI's.md new file mode 100644 index 00000000..d2dc88a2 --- /dev/null +++ b/content/GUI's.md @@ -0,0 +1,116 @@ +A window is a "`JFrame`" +- Dimensions are in pixels + - (0,0) is at the top left (like Godot) +- Widgets are the components: + - `TextLabel`s + - Will display words + - Buttons + - `TextField` + - Will allow user input + - `TextArea` + - `CheckBox` +* Output can be a label (most common) +* All widgets are rectangular and they are placed via the top-left corner's position + +E.g: a label is 200 by 50. The Frame is 500 by 500. How do we center it? +- y: 250 - 25 = 225 y +- x: 250 - 100 = 150 x +- Rect Coords: (150, 225) + + + + +* Main isn't used very much +* If we want to make a Gui, make a new file called frmMyGui + * All forms will start with "frm" + * All the imports will be copy-pasted + * Dw about what `extends` and `implements` mean; really. + * Instance the GUI inside of main: + * ![[Pasted image 20240227141600.png]] + +> here is the file frmMyGui.java +![[Pasted image 20240227141453.png]] + + +### Frame methods +> Inside of frmMyGUI's constructor +![[Pasted image 20240227141708.png]] + +### Instancing custom colors +![[Pasted image 20240227141748.png]] + +### Defining new widgets on a frame +![[Pasted image 20240227142036.png]] +> Declare it first +> +```java +public class frmMyFrame extends JFrame implements ActionListener +{ + // Declare variable + JLabel lblTitle; + JTextField txtName; + JButtom btnEnter; + + public frmMyFrame() + { + setLayout(null); // This will give "full control" over where labels go + + // Instance it + lblTitle = new JLabel("Welcome to my GUI"); + // These can now be controlled b/c setLayout is null. + lblTitle.setSize(200, 50); + lblTitle.setLocation(150, 0); + // Required to see the widget + add(lblTitle); + + + // Setting up a text field + txtName = new JTextField(); // Nothing required to instance + txtName.setLocation(150, 50); + txtName.setSize(100, 50); + add(txtName); + + + // Lastly, a button for example + btnEnter = new JButton("Enter"); + btnEnter.setSize(150, 200); + btnEnter.setLocation(100, 50); + add(btnEnter;) + } +} +``` +> [!Note] If two widgets are on the same spot, they're cover eachother up! Be careful about that + + +## Coding the GUI's +* All buttons have "Actions" +* Before adding a button, you need these 2 lines of code to make the button do something. +```java + +public frmMyFrame() { + btnEnter = new JButton("Enter"); + btnEnter.setSize(150, 200); + btnEnter.setLocation(100, 50); + // New lines + btnEnter.setActionComment("enter"); + btnEnter.setActionListener(this); + // Remember to add + add(btnEnter;) +} + +public void actionPerformed(ActionEvent e) { + if (e.getActionComment.equals("enter")) { + // Code is triggered when the button is pressed + } +} +``` + +## Getting text from TextLabel +```java +// It's this simple! txtName is a JTextLabel +String text = txtName.getText(); + +double dblValue = 10.41; +txtName.setText("" + dblValue); // Set text always takes in a string. A double is not a string, so we concatenate with the "+" +``` + diff --git a/content/Input.md b/content/Input.md new file mode 100644 index 00000000..488cc66d --- /dev/null +++ b/content/Input.md @@ -0,0 +1,7 @@ +```java +Scanner input = new(System.in); + +int __ = input.nextInt(); //-- Int +double __ = input.nextDouble(); //-- double +String __ = input.next(); //-- string +``` diff --git a/content/Interpreter.md b/content/Interpreter.md new file mode 100644 index 00000000..930887bb --- /dev/null +++ b/content/Interpreter.md @@ -0,0 +1,3 @@ +One part of the Java Virtual Machine ([[JVM]]) is its interpreter, which is then used to run code for difference devices. + +Java does have a JIT compiler, which compiles the byte-code into machine code right before being ran by the [[JVM]] (Yes, still. Even as machine code the [[JVM]] is still significant in running Java code) for performance gains by working with hardware more closely (sort of like lower-level languages) \ No newline at end of file diff --git a/content/JVM.md b/content/JVM.md new file mode 100644 index 00000000..f9a65866 --- /dev/null +++ b/content/JVM.md @@ -0,0 +1,10 @@ +Java code is ran via the JVM, which: +1. Uses its [[Interpreter]] to read the byte-code given by the [[Java Compiler]] +2. Runs its JIT compiler for optimization optionally +3. Runs the code for every device. + +> Therefore, Java is kind of *both* interpreted and compiled, but not* fully* interpreted and not *fully* compiled + + + + diff --git a/content/Java Compiler.md b/content/Java Compiler.md new file mode 100644 index 00000000..ef571207 --- /dev/null +++ b/content/Java Compiler.md @@ -0,0 +1 @@ +The compiler is what turns text code into byte-code (going from .java to .class files). It is used preliminarily in order for the JVM to interpret the code. Unlike python, where every line is read *raw*. \ No newline at end of file diff --git a/content/Jegification.md b/content/Jegification.md new file mode 100644 index 00000000..d2963dc6 --- /dev/null +++ b/content/Jegification.md @@ -0,0 +1,43 @@ +# 1 Indent using this format: +![[Pasted image 20240205141354.png]] +# 2 Header +The header will be like this: +```java +/** +Author: +Date: +Description: +**/ +``` +# 3 No commented-out code +Do not submit code with the backslashes (or it should run even with the backslashes on lines) + +# 4 Pretty math +Add spaces between all arithmetic +```java +int value = (x + 6) / 4 +``` + +# 5 Variable names +All variable names need to have the data type before them +```java +int intValue = 10; +double dblValue = 2.5; + +String strPain = "Welcome to jegified land"; +``` + +# 6 Comment everything +Always describe what a variable does when you declare it (EVERY ONE); don't just say you declared it +```java +// intJohn is an integer variable to store John's age +int intJohn; +``` + +# 7 All scanners shall be named "input" + +# 8 Break? More like i'll snap your neck in half +* You can only use "break" in switch-cases + +# 9 [[Strings||String]] methods +Only `length()`, `substring()`, and `indexOf()` are allowed diff --git a/content/Low-level and High-level languages.md b/content/Low-level and High-level languages.md new file mode 100644 index 00000000..7621f845 --- /dev/null +++ b/content/Low-level and High-level languages.md @@ -0,0 +1,6 @@ +According to Jeg: +- Low-level = compiled (no errors until you run the code) +- High-level = interpreted (you can see errors before compilation) + +>[!note] Java is high-level + diff --git a/content/Pasted image 20240205141354.png b/content/Pasted image 20240205141354.png new file mode 100644 index 00000000..44521fed Binary files /dev/null and b/content/Pasted image 20240205141354.png differ diff --git a/content/Pasted image 20240220132055.png b/content/Pasted image 20240220132055.png new file mode 100644 index 00000000..67752f57 Binary files /dev/null and b/content/Pasted image 20240220132055.png differ diff --git a/content/Pasted image 20240220132805.png b/content/Pasted image 20240220132805.png new file mode 100644 index 00000000..850c1628 Binary files /dev/null and b/content/Pasted image 20240220132805.png differ diff --git a/content/Pasted image 20240220133100.png b/content/Pasted image 20240220133100.png new file mode 100644 index 00000000..2263d7be Binary files /dev/null and b/content/Pasted image 20240220133100.png differ diff --git a/content/Pasted image 20240221144302.png b/content/Pasted image 20240221144302.png new file mode 100644 index 00000000..9a7bb4ec Binary files /dev/null and b/content/Pasted image 20240221144302.png differ diff --git a/content/Pasted image 20240222132119.png b/content/Pasted image 20240222132119.png new file mode 100644 index 00000000..8f269a1d Binary files /dev/null and b/content/Pasted image 20240222132119.png differ diff --git a/content/Pasted image 20240227141453.png b/content/Pasted image 20240227141453.png new file mode 100644 index 00000000..70865cb1 Binary files /dev/null and b/content/Pasted image 20240227141453.png differ diff --git a/content/Pasted image 20240227141543.png b/content/Pasted image 20240227141543.png new file mode 100644 index 00000000..952dd280 Binary files /dev/null and b/content/Pasted image 20240227141543.png differ diff --git a/content/Pasted image 20240227141557.png b/content/Pasted image 20240227141557.png new file mode 100644 index 00000000..43d805b0 Binary files /dev/null and b/content/Pasted image 20240227141557.png differ diff --git a/content/Pasted image 20240227141600.png b/content/Pasted image 20240227141600.png new file mode 100644 index 00000000..43d805b0 Binary files /dev/null and b/content/Pasted image 20240227141600.png differ diff --git a/content/Pasted image 20240227141708.png b/content/Pasted image 20240227141708.png new file mode 100644 index 00000000..56e7845f Binary files /dev/null and b/content/Pasted image 20240227141708.png differ diff --git a/content/Pasted image 20240227141748.png b/content/Pasted image 20240227141748.png new file mode 100644 index 00000000..cf8b792b Binary files /dev/null and b/content/Pasted image 20240227141748.png differ diff --git a/content/Pasted image 20240227142036.png b/content/Pasted image 20240227142036.png new file mode 100644 index 00000000..af717c25 Binary files /dev/null and b/content/Pasted image 20240227142036.png differ diff --git a/content/Strings.md b/content/Strings.md new file mode 100644 index 00000000..37a04b1a --- /dev/null +++ b/content/Strings.md @@ -0,0 +1,53 @@ +```java +String string = "Everything inside these (besides escape sequences and quotes) will be allowed in a string" + +``` + +Methods +```java +String myString = "I love MELONS"; + +int length = myString.length(); // Gets length +char firstChar = myString.charAt(0); // Indexes start at 0. You are not allowed to use this + +int index = myString.indexOf("l"); // Gets index of first instance of a string. if there's none, it will give "-1" +int index2 = myString.indexOf("love"); // Also possible; would be the same as the index above. + +String sub = myString.substring(0, 2); // Will get the character at index 0 up to the index before 2. Its range is basically [0, 2) +String sub2 = myString.substring(3) // Will return everything after and including index 3 + +String upper = myString.toUpperCase(); // Makes things upper case +String lower = myString.toLowerCase(); +``` +>[!Note] You can ONLY use the methods `length()`, `substring()`, and `indexOf()` for strings +### Reading strings as input +```java +Scanner input = new Scanner(System.in); +input.next(); +``` + + +## Comparing strings +```java +// You cannot use double-equal signs. it will not work +String temp = "My string"; +if (temp.equals("My string")) { + // Will run this block because every character is the same +} +``` + +### compareto +``` java +String s1 = "Apple", s2 = "Boy"; +// The method "compareTo" compare every character's ASCII value +if (s1.compareTo(s2) == 0) { + // S1 has the same ASCII characters as s2 +} +if (s1.compareTo(s2) < 0) { // it returns a random negative value + // s1 comes earlier alphabetically than s2. + // "A" is index 65 and "B" is index 66. Since 65 < 66, the function returns a value less than 0 +} +if (s2.compareTo(s1) > 0) { + // compareTo will return a positive value because +} +``` diff --git a/content/Switch-case.md b/content/Switch-case.md new file mode 100644 index 00000000..710f2d9e --- /dev/null +++ b/content/Switch-case.md @@ -0,0 +1,19 @@ +Instead of chaining if-else statements, using a switch is more performant. It also looks like Python. + +```java +int value = 3; +switch(value) { + // You are not allowed to use "break" ANYWHERE ELSE in your code + case 1: System.out.println("Sunday"); + break; // w/o this break the code will print the rest of the cases for some reason. + case 2: System.out.println("Monday"); + break; + case 3: System.out.println("Tuesday"); + break; + default: + System.out.println("Default b/c every other case failed"); + break; + //etc + } +} +``` \ No newline at end of file diff --git a/content/Times i goofed up.md b/content/Times i goofed up.md new file mode 100644 index 00000000..ecea2e13 --- /dev/null +++ b/content/Times i goofed up.md @@ -0,0 +1,7 @@ +1. System.out.print will print a line w/o a \n. + 1. If you call System.out.print, then System.out.println, it will still print on the same line +2. Tab works like this: + 1. a tab is every 4 characters. if a word is 5 words long, the tab will add 3 spaces to make it a multiple of 4 (which is 8) + 2. Just remember that he is assuming the font is monospace'd +3. % is before division/multiplication + 1. BE%DMAS \ No newline at end of file diff --git a/content/Variables.md b/content/Variables.md new file mode 100644 index 00000000..d0576300 --- /dev/null +++ b/content/Variables.md @@ -0,0 +1,27 @@ +An ATM will store data into the RAM, which stores le variable while the program is running. +It could be stored permanently on a server or something + +What is a variable? +- A memory location in the RAM +- Do not fly on the Boeing 373 max + +Data types +- Memory management: + - Smallest unit is a bit (0 or 1) + - 1 Byte is 8 bits + - 1024 bytes in 1 kilobyte + - 1024 kilobyte in 1 megabyte + - etc. + +Primitive types (values with a `?` are wrong but Jeg said so) + +| Type | Size | Range | +| ------- | --------- | ------------------------- | +| integer | 4 bytes | integers (-1, 0, 1, etc.) | +| double | 8 bytes | Real numbers | +| float | 4 bytes | Real numbers | +| String | 32 bytes? | all characters | +| Char | 1 byte? | single letter | +| bool | 1 byte | true, false | +| Objects | ~~~ | ~~~ | + diff --git a/content/While Loop.md b/content/While Loop.md new file mode 100644 index 00000000..f5d57261 --- /dev/null +++ b/content/While Loop.md @@ -0,0 +1,2 @@ +Uhhhh uhhhh hhhhhh +Just know they learned these or something like that. \ No newline at end of file diff --git a/content/index.md b/content/index.md new file mode 100644 index 00000000..cb302b70 --- /dev/null +++ b/content/index.md @@ -0,0 +1,5 @@ +--- +title: Welcome to my cs notes! (●'◡'●) +--- + +Nothing is in any order, so just look up the topic you are interested in and you'll find all the information 👍 \ No newline at end of file diff --git a/content/temp.md b/content/temp.md new file mode 100644 index 00000000..3ec8c4b6 --- /dev/null +++ b/content/temp.md @@ -0,0 +1,32 @@ +Erros: +1. Syntax errors + 1. Will not compile +2. Runtime errors + 1. Program compiles but code during runtime will unexpectedly terminate +3. Logical errors: + 1. Program runs and compiles but the output is wrong + + + +```java +double x = 5 +System.out.println(x); // Will print 5.0; make sure you remember this +``` + +```java +int x = (int)(3.68); +S.o.p(x); // Will print 3 + +``` + +```java +int x = 10; +int y = 20; +x = y; +y = x; + +// X is 20, y is 20 +``` + +> Do the question on google classroom with swapping the two numbers. + diff --git a/package-lock.json b/package-lock.json index 4a8b5833..3c827cd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "mdast-util-to-string": "^4.0.0", "micromorph": "^0.4.5", "preact": "^10.19.5", - "preact-render-to-string": "^6.3.1", + "preact-render-to-string": "^6.4.2", "pretty-bytes": "^6.1.1", "pretty-time": "^1.1.0", "reading-time": "^1.5.0", @@ -4463,9 +4463,9 @@ } }, "node_modules/preact-render-to-string": { - "version": "6.3.1", - "resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-6.3.1.tgz", - "integrity": "sha512-NQ28WrjLtWY6lKDlTxnFpKHZdpjfF+oE6V4tZ0rTrunHrtZp6Dm0oFrcJalt/5PNeqJz4j1DuZDS0Y6rCBoqDA==", + "version": "6.4.2", + "resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-6.4.2.tgz", + "integrity": "sha512-Sio5SvlyZSAXHuvnMgYzVQd67lNIuQe4uSjJ+2gfpJNC6L8zoHQR5xV7B/EjIqrAYWVyJ2eACkTCxVrIzZi6Vw==", "dependencies": { "pretty-format": "^3.8.0" }, diff --git a/package.json b/package.json index 54c67fbf..78785adc 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "mdast-util-to-string": "^4.0.0", "micromorph": "^0.4.5", "preact": "^10.19.5", - "preact-render-to-string": "^6.3.1", + "preact-render-to-string": "^6.4.2", "pretty-bytes": "^6.1.1", "pretty-time": "^1.1.0", "reading-time": "^1.5.0",