Differences between Java and .NET Framework

List some of the differences I've learned


stream

Java is InputStream (java.io.InputStream) and OutputStream (java.io.OutputStream http://docs.oracle.com/javase/jp/6/api/org/omg/CORBA/portable/OutputStream.html)) It is divided into two parts, input and output.

On the other hand, in the .NET Framework, it is called Stream (System.IO.Stream). As you can see, the input and output are unified.

But,

// C # sample code DeflateStream compressionStream = ne w DeflateStream(compressedFileStream, CompressionMode.Compress));

If you do, the output system (write) is good, but if you try to input (read), an error will occur, so it will hurt if you think that you can always input and output.


End of stream

java is "-1" .NET Framework is "0". (Only readByte () method is "-1")


Stream (Copy To)

.NET Framework 4 and later CopyTo (distStream) methods are useful


Filter stream

In Java, there are classes of the concept of filter streams (java.io.FilterInputStream and java.io. FilterOutputStream), so make it by inheriting it

There is no such thing in the .NET Framework, it is created by inheriting Stream


Memory stream

Java is java.io.ByteArrayInputStream and java.io.ByteArrayOutputStream .oracle.com/javase/jp/6/api/java/io/ByteArrayOutputStream.html)

.NET Framework is System.IO.MemoryStream

Both Java / .NET Framework are difficult to use in situations where data is generated in real time → read () ends.


Memory stream (corresponding to chorochoro)

Java is java.io.PipedInputStream and java.io.PipedOutputStream .oracle.com/javase/jp/6/api/java/io/PipedOutputStream.html)

.NET Framework doesn't know such classes Suffice it to say, the anonymous pipe class (System.IO.Pipes.AnonymousPipeClientStream. aspx) and System.IO.Pipes.AnonymousPipeServerStream)


Cryptographic / hash etc. (Java)

Java is fine

