Java.Streams.What subclasses of the OutputStream class do you know, what are they for?

OutputStream is an abstract class in java.io that represents an output stream of bytes — i.e., it lets you write raw binary data to some destination.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Streams.What subclasses of the OutputStream class do you know, what are they for?

Java.Streams.Which class allows you to read data from an input byte stream in the format of primitive data types?

The class you’re looking for is DataInputStream.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Streams.Which class allows you to read data from an input byte stream in the format of primitive data types?

Java.Streams.What is SequenceInputStream used for?

SequenceInputStream in Java is a class used to combine two or more input streams into one so they can be read sequentially, one after the other, as if they were a single continuous stream.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Streams.What is SequenceInputStream used for?

Java.Algo.Backtracking.AllSubsets

    public static List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        dfsBacktrackingAllSubsets(nums, 0, new ArrayList<>(), res);
        return res;
    }

    private static void dfsBacktrackingAllSubsets(int[] nums, int index, List<Integer> prevCombination, List<List<Integer>> allCombinations) {
        List<Integer> newCombination = new ArrayList<>(prevCombination);
        newCombination.add(nums[index]);
        allCombinations.add(newCombination);

        if (index == nums.length - 1) {
            return;
        }

        dfsBacktrackingAllSubsets(nums, index + 1, prevCombination, allCombinations);
        dfsBacktrackingAllSubsets(nums, index + 1, newCombination, allCombinations);
    }
Posted in Без рубрики | Comments Off on Java.Algo.Backtracking.AllSubsets

Java.Algo.Backtracking.AllPermutations

    public static List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        dfsBacktrackingAllPermutations(nums, 0, res);
        return res;
    }

    private static void dfsBacktrackingAllPermutations(int[] nums, int start, List<List<Integer>> result) {
        if (start == nums.length) {
            List<Integer> permutation = new ArrayList<>();
            for (int num : nums) {
                permutation.add(num);
            }
            result.add(permutation);
            return;
        }

        for (int i = start; i < nums.length; i++) {
            swap(nums, start, i); // choose
            dfsBacktrackingAllPermutations(nums, start + 1, result); // explore
            swap(nums, start, i); // un-choose (backtrack)
        }
    }

    private static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
Continue reading →
Posted in Без рубрики | Comments Off on Java.Algo.Backtracking.AllPermutations

Java.Streams.What is PushbackInputStream used for?

✅ What Is PushbackInputStream?

PushbackInputStream is a special kind of InputStream that allows you to “unread” or push back bytes into the stream — so they can be read again later.

It’s like a stream with an “undo” buffer — ideal for building parsers or tokenizers.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Streams.What is PushbackInputStream used for?

Java.Streams.What subclasses of the InputStream class do you know, what are they for?

Great question, Stanley! 🧠 Let’s explore the subclasses of InputStream and understand what each is used for.

InputStream is the abstract base class for reading raw bytes in Java.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Streams.What subclasses of the InputStream class do you know, what are they for?

Java.Streams.In which packages are the classes of input/output streams located?

✅ 1. java.io — Traditional I/O (Streams API)

This is the main package that contains most of the classic input/output stream classes.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Streams.In which packages are the classes of input/output streams located?

Java.Streams.Name the main classes of input/output streams.

✅ Main Classes of Input/Output Streams

🔹 1. Byte Streams

Use these for binary data (files, images, audio, etc.)

📥 Input Streams (read bytes):

  • InputStream (abstract base class)
  • FileInputStream – reads bytes from a file
  • BufferedInputStream – adds buffering
  • ByteArrayInputStream – reads from a byte array
  • DataInputStream – reads primitive types (int, double, etc.)
  • ObjectInputStream – reads serialized Java objects
  • PipedInputStream – used for inter-thread communication

📤 Output Streams (write bytes):

  • OutputStream (abstract base class)
  • FileOutputStream – writes bytes to a file
  • BufferedOutputStream – adds buffering
  • ByteArrayOutputStream – writes to a byte array
  • DataOutputStream – writes primitives
  • ObjectOutputStream – writes serialized objects
  • PipedOutputStream – connects to PipedInputStream

🔹 2. Character Streams

Use these for text (Unicode characters)

📥 Readers (read characters):

  • Reader (abstract base class)
  • FileReader – reads from a file
  • BufferedReader – efficient line-by-line reading
  • CharArrayReader – reads from a char array
  • StringReader – reads from a string
  • InputStreamReader – bridges byte → character stream

📤 Writers (write characters):

  • Writer (abstract base class)
  • FileWriter – writes to a file
  • BufferedWriter – buffered writing
  • CharArrayWriter – writes to char array
  • StringWriter – writes to string
  • OutputStreamWriter – bridges character → byte stream

🧠 Summary Table

CategoryInput (Read)Output (Write)
Byte StreamsInputStream and subclassesOutputStream and subclasses
Char StreamsReader and subclassesWriter and subclasses
Posted in Без рубрики | Comments Off on Java.Streams.Name the main classes of input/output streams.

Java.Streams.What types of input/output streams are there?

🧠 Let’s walk through the types of input and output streams in Java — these are part of the traditional java.io package.

Java organizes streams into two main categories:

Continue reading →
Posted in Без рубрики | Comments Off on Java.Streams.What types of input/output streams are there?