question archive 1) Java Programming in-depth discussing in encouraged 2
Subject:Computer SciencePrice:3.87 Bought7
1) Java Programming in-depth discussing in encouraged
2. Compare and contrast the input vs. output streams.
3. Give at least one example of an input and output stream.
Answer:
1.
JAVA is a popular programming language developed by James Gosling at Sun Microsystems in 1991. It so popular nowadays because it is used in many fields of technology like in mobile application development and many other computer application development. It is been known as the one of the most popular programming languages because of its many uses and applications. Since it's release, it is been a stable and efficient programming language for many programmers. But it just one of the many benefits of using Java programming language and there are many more to explore. For example, Java is also a platform independent programming language, it means that you can use it in one operating system like Windows and use to it to other operating system like linux, mac and etc. It is also an object oriented programming language, it applies real world concept when in it's structure and in the way of using it. Lastly, it is really easy and simple to learn Java, there are tons of tutorials that you can watch to learn Java using many different platforms that you are comfortable using. It's coding is also very simple understand and a very friendly one for those who are new to programming.
2.
Input and Output Stream are classes in Java that provides functionality for reading and writing outputs. Input Streams are use to read data from the source, while Output Streams are use to write data to a source/destination. They are basically a reader and writer respectively. While Input Streams are useful for reading data, and you can use different function to output it without the Output Stream and the same with Output Stream. They are basically different functions but together, they can became more useful and be a dynamic duo with each other.
Anything that can contain a data, file, string or memory is basically a Input/Output Stream, But there are more common example of it for better understanding, like Character Streams. Character Streams are used to read file inputs and outputs with the size of 16-bit unicode( type of file encoding). There are many classes in Character Stream, but the most popuplar are the FileReader and FileWriter. FileReader uses FileInputStream or basically and input stream to read data and FileWriter uses FileOutputStream or basically output stream to write data. For better here is an example:
3.
import java.io.*;
public class CopyFile {
public static void main(String args[]) throws IOException {
FileReader in = null;
FileWriter out = null;
try {
in = new FileReader("input.txt");
out = new FileWriter("output.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
}finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
}
*Note: If you want to try this, create a file first named input.txt and output.txt. In input.txt, write the following word, " I Love Java". Then after running the code, check content of the output.txt.
In the example above, the program uses FileReader to read the content of input.txt and and places a condition that while the input.txt have content, it will write all of its content in output.txt using the FileWriter.
References:
https://www.tutorialspoint.com/java/java_files_io.htm
https://www.programiz.com/java-programming
http://journals.ecs.soton.ac.uk/java/tutorial/java/io/index.html
https://www.javatpoint.com/history-of-java