java-faq

Java books and Learning Resources

The answers to this question were written by the joint efforts of the community. To improve this message, edit the existing r ... he general answer. This list is included in the community-supported Collection of educational resources on programming.

What is a Null Pointer Exception and how to fix it?

What is a Null Pointer Exception (java.lang.NullPointerException) and why can it occur? What methods and tools should I use ... tion to terminate prematurely? Translation of the question " What is a Null Pointer Exception, and how do I fix it?" @Ziggy.

What is stack trace, and how to use it to find errors in application development?

Sometimes when I run my app I get a similar error: Exception in thread "main" java.lang.NullPointerException at com.e ... cing. Translation of the question: "What is a stack trace, and how can I use it to debug my application errors?" @Rob Hruska

How and how to parse Json in Java?

There is often a need to work with Json, in particular its reading and parsing. In Java, you usually know what type of variab ... "type": "home", "number": "999 111-1234" } ] } ] }

How to compare strings in Java?

In my program, I used the == operator to compare strings. But I came across a bug, and when replacing == with equals, it disappeared. Should the == operator be avoided? When can it be used and when not? What's the difference?

What is packaging and unpacking (boxing/unboxing)?

What is packaging and unpacking (boxing/unboxing) and why is it necessary? Would be happy with examples.

How does the foreach loop work in Java?

There is a collection and a loop foreach: List<String> someList = new ArrayList<String>(); //add "monkey", "donk ... reach loop above look like? How does the foreach loop work inside? What is the difference between the for and foreach cycles?

What is null?

null is it an instance of something? What type does null belong to? What is null? How is it represented in memory? Free translation of the question "What is null in Java?" from the participant @unj2.

A foreach loop versus an Iterable loop.foreach in Java 8: what's better?

Which of the following is the best practice in Java 8? Java 8: list.forEach(e -> e.operation); Java 7: for (E e : lis ... bdas, but are there any real benefits from using Iterator.foreach? Will the performance and readability of the code improve?

What are the differences between findFirst and findAny in Java 8?

I don't really understand the difference between findFirst() and findAny() in the Java Stream API. I thought that findFirst ... and Stream.of(...).findAny() Then they both return the first element of the stream. Why? Are they both doing the same task?

What is the difference between the map and flatMap methods in Java 8?

What is the difference between the methods Stream.map and Stream.flatMap apart from each other?