Sunday, November 15, 2020

What's new in JDK 9(my short version)

1.Java platform module system
- optional phase, link time, between compile and run time.
- options to javac, jlink and java where you can specify module paths
- modular JAR file, which is a JAR with module-info.class in root dir
- JMOD format, which can include native code compared to JAR
- JDK divided into modules, thus enabling combination of modules.
- new URI scheme for naming modules, classes and resources stored in a runtime image without revealing the internal structure or format of the image.
- Removes rt.jar and tools.jar from the Java runtime.
- Makes most JDK internal APIs inaccessible by default, with some widely used exceptions.

2.New version-string scheme. $MAJOR.$MINOR.$SECURITY.$PATCH
- A major release contains new features and changes to existing features, which are planned and announced well in advance - A minor version number that is incremented for each minor update, such as bug fixes, revisions to standard APIs or implementation of features outside the scope of the relevant platform specifications
- Security is the version number that is incremented for a security-update release, which contains critical fixes, including those necessary to improve security. PATCH is the version number that is incremented for a release containing security and high-priority customer fixes that have been tested together

3.Language features
- @SafeVargs annotation
- effectively final variables to be used in try with resources
- support for private interface methods.

4.JVM
- G1 improvements.
- common logging system.
- G1 made Default.
- Concurrent Mark Sweep is deprecated.

5.Core
- Improvements on the OS Processes API
- Changed internal representation of strings from char array with 2 bytes for each character to a byte array plus encoding flag field.
- Minimal logging API that can be defined by apps to route logging to library of choice, or default to java.util.logging is used.
- Easier to make collections of small number of elements, like Set.of("","","")
- @Deprecated interface gets new parameters, like since and forRemoval.
- New API that can be used to hind that a spin loop is executing, this info being available for futher use for performance improvements.
- Stack walking API. Easy access to the information in stack traces.
- Support for 2.11.0 Xerces parser.

6.Nashorn
- Allows apps to parse and analyze ECMAScript code, parsing returns Abstract Syntax Tree.
- Implements features introduced in ECMAScript 6, like:
   a)template strings
   b)let, const and block scope
   c)iterators and for..of loops
   d)Map, Set, WeakMap, WeakSet
   e)Symbols
   f)Binary and Octal literals

7.Client Technologies
- Supports in AWT for multi resolution images, in order to adapt to different devices.
- public APIs for JavaFx UI controls and CSS that were previously available only through internal packages.
- @beaninfo replaced with JavaBean, BeanProperty, SwingContainer
- Add TIFF as standard to javax.imageio
- Automatic scale and size of AWT and Swing components to HiDPI on Windows and Linux.
Prior, apps were sized and rendered based on pixels, which led to components too small to read or use.
- New methods to java.awt.Desktop

8.Internationalization
- Support for Unicode 8.0. JDK 8 supported 6.2. 10555 more chars, 29 scripts and 42 blocks.
- Use of Common Locale Data Repository XML based locale data, which was added in JDK 8, as default. Previously, JRE was used.
- Loads properties files in UTF-8. Previously ISO-8859-1 was used. UTF-8 is better at representing non-Latin characters.

What's new in JDK 8(my short version)

JPL - Java Programming Language
1. Lambda expressions
2. Functional interfaces
3. method references
4. default methods
5. repeating annotations
6. type annotations
7. improved type inference

Collections
1. Stream API
2. Performance improvements for HashMaps with Key Collisions.

Compact Profiles - predefined subsets of Java SE platform to enable apps to be deployed on small devices.

JavaFX
1. Modena theme
2. Embedding swing content into JavaFX
3. New controls DatePicker and TreeTableView
4. javafx.print
5. New 3D Graphics features, like Shape3D, Material, LightBase
6. Improved WebView, including WebSockets, Web Workers and Web Fonts
7. Support for HiDPI displays
8. CSS Styleable classes made public
9. JavaFX available for ARM now

Tools
1. jjs command to invoke Nashorn engine
2. java command launches JavaFX apps
3. jdeps command line tool is provided for analyzing class files.
4. JMX (Java Management Extensions) provide remote access to diagnostic commands
Other Javac and Javadoc tool

Internationalization
1. New Calendar and Locale APIs (Instant, LocalDate, LocalTime, ZonedDateTime, Duration, Period etc.)
2. Unicode 6.2.0
3. Adoption of Unicode CLDR Data

Date-Time Package - a new set of packages that provide a comprehensive date-time model

Scripting
1. Rhino Javascript engine replaced by Nashorn

IO and NIO
1. Performance improvement for the java.lang.String(byte[], *) constructor and the java.lang.String.getBytes() method

java.lang and java.util
1. Parallel Array Sorting
2. Standard Encoding and Decoding Base64

Concurrency
1. New classes and improvements to java.util.concurrent

HotSpot
1. Removal of PermGen in favor of Metaspace. PermGen was continuously responsible for OutOfMemory.
PermGen contained class metadata, static content, String Pool (String interning).
PermGen was fixed in size and not eligible for GC.

Monday, November 9, 2020

Git commands cheatsheet

