LeetCode 560: Subarray Sum Equals K - C++/Java
I have some suggestion for the Java version
Always try to pass the size of the maximum size to the Collection / Map constructor when known
The map has a default size of 16 elements, if you have more elements, the map will have to resize its internal cache. By setting the size, you can prevent the resize and make your code faster.
In this case, you can set the maximum size since it's based on the size of the array + 1.
Map&lt;Integer, Integer&gt; prefixSum = new HashMap&lt;&gt;(nums.length + 1);

Extract the expression to variables when used multiple times
In your code, when you check if the key is present, you can extract the value to a variable to reuse it when present.
Before
if (prefixSum.get(sum - target) != null)
   subarrays += prefixSum.get(sum - target);

After
Integer currentValue = prefixSum.get(sum - target);
if (currentValue != null)
   subarrays += currentValue;

This will be better, since this will prevent the rechecking and the rehashing in the map.
Always add curly braces to loop &amp; if
In my opinion, it's a bad practice to have a block of code not surrounded by curly braces; I saw so many bugs in my career related to that, if you forget to add the braces when adding code, you break the logic / semantic of the code.
Before
if (prefixSum.get(sum - target) != null)
   subarrays += prefixSum.get(sum - target);

After
if (prefixSum.get(sum - target) != null) {
   subarrays += prefixSum.get(sum - target);
}

Extract some of the logic to methods.
In this case, I suggest to extract the map creation to a method; this will allow to group the logic and make the main code shorter.
public int subarraySum(int[] nums, int target) {
   Map&lt;Integer, Integer&gt; prefixSum = buildMap(lengthOfNums + 1);
   //[...]
}

private Map&lt;Integer, Integer&gt; buildMap(int defaultSize) {
   Map&lt;Integer, Integer&gt; prefixSum = new HashMap&lt;&gt;(defaultSize);
   prefixSum.put(0, 1);
   return prefixSum;
}