Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e1fb9d

Browse files
authored
Merge pull request#2 from coderolls/blog/2020-12-19-uuid-guide
Add new blogpost and a gem 'kramdown-parser-gfm' in Gemfile
2 parents42429cd +059faab commit5e1fb9d

File tree

4 files changed

+150
-1
lines changed

4 files changed

+150
-1
lines changed

‎Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ group :jekyll_plugins do
1717
gem'jekyll-archives'
1818
gem'kramdown'
1919
gem'rouge'
20+
gem'kramdown-parser-gfm'
2021
end

‎Gemfile.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ GEM
4444
listen (~>3.0)
4545
kramdown (2.3.0)
4646
rexml
47+
kramdown-parser-gfm (1.1.0)
48+
kramdown (~>2.0)
4749
liquid (4.0.3)
4850
listen (3.2.1)
4951
rb-fsevent (~>0.10,>=0.10.3)
@@ -63,6 +65,7 @@ GEM
6365
sass-listen (4.0.0)
6466
rb-fsevent (~>0.9,>=0.9.4)
6567
rb-inotify (~>0.9,>=0.9.7)
68+
wdm (0.1.1)
6669

6770
PLATFORMS
6871
ruby
@@ -75,7 +78,9 @@ DEPENDENCIES
7578
jekyll-seo-tag
7679
jekyll-sitemap
7780
kramdown
81+
kramdown-parser-gfm
7882
rouge
83+
wdm (>=0.1.0)
7984

8085
BUNDLED WITH
81-
2.0.2
86+
2.1.4
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
layout:post
3+
title:"Your Guide To UUID In Java"
4+
author:gaurav
5+
image:assets/images/2020-12-19/uuid.png
6+
categories:[ Java, Core Java, String]
7+
description:In this article you will learn what is UUID and about the Java UUID class.
8+
featured:false
9+
10+
---
11+
12+
In this article we will see,
13+
- What is UUID?
14+
- Java UUID class
15+
16+
##What is UUID?
17+
18+
UUID, a universally unique identifier is a 128-bit number used to identify information in computer systems.
19+
20+
UUID is made of hex digits along with 4 hyphen ("-") symbols. The length of a UUID is 36 characters.
21+
22+
There are 4 types of UUID
23+
24+
1. Time-based UUID (Version 1)
25+
2. DCE Security UUID (Version 2)
26+
3. Name-based UUID (Version 3 and 5)
27+
4. Randomly Generated UUID (Version 4)
28+
29+
Mostly Randomly Generated UUID i.e. UUID Version 4 is used.
30+
31+
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
32+
33+
There are 4 types of UUID variant
34+
35+
-**0:** It is reserved for NCS backward compatibility
36+
-**2:** Leach-Salz
37+
-**6:** It is reserved for Microsoft backward compatibility
38+
-**7:** It is reserved for future definition.
39+
40+
Mostly the variant 2 is used.
41+
42+
UUID can be used in the following cases
43+
44+
- As a primary key of database table
45+
- To create session id for web application
46+
- To represent as transaction id
47+
- To create a random file name
48+
49+
###Example UUID
50+
51+
df6fdea1-10c3-474c-ae62-e63def80de0b
52+
53+
![Structure of UUID](/assets/images/2020-12-19/uuid.png)
54+
##Java UUID class
55+
56+
UUID Class belongs to the`java.util` package. It represents an immutable universally unique identifier (UUID).
57+
58+
UUID Constructor
59+
60+
```java
61+
`[UUID](https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html#UUID-long-long-)(long mostSigBits, long leastSigBits)`
62+
```
63+
Constructs anew `UUID` using the specified data.
64+
65+
### Static methods
66+
There are three static methods of a UUID class,
67+
68+
```java
69+
UUID.fromString(String name)
70+
```
71+
The above method creates aUUID from the string standard representation as described in the [toString()](https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html#toString--) method.
72+
73+
```java
74+
UUID.nameUUIDFromBytes(byte[] name)
75+
```
76+
This method is used to create a version3 (name based)UUID based on the specifiedbyte array.
77+
78+
```java
79+
UUID.randomUUID()
80+
```
81+
This method is used to create a version4 (pseudo randomly generated)UUID.
82+
83+
###Instance methods
84+
85+
Also there are a few instance methods of aUUID class.
86+
87+
```java
88+
clockSequence()
89+
```
90+
This method is used to get the the clock sequence value associated withthisUUID.
91+
92+
This method returns the clock sequence value as `int`.
93+
94+
```java
95+
compareTo(UUID val)
96+
```
97+
This method is used to comparethisUUID with the specifiedUUID ( the one received as method param i.e. `val`
98+
99+
This method returns-1,0 or1 asthis `UUID` is less than, equal to, or greater than `val`
100+
101+
```java
102+
equals(Object obj)
103+
```
104+
This method simply comparesthis object to the specified object.Itreturn the result in `boolean`
105+
106+
```java
107+
node()
108+
```
109+
This method returns the node value (`long`) associated withthisUUID.
110+
111+
```java
112+
timestamp()
113+
```
114+
This method returns the timestamp value (`long`) associated withthisUUID.
115+
116+
```java
117+
toString()
118+
```
119+
This method returns a `String` object representingthisUUID.
120+
121+
```java
122+
variant()
123+
```
124+
This method returns the variant number (`int`) associated withthisUUID.
125+
126+
```java
127+
version()
128+
```
129+
This method returns the version number (`int`) associated withthisUUID.
130+
131+
--------
132+
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.
133+
134+
If you foundthis article worth, support me by [giving a cup ofCoffee ☕](https://www.paypal.me/GauravKukade)
135+
136+
####RelatedArticles
137+
138+
- [LearnAboutJavaStringPoolAnd intern()Method](https://coderolls.com/java-string-pool-and-intern-method/)
139+
- [HowDoICompareStringsInJava](https://coderolls.com/compare-strings-in-java/)
140+
- [HowToReverseAStringInJava (5 ways)](https://coderolls.com/reverse-a-string-in-java/)
141+
- [CompareTwoStringsLexicographicallyInJava](https://coderolls.com/compare-two-strings-lexicographically-in-java/)
142+
- [Introduction toJavaTechnology (Language andPlatform)](https://coderolls.com/java-introduction/)
143+

‎assets/images/2020-12-19/uuid.png

20.5 KB
Loading

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp