如何可视化Stream对象(以及其他一些数据类型)?

huangapple go评论88阅读模式
英文:

How to visualize a Stream object (and some other data types)?

问题

I want to make a small programming tutorial which will have a number of images visualizing various data types, but I am not sure how to draw these images of the data types.
我想制作一个小型的编程教程,其中会包含许多用于可视化各种数据类型的图像,但我不确定如何绘制这些数据类型的图像。

Assume that I have a FileOutputStream object that writes to the file 1.txt.
假设我有一个名为FileOutputStream的对象,它可以将数据写入文件1.txt

How can I think of this FileOutputStream object, do I think about it as a container of the stream of data (i.e. a pipe), for example:
我应该如何理解这个FileOutputStream对象呢?我是否可以将它看作是数据流的容器(即管道)?例如:

如何可视化Stream对象(以及其他一些数据类型)?

Or do I think about it as the stream of data only, for example:
还是我应该将它仅视为数据流本身?例如:

如何可视化Stream对象(以及其他一些数据类型)?

I think the term "stream of water" in real life only means the flowing water (without having a container that contains the flowing water).
我认为现实生活中的“水流”一词仅表示流动的水(而不是指包含流动水的容器)。


My question also apply to other data types, for example do I think of a Stack of integers as the container of the stack of integers, for example:
我的问题也适用于其他数据类型,例如,我是否应该将整数的Stack看作是整数堆栈的容器,例如:

如何可视化Stream对象(以及其他一些数据类型)?

Or do I think about it as the stack of integers only, for example:
还是我只将其视为整数堆栈本身?例如:

如何可视化Stream对象(以及其他一些数据类型)?

I think the term "stack of books" in real life only means the stacked books (without having a container that contains the stacked books).
我认为现实生活中的“书堆”一词仅表示叠放的书籍(而不是指包含叠放书籍的容器)。


Same thing for the int data type, do I think of an int as the container of the integer, for example:
对于int数据类型也是一样,我是否应该将int视为整数的容器,例如:

如何可视化Stream对象(以及其他一些数据类型)?

Or do I think about it as the integer only, for example:
还是我只将其视为整数本身?例如:

如何可视化Stream对象(以及其他一些数据类型)?

英文:

I want to make a small programming tutorial which will have a number of images visualizing various data types, but I am not sure how to draw these images of the data types.

Assume that I have a FileOutputStream object that writes to the file 1.txt.

How can I think of this FileOutputStream object, do I think about it as a container of the stream of data (i.e. a pipe), for example:

如何可视化Stream对象(以及其他一些数据类型)?

Or do I think about it as the stream of data only, for example:

如何可视化Stream对象(以及其他一些数据类型)?

I think the term "stream of water" in real life only means the flowing water (without having a container that contains the flowing water).


My question also apply to other data types, for example do I think of a Stack of integers as the container of the stack of integers, for example:

如何可视化Stream对象(以及其他一些数据类型)?

Or do I think about it as the stack of integers only, for example:

如何可视化Stream对象(以及其他一些数据类型)?

I think the term "stack of books" in real life only means the stacked books (without having a container that contains the stacked books).


Same thing for the int data type, do I think of an int as the container of the integer, for example:

如何可视化Stream对象(以及其他一些数据类型)?

Or do I think about it as the integer only, for example:

如何可视化Stream对象(以及其他一些数据类型)?

答案1

得分: 3

查看Java IO流的教程:https://docs.oracle.com/javase/tutorial/essential/io/streams.html 以及它的示例:

如何可视化Stream对象(以及其他一些数据类型)?

我认为这个问题有些主观。这个“容器”通过为图像中的不同组件提供清晰的轮廓来使表示更加清晰(如上面的示例所示)。它还可以为读者提供背景信息:例如,对于堆栈,将其表示为容器是有意义的,因为它是一个保存元素的集合。但对于一个整数,它代表什么?内存分配吗?

请记住,最终它只是对该概念的抽象表示。

英文:

Take a look at the Java tutorials for IO streams: https://docs.oracle.com/javase/tutorial/essential/io/streams.html and how it illustrates it:

如何可视化Stream对象(以及其他一些数据类型)?

I think the question is somewhat subjective. The "container" helps make the representation more clearer by having clear outlines for the different components in the image (as in the above example). It may also give context to the reader: e.g. for the stack it makes sense to represent it as a container as it is a collection that holds elements. But for an int, what does it represent? Memory allocation?

Keep in mind that at the end, it's just an abstract representation of the concept.

答案2

得分: 2

这里都是容器。

让我从底部开始,因为我认为这会更容易理解。

不涉及太多内存管理细节,你必须将每个人都看作"容器加数据"。特别是在有类型的情况下。

某个东西,如果没有容器,只是一些位(bit)。

例子:一个整数4,只是一个"1000"。但如果这个4是一个ASCII码,它会是一个可写的符号,同样是"1000"。容器赋予数据内部以意义。没有容器的数据,即原始数据,只是一些位(bit)。

再往上看栈(stack),同样地,你应该以相同的方式思考。抽象就是容器,是容器的容器。

所以像一个Stack<T>,就像是:

_______________ 
| 
| *top 
| ==== 类型 T == 
| ==== 类型 T == 
| ==== 类型 T == 
|______________| 

然后,在之后,那些类型T、整数、字符串或其他任何东西,都将是容器,以另一种精确的方式保存一些其他的位。

始终强调抽象、盒子的重要性,因为具体实现完全依赖于系统、语言、编译、CPU架构等等...所以,对于我们来说,它们始终是盒子。