--Cryptography -javax.crypto.CipherInputStream and [javax.crypto.CipherOutputStream](http://docs. oracle.com/javase/jp/6/api/javax/crypto/CipherOutputStream.html) --The substance of them javax.crypto.Cipher --Hash -java.security.DigestInputStream and [java.security.DigestOutputStream](http://docs. oracle.com/javase/jp/6/api/java/security/DigestOutputStream.html) --The substance of them java.security.MessageDigest


Cryptographic / hash etc. (.NET Framework)

Treated in a unified manner

Base class

System.Security.Cryptography.ICryptoTransform Assigned to the above class as an interface

--Cryptography -CreateEncryptor / CreateDecryptor method of System.Security.Cryptography.SymmetricAlgorithm --Hash --[System.Security.Cryptography.HashAlgorithm] inherited from ICryptoTransform [https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hashalgorithm(v=vs.110).aspx)

HMAC under HashAlgorithm

There is.


compression

Both Java / .NET Framework did not have the function to compress in real time, but from Java7 [java.util.zip.Deflater#SYNC_FLUSH](http://docs.oracle.com/javase/jp/8/docs/api/ java / util / zip / Deflater.html) has been added to enable real-time zlib compression.

For the .NET Framework, you can use zlib.NET.dll. How to perform compression synchronously (real time) with C # /.NET Framework


SSL

Java inherits java.net.Socket javax.net.ssl.SSLSocket //docs.oracle.com/javase/jp/6/api/javax/net/ssl/SSLSocket.html)

.NET Framework inherits System.IO.Stream System.Net .Security.SslStream

The .NET Framework inherits Stream, while Java branches into InputStream / OutputStream !? Socket inherits


SSL option (Java)

Java is versatile

--Protocol / cipher suites supported as JavaVM


SSL option (.NET Framework)

.NET Framework only protocol control !?


Reader/Writer

Both Java / .NET Framework are unified with internal character code UTF16.

Java is basically prepared for each implementation AudioFileReader, FileReader, FilterReader, InputStreamReader, LineNumberReader, PipedReader, PushbackReader, Reader, XMLStreamReader .... too many

The .NET Framework includes System.IO.StreamReader and System.IO. StreamWriter


Reader ReadToEnd ()

System.IO.StreamReader.ReadToEnd () is convenient.

Close to ReadAll () for file operations in VisualBASIC6.0 (Scripting.FileSystemObject). Very convenient.


Multicast UDP

Multicast is implemented as UDP in both .NET Framework / Java

Java inherits java.net.DatagramSocket which is the substance of UDP [java.net.MulticastSocket] ](Http://docs.oracle.com/javase/jp/6/api/java/net/MulticastSocket.html)

The .NET Framework is the entity of UDP [System.Net.Sockets.UdpClient](https://msdn.microsoft.com/ja-jp/library/system.net.sockets.udpclient (v = vs.110). aspx) itself


sound

In Java, it is javax.sound.sampled.AudioInputStream that inherits Stream, so recording is easy. it can.

The output (audio playback to the speaker) is not Stream, but you can easily create a wrapper that inherits Stream.

The .NET Framework can only use Managed DirectX (MDX) or 3rd Party's SlimDX, but coding may be quite difficult.


Web(HttpClient)

Java inherits java.net.URLConnection [java.net.HttpURLConnection](http: / /docs.oracle.com/javase/jp/6/api/java/net/HttpURLConnection.html) "http only" and its children javax.net.ssl.HttpsURLConnection /javase/jp/6/api/javax/net/ssl/HttpsURLConnection.html) "For https"

.NET Framework inherits System.Net.WebRequest System.Net .HttpWebRequest "http / https combined use"

Android has org.apache.http.client.HttpClient class


Type of type

Java is basic such as int, long (only necessary and sufficient)

.NET Framework is various such as Int32, UInt32 ,,,


byte type

Java is -128 to 127 (Be careful when converting to and from JRuby / Jython)

.NET Framework 0-255

Personally, I don't understand the meaning of negative numbers in byte type.


Static method

Java can put static methods in instantiated objects → You can call it with this

.NET Framework cannot be called with this


thread

Java calls the class itself java.lang.Thread class (java.lang.Runnable //docs.oracle.com/javase/jp/6/api/java/lang/Runnable.html) Inherit and implement the interface) → Threads can be said to be class units

.NET Framework registers the method in System.Threading.Thread → Threads can be said to be method units


Lock processing

Java lock is "synchronized"

Various .NET Framework locks (with the evolution of Windows ...)


Base64

Java.util.Base64 from JDK8

.NET Framework Base64 in many places


URL encoding

Java URL encoding (java.net.URLEncoder and [java.net.URLDecoder](http: //docs.oracle.com/javase/jp/6/api/java/net/URLDecoder.html)) is a character string → Cannot be used


String comparison

Java string comparison is equals () method


switch statement

You cannot switch () with a string in Java. → Solved with Java 8 !?


Zlib real-time compression

How to perform compression synchronously (real time) with C # /.NET Framework


XML xref

Java is [javax.xml.parsers.DocumentBuilder # setEntityResolver () method](https://docs.oracle.com/javase/jp/6/api/javax/xml/parsers/DocumentBuilder.html#setEntityResolver (org.xml) .sax.EntityResolver)))

.NET Framework is System.Xml.XmlDocument # XmlResolver Property


Null behavior of XML xrefs

Not only are the above methods and properties different, but the behavior when NULL is specified is also different.

Java adopts the default object (that is, the same as parsing XML without calling a method).

The .NET Framework is a NULL object (that is, no xrefs / no xrefs).


XML xref object

The object that specifies the resolver of the above xref is

For Java, org.xml.sax.EntityResolver interface

For .NET Framework, System.Xml.XmlResolver abstract class


The only class that needs to implement an XML xref object

Obviously, the only thing that needs to be implemented in the object that specifies the xref resolver above is ** "a method that returns the content of the URI that points to the xref" **.


The only class that requires an implementation of an XML xref object (Java)

For Java, [org.xml.sax.InputSource.InputSource resolveEntity (String publicId, String systemId) method](https://docs.oracle.com/javase/jp/6/api/org/xml/sax/EntityResolver .html # resolveEntity (java.lang.String,% 20java.lang.String))

The second argument is a String type, but a URI indicating an external reference comes and [org.xml.sax.InputSource.InputSource class](https://docs.oracle.com/javase/jp/6/api/org/xml /sax/InputSource.html) is returned.


The only class that requires an implementation of an XML xref object (.NET Framework)

For .NET Framework, [object GetEntity (Uri absoluteUri, string role, Type ofObjectToReturn) method](https://docs.microsoft.com/ja-jp/dotnet/api/system.xml.xmlresolver.getentity?view= netframework-4.7.2 # System_Xml_XmlResolver_GetEntity_System_Uri_System_String_System_Type_) only.

In the first argument, the URI indicating the external reference comes in System.Uri class. , System.IO.Stream class is just returned.

There is a third argument that indicates the type / class you want to return, but the reality is [System.IO.Stream class](https://docs.microsoft.com/ja-jp/dotnet/api/system.io.stream? It seems that only view = netframework-4.7.2) is given, so after all [System.IO.Stream class](https://docs.microsoft.com/ja-jp/dotnet/api/system.io.stream?view?view Just return = netframework-4.7.2).


What is the InputSource class returned by an XML xref object?

For the above .NET FrameWork, use System.IO.Stream class It's neat because it just returns, but the [org.xml.sax.InputSource.InputSource class] for Java (https://docs.oracle.com/javase/jp/6/api/org/xml/sax) What is /InputSource.html)? java.io.InputStream class and [java.io.Reader class](https://docs .oracle.com/javase/jp/6/api/java/io/Reader.html) (and the character code) can be expressed as a summary.


Classic 3rd party library

For Java, there's usually something in Apache-Commons

.NET Framework ... I don't know


Classic 3rd party library (.NET Framework hash)

Classless.Hasher was convenient


Classic 3rd party library (.NET Framework random numbers)

Rei no Hut C # Random Library was convenient


Classic 3rd party library (.NET Framework / Java encryption)

The Legion of the Bouncy Castle may be a classic crypto library for both Java / .NET Framework

Recommended Posts

Differences between Java and .NET Framework
[Java] Differences between instance variables and class variables
Summarize the differences between C # and Java writing
[Java] Difference between == and equals
Differences between IndexOutOfBoundsException and ArrayIndexOutOfBoundsException
[Java Bronze learning] Differences between encapsulation, data hiding, and information hiding
[Java] Difference between Hashmap and HashTable
java framework
[JAVA] Difference between abstract and interface
Differences between Applet class and JApplet class
[Java] Difference between array and ArrayList
Think about the differences between functions and methods (in Java)
Differences in how to handle strings between Java and Perl
[Java] Difference between Closeable and AutoCloseable
[Java] Difference between StringBuffer and StringBuilder
[Java] Difference between length, length () and size ()
Conversion between Kotlin nullable and Java Optional
Relationship between kotlin and java access modifiers
Difference between final and Immutable in Java
Differences between preface and postfix of operators
[For beginners] Difference between Java and Kotlin
[Note] Cooperation between Java and DB (basic)
Differences between Ruby strings and symbols [Beginner]
[Java] Difference between Intstream range and rangeClosed
Difference between int and Integer in Java
HashMap # putAll () behaves differently between Java 7 and Java 8
A note on the differences between interfaces and abstract classes in Java
Java framework comparison
Java and JavaScript
XXE and Java
[Java] Collection framework
[Java] Understand the difference between List and Set
Differences between Spring Initializr packaging JAR and WAR
Difference between next () and nextLine () in Java Scanner
I compared the characteristics of Java and .NET
[Understanding] Differences between hashes and arrays in Ruby
Differences in writing Java, C # and Javascript classes
Distinguish between positive and negative numbers in Java
Ruby: Differences between class methods and instance methods, class variables and instance variables
[Java] Difference between "final variable" and "immutable object"
Differences between Java, C # and JavaScript (how to determine the degree of obesity)
Organize your own differences in writing comfort between Java lambda expressions and Kotlin lambda expressions.
Play Framework2.5 (Java) Tips
Getters and setters (Java)
[Ruby] Difference between receiver and object. Differences between Ruby objects and JS objects
[Java] Thread and Runnable
Java true and false
Differences between Ruby syntax error statements in Ruby and binary
[Java] String comparison and && and ||
[Java] Difference between static final and final in member variables
[JAVA] What is the difference between interface and abstract? ?? ??
Differences between browser sessions and cookies and Rails session and cookies methods
Java --Serialization and Deserialization
[Java] Arguments and parameters
Let's sort out the differences between Java substring and C # Substring, and how to port them.
Differences between Fetch Type LAZY and EAGER in Hibernate
[Java] Branch and repeat
[Development] Java framework comparison
Difference between vh and%
Mutual conversion between Java objects and JSON using Moshi
[Java] Variables and types