1.  git clone git@server:username/repo_name.git - basic command that usually you don't need to remember as you copy it from Git SCM/VCS directly.
2.  git pull - retrieves metadata info from origin and brings the changes. git pull = git fetch + git merge. git pull --rebase = git fetch + git rebase.
3.  git fetch - retrieves metadata only.
4.  git diff origin - allows you to compare your local changes to the fetched remote changes. If you don't fetch before, this comparison might not reflect real state of the remote.
5.  git diff origin/master - same as above.
6.  git diff origin/master -- src/path_to_file/file.extension - executes a diff operation on a single explicitly specified file.
7.  git status - allows you to view current state of the branch.
8.  git checkout -b new_branch_name - allows you to checkout a new branch. Local changes only.
9.  git push - allows you to push the local changes to remote. If will show error if you don't have a remote branch, providing the command how to get one as output.
10. git push --set-upstream origin new_branch_name - full command to push a new branch to remote. Usually you don't need to remember it as it is included in the output message of the git push command when no remote branch exists.
11. git checkout master - checks out master branch.
12. git checkout branch_name - attempts to checkout an existing branch with the name: "branch_name".
13. git add . - adds all local changes to the changes to be committed.
14. git add src/path_to_file - adds a specific file to the changes to be committed.
15. git commit -m "Message" - commits the changes, creating a local commit.
16. git diff origin/master origin/branch_name - allows you to compare master to a specific branch.
17. git log --oneline --graph origin/master..origin/custom_username - allows you to observe the commit differences between branches.
18. git log -n 10 --oneline - lists the last 10 commits in a shortened oneline form
19. git branch -r --list *keyword* - will allow you to search for all branches which contain the keyword in their name.
20. git merge master - allows you to merge master into your currently checked out branch.
21. git rebase master - allows you to rebase master into your currently checked out branch.
22. git mergetool - used when you are solving conflicts from console, to launch the configured merge tool. It can be vim by default, or TortoiseGit, which I prefer.
23. :wq! - vim command to write and quit the vim interface.
24. :q! - vim command to quit without committing.
25. i - enter edit mode in vim.
26. ESC - exit edit mode in vim.
27. git clean -fd - remove all, let's say, unnecessary files and folders.
28. git reset --hard origin/branch_name - resets current branch to the remote state, discarding all changes.
29. git reset --soft origin/branch_name - resets current branch to the remote state, preserving changes in an uncommitted state.
30. git checkout commit_id - checks out a specific commit by its ID.
31. git checkout . - checks out current directory state, resetting it to the HEAD. Basically used to discard current changes.
32. git reset --hard HEAD~2 - resets current branch to the HEAD - 2 commits behind, while not preserving the changes in those 2 commits. You can do this for virtually any number of commits.
33. git cherry-pick commit_id - cherry picks a commit into current branch.
34. git push -f - force push to remote of the branch. Necessary if you've done git rebase master and your local and remote branches diverged.
35. git branch -d branch_name - allows to delete local branch, when no local changes exist compared to remote.
36. git branch -D branch_name - allows to force delete local changes, even if local changes exist.
37. git branch -a - show all branches, including remote.
38. git branch -r - show remote branches only.
39. git branch - shows local branches only.
40. git push --delete origin branch_name - deletes the remote branch.
41. git branch -m new_branch_name - renames the branch. This does not affect remote branch name.
42. git branch -M new_branch_name - renames the branch, if it has only Capital Letter Changes.
43. git branch --set-upstream-to origin/remote_branch_name - changes the upstream of the currently checked out branch.
44. git checkout -b branch_name --track origin/remote_branch_name - creates a new branch that tracks an existing remote branch.
45. git stash - saves your current changes into a stack that you can apply or pop later.
46. git stash push -m "some comment" - saves your current changes into a stack that you can apply or pop later, with comment
47. git stash list - List all stash.
48. git stash apply stash@{n} - Apply stash under n index, keeping it there. If you want to remove the stash, use pop instead
49. git stash apply - applies your saved changes to current branch while preserving them in stash.
50. git stash pop - applies your saved changes to current branch while removing them from stash.
51. git revert HEAD - reverts the latest commit on your branch by adding a revert commit.
52. git revert HEAD~1 - reverts the latest commit - 1 on your branch by adding a revert commit.
53. gitk - embedded into git bash history viewer tool.

Useful standalone tools: TortoiseGit
Merge vs rebase visual comparison:
EASY TO COPY LIST:
git clone git@server:username/repo_name.git
git pull
git fetch
git diff origin git diff origin/master
git diff origin/master-- src/path_to_file/file.extension
git status
git checkout -b new_branch_name
git push
git push --set-upstream origin new_branch_name
git checkout master
git checkout branch_name
git add .
git add src/path_to_file
git commit -m "Message"
git diff origin/master origin/branch_name
git log --oneline --graph origin/master..origin/custom_username
git log -n 10 --oneline
git branch -r --list *keyword*
git merge master
git rebase master
git mergetool
git clean -fd
git reset --hard origin/branch_name
git reset --soft origin/branch_name
git checkout commit_id
git checkout .
git reset --hard HEAD~2
git cherry-pick commit_id
git push -f
git branch -d branch_name
git branch -D branch_name
git branch -a
git branch -r
git branch
git push --delete origin branch_name
git branch -m new_branch_name
git branch -M new_branch_name
git branch --set-upstream-to origin/remote_branch_name
git checkout -b branch_name --track origin/remote_branch_name
git stash
git stash push -m "some comment"
git stash list
git stash apply stash@{n}
git stash apply
git stash pop
git revert HEAD
git revert HEAD~1
gitk