谈到流(stream),流与其他情况略有不同,因为流在理论上仅发送原始数据,只有在使用数据时才会进行转换。这对于Java中的IO流是正确的,但对于流的概念本身,或者响应式编程中的流是不适用的,这些是非常不同的概念。但总的来说,流只是将数据紧凑地发送出去,然后在数据退出时,你或流会以所需的方式处理数据,以便于理解。

如果你有更多问题,不要犹豫,尽管问。

英文:

It's always containers.

Let me start from the bottom, because I think it will be easier.

Without getting too far inside memory management specifics, you have to think of everyone as the CONTAINER plus THE DATA. Specially in typed types.

Something, without the container, is just bits.

Example: An integer 4, is just a '1000'. But that 4, if it were an ascii, it would be some writtable symbol, and it would be just a '1000'. The container is what brings meaning to the data inside. Data without contanier, raw data, is just bits.

Going up to the stack, again, you should think the same. THe abstraction IS the container, and is a container of CONTAINERS.

So something like a Stack<T> issomething like

_______________
|
| *top
| ==== type T==
| ==== type T==
| ==== type T==
|______________|

And then,after, those types T, or integers, or Strings, or whatever, will be containers that will hold some other bites in another precise way.

Is important to always talk about the abstraction, the box, because the implementation is totally dependant on system, language, compilation, cpu architecture... so, for as, they will always be boxes.

Coming to the stream, the stream is a little different than the others because the stream, in theory, only sends raw data and it only gets converted when you are gonna use it. This is true for IO Streams in Java, but not for the Streams concept itself, or Streams as in reactive programming, which are very different things. But, as a general simplification, the stream just sends the data crammed up, in a optimized way, and then you, or the stream, treats that data in the way needed for it to be understood when exiting it.

If you have any more questions, dont hesitate to ask

答案3

得分: 0

每个在Java中的非原始类型变量都是一个指向对象的指针。任何类型的对象都是类的实例。无论你正在处理哪种数据类型,实际上只是一个单一的对象。例如,ArrayList&lt;String&gt; li; 不是多个字符串,它是一个类型为ArrayList的对象li

澄清了这一点之后,无论是输入还是输出的流都是一个对象,即一个容器。栈也是一样的。在几乎所有编程语言中,你不能没有容器来存储数据。

对于所有原始类型,当然,你必须将它们视为数据本身。例如,int a=3; 你必须将a看作是3,没有容器。这是因为在Java中,你不能有一个指向原始类型的指针。

英文:

Every variable of non primitive type in Java is a pointer to an object.
An object of any type is an instance of a class. Whichever data type you are dealing with, in reality is just 1 single object. For example an ArrayList&lt;String&gt; li; it's NOT multiple strings, it is 1 object li of type ArrayList.

Having clarified that, A stream be it input or output is 1 object, i.e. a container. a stack is the same. In pretty much all programming languages, you can't have data without a container.

For all primitive types, of course, you must think of them as the data itself. For example an int a=3; you must think of a as 3 there is no container. This is because in Java you can't have a pointer to a primitive type.

答案4

得分: 0

这里是一个简短且希望有帮助的回答。

对于所有的数据类型,应该是 "容器"。为什么?因为所有东西都是一个对象(封装)- 即使是 "int" 也可以与 "Integer" 互换。

更具体地说:

对于文件输入/输出(FileIO) -
将容器塑造成管道,这样你就可以包裹它们。像这样 -
图片链接 - https://i.stack.imgur.com/zRqoL.png

来自 O'Reilly 图书馆本身 -
https://www.oreilly.com/library/view/learning-java-4th/9781449372477/ch12s01.html

对于栈(Stacks) - 将容器塑造成盒子
https://i.stack.imgur.com/JP7Dz.jpg

对于数据类型 - 胶囊非常合适
https://i.stack.imgur.com/Qqhrw.png

参考 - https://stackify.com/oop-concept-for-beginners-what-is-encapsulation/

希望能有所帮助。

英文:

Here is a short and hopefully helpful answer.

For all data types it should be "Containers"
Why ? - Because everything is an Object ( Encapsulation ) -
even an "int" is interchangeable with "Integer".

More Specifically

for FileIO -
Shape the containers as Pipes, so you can wrap them. Like this -
Image Link - https://i.stack.imgur.com/zRqoL.png

from Oreily Library itself -
https://www.oreilly.com/library/view/learning-java-4th/9781449372477/ch12s01.html

For Stacks - Containers shaped as boxes.
https://i.stack.imgur.com/JP7Dz.jpg

For Data Types - A Capsule is quite apt.
https://i.stack.imgur.com/Qqhrw.png

ref - https://stackify.com/oop-concept-for-beginners-what-is-encapsulation/

Hope that helped.

答案5

得分: 0

我喜欢对熟悉事物的暗示(比如水流或书堆),这对于初学者或普通大众非常有帮助。如果你的受众是这样的话,可以将它加入你的描述中。

至于流,我对于有无容器都可以接受,但我建议指明流动的方向。

至于堆栈,我更倾向于它整体上没有容器。更重要的是,这是一个有条理的堆叠,其中一个物品明显在另一个物品上面。

至于整数,当被解释为数据类型时,不需要容器。(但一旦被放在变量中,从我的观点来看,一个“容器”就是合适的)。

英文:

I like the allusions to familiar things (like stream of water or stack of books), it can be very helpful especially for beginners or general public. If that's your audience, feel free to add it to your description.

As for the stream, I'm fine with both with and without a container but I'd suggest to indicate stream direction.

As for the stack, I prefer it not having a container as a whole. More importantly, it's an organized pile with one item being clearly above another.

As for int, it doesn't need a container when being explained as a data type. (As soon as placed within a variable though, a 'container' would be appropriate, in my view).

huangapple
  • 本文由 发表于 2020年8月24日 03:31:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63551196.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定