10 Java Tips – Series I

Java Tips

10 Java Tips – あなたは知らねばならない,,en,Javaでのメモリ管理,,en,インタフェースは目的を達成するために導入されたもので、Objective C,,en,Java言語からの複数の継承を省略する理由は、主に,,en,簡単な言葉として,,en,Javaの作成者は、大部分の開発者が大規模なトレーニングなしに理解できる言語を求めていました,,en,C の不要な複雑さを乗り越えることなく,,en,デザイナー,,en,意見,,en,多重継承は、より多くの問題と混乱を引き起こします,,en,そこで彼らは言語から複数の継承を削除しました,,en,演算子のオーバーロードを削減するのと同じように,,en,デザイナー,,en,豊富なC の経験は、複数の継承が頭痛の価値がないことを教えてくれました,,en,Javaの設計者は、インタフェースを使用して複数のインタフェースの継承を許可することを選択しました,,en

メモリはJavaで管理されている方法?

In Java manual memory allocation and de-allocation has been eliminated. Memory in Java is automatically garbage collected so you never have to worry about memory corruption. Java memory is managed by the memory model. The Java Memory model explains synchronization techniques to make sure data corruption does not take place. Synchronization can also help to avoid deadlocks between threads and run programs smoothly. The following diagram gives an overview on java memory management.

Memory management in Java

Image 1: Memory management in Java

Are multiple inheritances possible in java?

No, multiple inheritance is not possible in java. Interface has been introduced to serve the purpose and it has been derived from Objective C.

The reasons for omitting multiple inheritances from the Java language mostly stem from the “simple, object oriented and familiar” goal. As a simple language, Java’s creators wanted a language that most developers could grasp without extensive training. To that end, they worked to make the language as similar to C as possible (familiar) without carrying over C ’s unnecessary complexity (simple).

In the designers’ opinion, multiple inheritance causes more problems and confusion than it solves. So they cut multiple inheritances from the language (just as they cut operator overloading). The designers’ extensive C experience taught them that multiple inheritances just weren’t worth the headache.

代わりに, Java’s designers chose to allow multiple interface inheritance through the use of interfaces, Objective Cのプロトコルから借りたアイデア,,en,複数のインタフェースの継承により、オブジェクトは、継承するオブジェクトがそれらの継承されたメソッドを実装しなければならないという注意を払って、多くの異なるメソッドシグネチャを継承できます,,en,Javaの11の設計目標は何ですか?,,en,以下は、Javaプログラミング言語の11の設計目標です,,en,Javaデザイナーは、これらの目標を念頭に置いてタスクを達成しました,,en,オブジェクト指向,,en,解釈された,,en,分散,,en,ロバスト,,en,マルチスレッド,,en,安全な,,en,動的,,en,建築中立,,en,なぜjavaは分散型と呼ばれるのですか?,,en,Javaには、HTTPやFTPなどのTCP / IPプロトコルを処理するための豊富なルーチンライブラリがあります,,en,そのため、JavaアプリケーションはURL経由でインターネット上のオブジェクトを開いたりアクセスしたりすることができます,,en,Javaを使用したネットワークプログラミングは強力で使いやすいです,,en,したがって、Javaは分散型と呼ばれます,,en. Multiple interface inheritance allows an object to inherit many different method signatures with the caveat that the inheriting object must implement those inherited methods.







What are the eleven design goals of java?

Following are the eleven design goals of java programming language. Java designers have accomplished the task by keeping these goals in mind.

  • Simple
  • Portable
  • Object Oriented
  • Interpreted
  • Distributed
  • ハイパフォーマンス
  • Robust
  • Multithreaded
  • Secure
  • Dynamic
  • Architecture Neutral

Why java is called distributed?

Java has an extensive library of routines for handling TCP/IP protocols like HTTP and FTP. So Java applications can open and access objects across the internet via URLs. The network programming using java is strong and easy to use. So java is called distributed.

動的なクラスローディング機能と組み合わせると、Javaの分散された性質が本当に輝きます,,en,これらの機能により、Javaインタープリタはインターネットからコードをダウンロードして実行することができます,,en,WebブラウザがJavaアプレットをダウンロードして実行すると、これが起こります,,en,シナリオはこれより複雑になる可能性があります,,en,Javaで書かれたマルチメディア・ワードプロセッサを想像してみてください。,,en,このプログラムが以前に遭遇したことのない何らかのタイプのデータを表示するように要求されたとき,,en,データを解析できるネットワークからクラスを動的にダウンロードすることがあります,,en,別のクラスを動的にダウンロードする,,en,おそらくJava,,en,複合文書内のデータを表示することができる,,en,このようなプログラムは、ネットワーク上の分散リソースを使用して、ユーザーのニーズに合わせて動的に成長し、適応します,,en. Together, these features make it possible for a Java interpreter to download and run code from across the Internet. This is what happens when a Web browser downloads and runs a Java applet, 例えば. Scenarios can be more complicated than this, however. Imagine a multi-media word processor written in Java. When this program is asked to display some type of data that it has never encountered before, it might dynamically download a class from the network that can parse the data, and then dynamically download another class (probably a Java “bean”) that can display the data within a compound document. A program like this uses distributed resources on the network to dynamically grow and adapt to the needs of its user.

