Last active
August 19, 2020 01:06
-
-
Save ponsuke0531/c9de55c7f7eed2134bd8e0b8fddc4f26 to your computer and use it in GitHub Desktop.
Javaの基本を教えてくれるサイト集 ref: https://qiita.com/ponsuke0531/items/971af69f49825dc0bdab
This file contains 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
A.compareTo(B); |
This file contains 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
Date onlyDateA = clearTime(dateWithTimeA); | |
Date onlyDateB = clearTime(dateWithTimeB); | |
onlyDateA.compareTo(onlyDateB); | |
/** | |
* 引数の日時の時刻部分をリセットする. | |
* @param dateWinthTime 時間が設定されている日付. | |
* @return 時刻部分をリセットした日付. | |
*/ | |
private Date clearTime(Date dateWinthTime) { | |
return new Date(DateUtils.truncate(dateWinthTime, java.util.Calendar.DAY_OF_MONTH).getTime()); | |
} |
This file contains 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
A.compareTo(B); |
This file contains 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
// 比較したい | |
A.equals(B); | |
// 速く結合したい | |
StringBuilder stringBuilder = new StringBuilder(); | |
stringBuilder.append(A); | |
stringBuilder.append(B); | |
// 特定文字の出現回数を知りたい | |
int shutsugenCount = (mojiretsu.length() - mojiretsu.replaceAll(tokuteiMoji, "").length()) / tokuteiMoji.length(); |
This file contains 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
// 比較したい | |
A.compareTo(B); |
This file contains 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
// String>>float変換 | |
float f = Float.parseFloat("string"); |
This file contains 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
System.currentTimeMillis(); | |
System.nanoTime(); |
This file contains 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
System.currentTimeMillis(); | |
System.nanoTime(); |
This file contains 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
System.currentTimeMillis(); | |
System.nanoTime(); |
This file contains 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
System.currentTimeMillis(); | |
System.nanoTime(); |
This file contains 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
System.currentTimeMillis(); | |
System.nanoTime(); |
This file contains 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
$ jar xvf {jarとかwarファイル} {jarとかwarファイル内でのファイルパス} |
This file contains 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
// ファイルを抽出する | |
jar xvf {jarとかwarファイル} {jarとかwarファイル内でのファイルパス} |
This file contains 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
● 具象クラスであること | |
● 引数なしのデフォルトコンストラクタを持つこと | |
● static付きのインナークラスではないこと |
This file contains 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
-- Oracle | |
DECODE(kokyaku_rank, 1, '優', 2,'良', 3,'可', '不可') | |
-- Postgresql | |
CASE kokyaku_rank WHEN 1 THEN '優' WHEN 2 THEN '良' WHEN 3 THEN '可' ELSE '不可' END |
This file contains 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
// 速く結合したい | |
StringBuilder stringBuilder = new StringBuilder(); | |
stringBuilder.append(A); | |
stringBuilder.append(B); | |
// 特定文字の出現回数を知りたい | |
int shutsugenCount = (mojiretsu.length() - mojiretsu.replaceAll(tokuteiMoji, "").length()) / tokuteiMoji.length(); |
This file contains 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
// equals版 | |
A.equals(B); | |
// compareTo版:辞書的な並び順で返却値が変わる | |
String str1 = "1"; | |
String str2 = "2"; | |
String str3 = "3"; | |
str2.compareTo(str3); // -1 | |
str2.compareTo(str2); // 0 | |
str2.compareTo(str1); // 1 | |
str2.compareTo(null); // 1 |
This file contains 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
JavaEE7からのCDIビーンクラスの基本条件 | |
a. 具象クラスであること | |
b. 引数なしのデフォルトコンストラクタを持つこと | |
c. static付きのインナークラスではないこと | |
JSFのaction属性に指定するメソッドのルール | |
a. publicであること | |
b. 引数がないこと | |
c. Stringを返値とすること。この返値がoutcomeになります。 |
This file contains 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
/** 正規表現として使うのにエスケープが必要な文字群\*+.?{}()[]^$-|/. */ | |
private static final String CHARACTERS_NEED_ESCAPE = "\\*+.?{}()[]^$-|/"; |
This file contains 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
private String getEscapedKigo(String hankakuKigo) { | |
StringBuilder sb = new StringBuilder(); | |
for (int i = 0; i < hankakuKigo.length(); i++) { | |
String c = String.valueOf(hankakuKigo.charAt(i)); | |
sb.append(Matcher.quoteReplacement(c)); | |
} | |
return sb.toString(); | |
} |
This file contains 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
// 一回の呼び出し(リクエスト)とそれへの応答(レスポンス)の間存続 | |
@RequestScoped | |
// HTTPセッションが続いている間(ログインしている間)存続 | |
@SessionScoped | |
// ウェブアプリケーションが実行されている間存続 | |
@ApplicationScoped | |
// 一回以上のリクエストの間で、開始と終了をプログラムで制御する | |
@ConversationScoped | |
// インジェクト先のスコープを引き継ぐ(予めスコープを決められない場合に使う) | |
@Dependent | |
// リクエストにより表示されたJSFページが他のページへ切り替わる直前まで存続 | |
@ViewScoped |
This file contains 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
import org.apache.commons.lang3.RandomStringUtils; | |
String randamString = RandomStringUtils.random([文字数], [使いたい文字の文字列]); |
This file contains 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
str.trim(); | |
StringUtils.stripStart(str, " "); | |
StringUtils.stripEnd(str, " "); |
This file contains 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
System.currentTimeMillis(); | |
System.nanoTime(); |
This file contains 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
// String > float変換 | |
float f = Float.parseFloat("string"); | |
// String > BigDecimal | |
BigDecimal bigDecimal = new BigDecimal(string) | |
// String > Double | |
try { | |
Double.parseDouble(s); | |
} catch (NumberFormatException e) { | |
// 空文字・スペース | |
} catch (NullPointerException e) { | |
// null | |
} | |
// String > int | |
int i = Integer.parseInt(s); | |
// int > String | |
String s = Integer.toString(i); |
This file contains 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
StringBuilder stringBuilder = new StringBuilder(); | |
stringBuilder.append(A); | |
stringBuilder.append(B); |
This file contains 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
-- SELECT対象の全ての表のレコードをロック | |
SELECT 〜 WHERE ... FOR UPDATE; | |
-- 表を結合する場合に使用。行ロックする表を指定 | |
SELECT 〜 WHERE ... FOR UPDATE OF 行ロックする表.列名 [,column_name2...]; | |
-- 対象レコードにロックがかかっていた時に、ロックが開放されるまで待つ | |
SELECT 〜 WHERE ... FOR UPDATE WAIT [待ち時間] | |
-- 対象レコードにロックがかかっていた時に、開放を待たずに下記エラーで復帰 | |
SELECT 〜 WHERE ... FOR UPDATE NOWAIT; |
This file contains 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
// String | |
A.equals(B); | |
// Date | |
A.compareTo(B); |
This file contains 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
int shutsugenCount = (mojiretsu.length() - mojiretsu.replaceAll(tokuteiMoji, "").length()) / tokuteiMoji.length(); |
This file contains 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
stringBuilder.replace(開始インデックス(この値を含む), 終了インデックス(この値を含まない), 対象文字列) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment