Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1
Add new blogpost#2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsGemfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -17,4 +17,5 @@ group :jekyll_plugins do | ||
| gem 'jekyll-archives' | ||
| gem 'kramdown' | ||
| gem 'rouge' | ||
| gem 'kramdown-parser-gfm' | ||
| end | ||
7 changes: 6 additions & 1 deletionGemfile.lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions_posts/2020-12-19-your-guide-to-uuid-in -java.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| --- | ||
| layout: post | ||
| title: "Your Guide To UUID In Java" | ||
| author: gaurav | ||
| image: assets/images/2020-12-19/uuid.png | ||
| categories: [ Java, Core Java, String] | ||
| description: In this article you will learn what is UUID and about the Java UUID class. | ||
| featured: false | ||
| --- | ||
| In this article we will see, | ||
| - What is UUID? | ||
| - Java UUID class | ||
| ## What is UUID? | ||
| UUID, a universally unique identifier is a 128-bit number used to identify information in computer systems. | ||
| UUID is made of hex digits along with 4 hyphen ("-") symbols. The length of a UUID is 36 characters. | ||
| There are 4 types of UUID | ||
| 1. Time-based UUID (Version 1) | ||
| 2. DCE Security UUID (Version 2) | ||
| 3. Name-based UUID (Version 3 and 5) | ||
| 4. Randomly Generated UUID (Version 4) | ||
| Mostly Randomly Generated UUID i.e. UUID Version 4 is used. | ||
| UUID Version 4 uses random numbers as a source. It uses an unpredictable value as the seed to generate random numbers to reduce the chance of collisions | ||
| There are 4 types of UUID variant | ||
| - **0:** It is reserved for NCS backward compatibility | ||
| - **2:** Leach-Salz | ||
| - **6:** It is reserved for Microsoft backward compatibility | ||
| - **7:** It is reserved for future definition. | ||
| Mostly the variant 2 is used. | ||
| UUID can be used in the following cases | ||
| - As a primary key of database table | ||
| - To create session id for web application | ||
| - To represent as transaction id | ||
| - To create a random file name | ||
| ### Example UUID | ||
| df6fdea1-10c3-474c-ae62-e63def80de0b | ||
|  | ||
| ## Java UUID class | ||
| UUID Class belongs to the `java.util` package. It represents an immutable universally unique identifier (UUID). | ||
| UUID Constructor | ||
| ```java | ||
| `[UUID](https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html#UUID-long-long-)(long mostSigBits, long leastSigBits)` | ||
| ``` | ||
| Constructs a new `UUID` using the specified data. | ||
| ### Static methods | ||
| There are three static methods of a UUID class, | ||
| ```java | ||
| UUID.fromString(String name) | ||
| ``` | ||
| The above method creates a UUID from the string standard representation as described in the [toString()](https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html#toString--) method. | ||
| ```java | ||
| UUID.nameUUIDFromBytes(byte[] name) | ||
| ``` | ||
| This method is used to create a version 3 (name based) UUID based on the specified byte array. | ||
| ```java | ||
| UUID.randomUUID() | ||
| ``` | ||
| This method is used to create a version 4 (pseudo randomly generated) UUID. | ||
| ### Instance methods | ||
| Also there are a few instance methods of a UUID class. | ||
| ```java | ||
| clockSequence() | ||
| ``` | ||
| This method is used to get the the clock sequence value associated with this UUID. | ||
| This method returns the clock sequence value as `int`. | ||
| ```java | ||
| compareTo(UUID val) | ||
| ``` | ||
| This method is used to compare this UUID with the specified UUID ( the one received as method param i.e. `val` | ||
| This method returns -1, 0 or 1 as this `UUID` is less than, equal to, or greater than `val` | ||
| ```java | ||
| equals(Object obj) | ||
| ``` | ||
| This method simply compares this object to the specified object. It return the result in `boolean` | ||
| ```java | ||
| node() | ||
| ``` | ||
| This method returns the node value (`long`) associated with this UUID. | ||
| ```java | ||
| timestamp() | ||
| ``` | ||
| This method returns the timestamp value (`long`) associated with this UUID. | ||
| ```java | ||
| toString() | ||
| ``` | ||
| This method returns a `String` object representing this UUID. | ||
| ```java | ||
| variant() | ||
| ``` | ||
| This method returns the variant number (`int`) associated with this UUID. | ||
| ```java | ||
| version() | ||
| ``` | ||
| This method returns the version number (`int`) associated with this UUID. | ||
| -------- | ||
| You can visit my [YouTube channel 'coderolls'](https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w?view_as=subscriber?sub_confirmation=1) to find more video tutorials. | ||
| If you found this article worth, support me by [giving a cup of Coffee ☕](https://www.paypal.me/GauravKukade) | ||
| #### Related Articles | ||
| - [Learn About Java String Pool And intern() Method](https://coderolls.com/java-string-pool-and-intern-method/) | ||
| - [How Do I Compare Strings In Java](https://coderolls.com/compare-strings-in-java/) | ||
| - [How To Reverse A String In Java (5 ways)](https://coderolls.com/reverse-a-string-in-java/) | ||
| - [Compare Two Strings Lexicographically In Java](https://coderolls.com/compare-two-strings-lexicographically-in-java/) | ||
| - [Introduction to Java Technology (Language and Platform)](https://coderolls.com/java-introduction/) | ||
Binary file addedassets/images/2020-12-19/uuid.png
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.