summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbdus <abdus@abdus.net>2021-05-03 11:22:04 +0530
committerAbdus <abdus@abdus.net>2021-05-03 11:22:04 +0530
commit4ca3bc3d0607c7c50d14d7b3f03cfa6ba55b0856 (patch)
tree9577681e42f7c81acc7d8a51e4854e64123b2501
parent89e61e5590a12dc364d815ac6c89a09d284b0942 (diff)
downloadabdus.net-4ca3bc3d0607c7c50d14d7b3f03cfa6ba55b0856.tar.bz2
abdus.net-4ca3bc3d0607c7c50d14d7b3f03cfa6ba55b0856.zip
new notes
-rw-r--r--.vim-session.vim57
-rw-r--r--content/notes/java-basics.md71
2 files changed, 79 insertions, 49 deletions
diff --git a/.vim-session.vim b/.vim-session.vim
index 4e76c7f..a434944 100644
--- a/.vim-session.vim
+++ b/.vim-session.vim
@@ -7,8 +7,7 @@ if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
set shortmess=aoO
-badd +9 content/notes/java-basics.md
-badd +1 content/posts/typescript-webpack-setup.md
+badd +219 content/notes/java-basics.md
argglobal
%argdel
$argadd content/posts/typescript-webpack-setup.md
@@ -24,62 +23,22 @@ setlocal fdm=indent
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
-setlocal fdl=0
+setlocal fdl=4
setlocal fml=1
setlocal fdn=20
setlocal fen
-8
+223
normal! zo
-116
+224
normal! zo
-117
+253
normal! zo
-126
-normal! zo
-131
-normal! zo
-136
-normal! zo
-152
-normal! zo
-155
-normal! zo
-157
-normal! zo
-162
-normal! zo
-163
-normal! zo
-165
-normal! zo
-166
-normal! zo
-168
-normal! zo
-169
-normal! zo
-174
-normal! zo
-177
-normal! zo
-193
-normal! zo
-200
-normal! zo
-203
-normal! zo
-209
-normal! zo
-211
-normal! zo
-215
-normal! zo
-let s:l = 85 - ((13 * winheight(0) + 24) / 48)
+let s:l = 288 - ((2 * winheight(0) + 24) / 48)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
-85
-normal! 085|
+288
+normal! 0
tabnext 1
if exists('s:wipebuf') && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
silent exe 'bwipe ' . s:wipebuf
diff --git a/content/notes/java-basics.md b/content/notes/java-basics.md
index 1faf26a..8c23692 100644
--- a/content/notes/java-basics.md
+++ b/content/notes/java-basics.md
@@ -215,3 +215,74 @@ class Test {
but won't halt the execution. compiler wil replace the object name with
class name
- static variables can be accessed without initializing an object
+
+## Loops
+
+```java
+class Loop {
+ public static void main(String[] args) {
+ // while
+ while (true) {
+ System.out.println("Hello");
+ }
+
+ // for loop: the classic for loop
+
+ // enhanced for loop
+ // when there's no need for element index,
+ // enhanced for loop can be used
+ String array[] = {"Jon", "Snow"};
+
+ for (String s : array) {
+ System.out.println(x);
+ }
+
+ // do while: similar to other languages
+ }
+}
+```
+
+## String
+
+Strings in Java can be declared in two ways. Strings are baked by a char array
+internally. Hence, they are immutable. All strings are terminated with `\0`(null
+character).
+
+```java
+class StringExample {
+ public static void main() {
+ String str1 = "String"; // stores in constant pool
+ String str2 = new String("kaboom"); // stores in heap
+
+ // to store a string from heap to constant pool,
+ // `intern` method.
+ String str3 = str2.intern();
+ }
+}
+```
+
+Some classes that provides more flexible ways to work with string:
+
+- [`StringBuffer`](http://www.geeksforgeeks.org/stringbuffer-class-in-java/)
+- [`StringBuilder`](https://www.geeksforgeeks.org/stringbuilder-class-in-java-with-examples/)
+- [`StringTokenizer`](https://www.geeksforgeeks.org/stringtokenizer-class-java-example-set-1-constructors/)
+- [`StringJoiner`](https://www.geeksforgeeks.org/java-util-stringjoiner-java8/)
+
+### String Methods
+
+- `int length`: retuns length of the string
+- `char charAt(int i)`: returns the char at `i` index
+- `String substring(int i)`: returns the substring from `i` to the end of the str
+ passing a second argument would return str upto (index - 1)
+- `String concat(String r)`: append a string. returns the full string.
+- `int indexOf(String s, int i)`: returns position of the string `s`. second
+ parameter sets the index from where the search should start
+- `int lastIndexOf(String s)`: position of last occurance
+- `boolean equals(Object obj)`: compares string to the specified object. another
+ variant is `equalsIgnoreCase(String s)`
+- `int compareTo(String s)`: compare to another string. returns `<0` if `s1`
+ comes before `s2`, `0` is both are equal, `>0` is `s1` comes after `s2`.
+ another variant is `compareToIgnoreCase`
+- `String toLowerCase()`: converts to lower case
+- `String toUpperCase()`: converts to upper case
+- `String replace(char old, char new)`: replaces char with a new one