なぜJavaがアーキテクチャニュートラルと呼ばれるのか,,en,Javaコンパイラは、コンピュータアーキテクチャに依存しないバイトコード命令を生成する,,en,バイトコードは、どのマシンでも容易に解釈できるように設計されており、即座にネイティブマシンコードに変換されます,,en,次の図は、その動作の詳細を示しています,,en,Javaアーキテクチャニュートラル,,en,Java対応のブラウザがアプレットを実行するために必要な理由,,en,アプレットはWebページ上で動作するJavaプログラムです,,en,したがって、ブラウザには、バイトコードを解釈して機能させる機能が必要です,,en,そのため、Webページに埋め込まれたアプレットを実行するにはJava対応ブラウザが必要です,,en,実際には、ブラウザにはバイトコードの解釈と出力の表示に役立つJVMが組み込まれています,,en?

The Java compiler generates a bytecode instruction which is independent of computer architecture. The bytecode is designed to be both easy to interpret on any machine and easily translated into native machine code on the fly. The following diagram shows the details how it works.

Java architecture neutral

Image 2: Java architecture neutral

Why java enabled browser is needed to run an applet?

Applet is a java program that works on a web page. So the browser should have the capability to interpret the bytecode and make it work. That is why java enabled browser is required to run an applet embedded in a web page. Actually the browser contains the JVM inbuilt which helps to interpret the byte code and show the output.

「Javaは強く型付けされた言語です」とはどういう意味ですか?,,en,Javaは強く型付けされているということは、javaのすべての変数は宣言された型,,en,Javaには8つのプリミティブ型があります,,en,4つは整数型で、2つは浮動小数点型です,,en,1つは文字タイプchar,,en,Unicodeエンコーディングの文字に使用され、1つは真偽値のブール型です,,en,JavaでI / Oをどのように管理するか,,en,Java I / Oでは入力ストリームと出力ストリームを表します,,en,ストリームは、ファイルやネットワーク、コンソールなどのデバイスの読み書きに使用されます。,,en,Java.ioパッケージは、ストリームを操作するためのI / Oクラスを提供します,,en,このパッケージは2種類のストリームをサポートしています,,en,バイナリデータを扱うバイナリストリームと、文字データを扱う文字ストリーム,,en?

Java is strongly typed means that every variable in java must have a declared type. There are eight primitive types in Java. Four of them are integer types and two are floating-point number types. One is the character type char, used for characters in the Unicode encoding and one is a Boolean type for truth values.







How I/O is managed in java?

In java I/O represents Input and Output streams. Streams are used to read from or write to devices such as file or network or console. Java.io package provides I/O classes to manipulate streams. This package supports two types of streams – binary streams which handle binary data and character streams which handle character data. InputStreamとOutputStreamは、バイナリストリームを操作するための高水準インタフェースです,,en,リーダとライタは、文字ストリームを操作するための高水準のインタフェースです,,en,次の図は、このセクションで扱うさまざまなIOクラスの関係を示しています,,en,異なるI / Oクラス,,en,バッファリングされたストリームはJavaのパフォーマンスをどのように向上させますか,,en,ストリームのデフォルトの動作は、一度に1バイトを読み書きすることです,,en,これは、大量のデータを扱うときに1バイトずつ読み書きするのに時間がかかるため、I / Oパフォーマンスが低下します,,en,Java I / Oは、バイト単位のデフォルト動作をオーバーライドするバッファ付きストリームを提供します。,,en,バッファリングされたストリームを使用する必要があります,,en,BufferedInputStreamおよびBufferedOutputStream,,en,データをバッファリングしてから読み込み/書き込みを行い、パフォーマンスが良い,,en. Reader and Writer are high level interfaces for manipulating character streams.

The following figure shows the relationship of different IO classes addressed in this section

Different I/O classes

Image 3: Different I/O classes

How does buffered stream improve performance in java?

