In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the relevant knowledge of "Java object instance analysis". Xiaobian shows you the operation process through actual cases. The operation method is simple and fast, and the practicality is strong. I hope this article "Java object instance analysis" can help you solve the problem.
1. Winter hibernation
The work here is very busy, 365 days a year, almost 24 hours a day.
But I am an idle person, because the work I do recently uses too few people and is often neglected.
Most of the time, I can only enviously watch threads, reflections, annotations, collections, generics--these star employees hustle and bustle, listening to their passionate, loud laughter.
They all call me serialize, and think about it, my job is to turn a Java object into a binary byte stream, or vice versa, into a Java object. What does that mean?
When you need a Java object, just new it out, and the object is not used, there is naturally a scary garbage collection to deal with.
But existence is reasonable, and in the era of JDk 1.1, I already existed. At the time, people were thinking ahead: the network was a computer. Java objects should be able to travel around the network: from one machine, they become binary byte streams, travel across the network to another machine, where they transform back into Java objects, and continue computing there.
Since I can roam the network in binary mode, I can naturally save these byte streams to the hard disk. When the JVM stops and the whole world collapses, threads, reflections, and annotations no longer exist, and my byte stream will still wait silently on the hard disk, waiting for the next JVM rebirth to restore the object.
So I think my work is valuable, too, in the sense that I can make Java objects immortal across time and space!
This immortality comes at a price, first you have to use Java, which is nonsense, because I'm just serializing Java objects.
Although the format of the binary byte stream is public, you can parse it in any language (C,C++,Python...), but what is the use of parsing it? Those byte streams tell you which class of data it is, the type and value of the field, but you can't build Java objects without the corresponding Java class.
Second, the classes on both sides of the serialization must be consistent, otherwise there must be trouble.
Most people don't know that at the end of last century and the beginning of this century, I was still popular with J2EE for a while. At that time, there was something called RMI in J2EE, which was actually Java RPC. Thanks to my excellent work, developers can easily invoke Java methods on remote servers just as easily as they can invoke local methods.
Unfortunately, this RMI can only be used in Java environment, for the server is not a problem, but at that time Web applications are emerging, a browser is difficult to have Java environment, so RMI soon declined, I was also followed into the cold palace, I had to hibernate, waiting for the opportunity.
The Challenges of XML and JSON
Later, we came here with a young man named XML, who was very popular with everyone and liked to hand over the work of Java object serialization to him.
I couldn't wait to die. After a few days of careful observation, I finally found that this guy had a big flaw: it was too complicated!
For my Java serialization, most of the time you just need to make your class implement Serializable and I can take over all the work. Don't worry about it.
But with XML, you also have to write a bunch of code to turn the fields and their values in a class into XML tags/attributes/values. When an XML string representing an object roams to another machine, there's still a bunch of code to turn the XML into an object.
I laughed at XML and said,"Boy, this is too much trouble for you. Human time is precious. In order to use XML to do serialization, the price is high!" "
"Old man, it's not as complicated as you think. You may not know this, but we have some libraries that automatically help us turn objects into XML."
"Don't forget," the guy added,"that our XML is language-neutral, Java objects in this case, and any language on the client side, Java/C/Python/Ruby... is fine, even Javascript in the browser can handle it, can't you? "
This guy hit a nerve, I really need a Java environment in the browser to run, alas, it really is Java , Java failure.
I said,"I know you're language-independent, but you haven't noticed that your XML tags are redundant and there's very little real data. For example, if you have a Person class with two fields, name and address, serialize it with your XML and it looks like this.
abc xyz
This is definitely a waste to transmit on the network! My java byte stream is different, binary, very compact, not wasted at all! "
XML guy silent, sample, I also caught your pain point.
After two days, this young man brought a younger brother named JSON. He proudly showed off to me: after using JSON, the data is much simpler. If you don't believe me, you can see: {"name":"abc", "address":"xyz"}. Now we are not only language neutral, but also very concise. Old man, you have nothing to say now.
I admit defeat, but let XML also not happy for long, let him did not think that the Web era JSON and Javascript is a perfect match, jointly ruled the browser. Even XML itself was running out of food.
3. The Rise of New Agreements
In fact, I have always felt that my binary serialization method can reduce storage space and facilitate network transmission, but my hard injury is that I cannot cross languages.
No, I can't keep Java this mu three points, must extend support for multiple languages, so as to get out of the Java environment.
It has been said that all computer problems can be solved by adding an intermediate layer. Can I have a middle tier too?
Let this middle layer define/describe the format of the message, and then get a small translator (no, call the compiler obviously higher) to convert this programmer-defined message format into various language implementations, such as java, python, c++, etc.
In the translated language implementation, the definition of the class to be serialized is automatically included, as well as the code for serialization and deserialization. Of course, the serialized data is binary.
Once the binary byte stream is transmitted over the network to another machine, it can be deserialized into objects in various languages (such as Python), of course, Python classes generated by the same message format.
Not only Python, C++, Go, C#, but even Javascript!
About "Java object instance analysis" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.