assert とは ここでは JDK 1.4 で導入されたアサーション (assertion) の使い方について説明します。 アサーションはデバッグを支援するための機能です。assert ステートメントを使って、記述します。 assert には常に「真 (true) となると想定している式」を書くことによって開発者が何を想定しているか記述できます。 これがどういう意味か、具体例で示します。 assert の使い方 assert に続けて、常に真 (true) であると考えている式と false と評価された場合に表示するメッセージを、コロン : で区切って記述します。 assert 「常に true となると考えている式」: 「メッセージ」; 具体例でみてみましょう。次の例をみてください。 public class TestApp { public static void main(Str
Just as there was Retroweaver et al. for running Java 5 code with generics on Java 1.4, Retrolambda lets you run Java 8 code with lambda expressions, method references and try-with-resources statements on Java 7, 6 or 5. It does this by transforming your Java 8 compiled bytecode so that it can run on an older Java runtime. After the transformation they are just a bunch of normal .class files, with
概要 java.netで提供されるURLクラスを使用して、URLを簡単に分解できます。 URLに含まれるベーシック認証のユーザ名とパスワードも簡単に取得できます。 parseurl1 ソースコード parseurl1.java /* * parseurl1.java * Copyright (C) 2015 kaoru <kaoru@bsd> */ import java.net.*; public class parseurl1 { public static void main(String[] args) { try { URL url = new URL("http://user:password@foo.com:80/path/to?k1=v1&k2=v2#help"); System.out.println("protocol = " + url.getProtocol() )
2011/08/22 Base64クラスを使ってエンコードとデコードを行う Tweet JavaにはBase64のエンコード、デコードを行うクラスが標準には無いため、フレームワークだったりライブラリで 提供されているのですが、AndroidのSDKにはAPIバージョン8(Android2.2)からBase64クラスが提供されています。 ドキュメントはAndroid Developers Base64にあります。 以下、エンコードとデコードのサンプル //対象の文字列 String org = "ほげほげ"; //文字列のエンコード String encode = Base64.encodeToString(org.getBytes(), Base64.DEFAULT); Log.d("encode",encode); //文字列のデコード String decode = new St
The “Java Decompiler project” aims to develop tools in order to decompile and analyze Java 5 “byte code” and the later versions. JD-GUI is a standalone graphical utility that displays Java source codes of “.class” files. You can browse the reconstructed source code with the JD-GUI for instant access to methods and fields. JD-Eclipse is a plug-in for the Eclipse platform. It allows you to display a
This Java package contains a DFA/NFA (finite-state automata) implementation with Unicode alphabet (UTF16) and support for the standard regular expression operations (concatenation, union, Kleene star) and a number of non-standard ones (intersection, complement, etc.) In contrast to many other automaton/regexp packages, this package is fast, compact, and implements real, unrestricted regular operat
文字列を指定の文字エンコーディングでのバイト数で切る処理を作ってみた。固定バイト長の文字コードであれば指定のバイト長で切る処理というのはさほど難しいところはないのだが。 たとえば、"1234" という ASCII 文字列を、3 バイトで切りたい場合、"123"。文字数とバイト数が一致するため、もっとも簡単だ。 しかし、ShiftJIS 等の主要な文字コードでは、文字種によってバイト長が変化する。結局のところ、指定のバイト数に何文字まで入るか、というのはその文字コードに変換してみないとわからない。 Java では文字の内部表現は普通 UTF-8 だけど、DB では EUC で、カラム長は 256 バイト。というような場合。カラム長がバイト指定なのが全部悪いんだが。 で、先日見たとあるロジックはこの「文字列を指定の文字エンコーディングでのバイト数で切る処理」を実装してたのだが、なかなか気になる
Not your computer? Use a private browsing window to sign in. Learn more about using Guest mode
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く