The default behavior of a stream is to read or write one byte at a time. This causes poor I/O performance because it takes lot of time to read/write byte by byte when dealing with large amounts of data. Java I/O provides Buffered streams to override these byte by byte default behaviors. You need to use Buffered streams (BufferedInputStream and BufferedOutputStream) to buffer the data and then read/write which gives good performance. メソッドのデフォルト動作を理解し、それに基づいて動作する必要があります,,en,次の図は、バッファリングされたストリームがデータフローをどのように迂回するかを示しています,,en,バッファリングされたストリーム,,en,ファイルの読み込みのデフォルト動作とバッファリングのパフォーマンスをどのように測定しますか,,en,次のコードスニペットは、既定の読み取りとバッファ付きの読み取りを使用して、読み取りと書き込みを行う同様のファイルを取ります,,en,そして、両方の時間が表示されます,,en,コードをテストするには、以下のようにファイルをローカルファイルシステムに保管してください,,en,ファイルの読み込みのためのバッファリング,,en,package com.performance.io,,en,パブリッククラスIOTest,,en,IOTest io =新しいIOTest,,en,長いstartTime = System.currentTimeMillis,,en,io.readWrite,,en,temp / test-origin.html,,en,temp / test-destination.html,,en,long endTime = System.currentTimeMillis,,en,既定の動作を使用して読み書きするのにかかる時間,,en,終了時間,,en,始まる時間,,en,ミリ秒,,kn.

The following figure shows how buffered streams divert the data flow.

Buffered streams

Image 4: Buffered streams

How do you measure performance of default behavior and buffering for file reading?

The following code snippet will take similar files to read and write using default reading and buffered reading. And then it will display the time taken by both of them. For testing the code keep the files in local file system as shown below.

Listing 1: Buffering for file reading

package com.performance.io;

import java.io.*;

public class IOTest {

公共の静的な無効メイン(文字列[] argsに){

IOTest io = new IOTest();

試す{

long startTime = System.currentTimeMillis();

io.readWrite(“C言語:/temp/test-origin.html”,”C言語:/temp/test-destination.html”);

long endTime = System.currentTimeMillis();

System.out.printlnは(“Time taken for reading and writing using default behaviour : ”

+ (endTime – startTime) + ” milli seconds” );

長いstartTime1 = System.currentTimeMillis,,en,io.readWriteBuffer,,en,long endTime1 = System.currentTimeMillis,,en,バッファリングされたストリームを使用して読み書きする時間,,en,endTime1,,en,startTime1,,fi,public static void readWrite,,en,文字列fileFrom,,fy,String fileTo,,el,InputStream in = null,,en,OutputStream out = null,,en,in =新しいFileInputStream,,en,ファイルから,,fy,out =新しいFileOutputStream,,en,fileTo,,el,int bytedata = in.read,,en,バイトデータ==,,sv,バイトデータ,,sv,最後に,,en,in.close,,en,public static void readWriteBuffer,,en,InputStream inBuffer = null,,en,OutputStream outBuffer = null,,en,InputStream in =新しいFileInputStream,,en,inBuffer =新しいBufferedInputStream,,en,OutputStream out =新しいFileOutputStream,,en,outBuffer =新しいBufferedOutputStream,,en,int bytedata = inBuffer.read,,en,inBuffer,,en,inBuffer.close,,en,outBuffer,,en,outBuffer.close,,en,techalpine.com/10-java-tips-series-i,,en();

io.readWriteBuffer(“C言語:/temp/test-origin.html”,”C言語:/temp/test-destination.html”);

long endTime1 = System.currentTimeMillis();

System.out.printlnは(“Time taken for reading and writing using buffered streams : ”

+ (endTime1 – startTime1) + ” milli seconds” );

}キャッチ(IOExceptionが電子){ e.printStackTrace();}

}

public static void readWrite(String fileFrom, String fileTo) throws IOException{

InputStream in = null;

OutputStream out = null;

試す{

in = new FileInputStream(fileFrom);

out = new FileOutputStream(fileTo);

while(真){

int bytedata = in.read();

場合(bytedata == -1)

break;

out.write(bytedata);

}

}

キャッチ(Exception e)

{

e.printStackTrace();

}

finally{

場合(in != null)

in.close();

場合(外に !=null)

out.close();

}

}

public static void readWriteBuffer(String fileFrom, String fileTo) throws IOException{

InputStream inBuffer = null;

OutputStream outBuffer = null;

試す{

InputStream in = new FileInputStream(fileFrom);

inBuffer = new BufferedInputStream(in);

OutputStream out = new FileOutputStream(fileTo);

outBuffer = new BufferedOutputStream(外に);

while(真){

int bytedata = inBuffer.read();

場合(bytedata == -1)

break;

out.write(bytedata);

}

}

キャッチ(Exception e)

{

e.printStackTrace();

}

finally{

場合(inBuffer != null)

inBuffer.close();

場合(outBuffer !=null)

outBuffer.close();

}

}

)







============================================= ============================================== Amazonで最高のTechAlpine Booksを購入してください,en,電気技師CT栗,en
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share