PVS-Studio static analyzer team, which until recently was searching for bugs and potential vulnerabilities only in C, C++, and C# code, has prepared a new version of their tool for Java code as well. Despite the fact that in the Java world there is already a number of static analysis tools, developers believe that their analyzer can be powerful and will be a good competition.
In this article I want to tell you about the experience of developing one unpretentious game for Android, which has repeatedly paid off at the development stage!
PrehistoryWe started developing the game in the 10th grade. Before that, we had no experience in developing and promoting mobile games. There were only basic knowledge of Java and a little experience of creating websites. And that's all!
On this Wednesday, August 30, at the office of Oracle, meeting JUG with Oleg Shelaev, Developer Advocate in the company ZeroTurnaround, which makes JRebel and XRebel. The topic of the meeting is the tools for creating multi-threaded Java programs (from designing bikes and starting threads to handles, to ForkJoinPools, green threads and transactional memory).
Of course, we asked which Java 9 chips are considered the most useful in ZeroTurnaround. As a result, they got hold of the article that you are reading right now. The original article Oleg published in the blog RebelLabs , there are many more interesting.
How does the JVM create new objects? What exactly happens when you write a new Object ()?
At conferences, it is periodically told that the allocation of objects uses the thread-local allocation buffer (TLABs): memory areas allocated exclusively to each thread, creating objects in which is very fast due to the lack of synchronization.
But how correctly to choose the size of TLAB'a? What to do if you need to allocate 10% of the size of TLAB'a, but only 9% is free? Can an object be allocated outside TLAB? When (if) is the allocated memory set to zero?
Having asked these questions and did not find all the answers, I decided to write an article to correct the situation.
Before reading it, it's useful to remember how some garbage collector works
In this article we'll look at the main features of SonarQube - a platform for continuous analysis and measurement of code quality, and we'll also discuss advantages of the methods for code quality evaluation based on the SonarQube metrics.
SonarQube is an open source platform, designed for continuous analysis and measurement of code quality. SonarQube provides the following capabilities:
Nowadays a lot of projects are opening their source code and letting those who are interested in the development of it edit the code. OpenJDK is no exception, programmers PVS-Studio have found a lot of interesting errors that are worth paying attention to.
OpenJDK (Open Java Development Kit) - a project for the creation and implementation of Java (Java SE) platform, which is now free and open source. The project was started in 2006, by the Sun company. The project uses multiple languages- C, C++, and Java. We are interested in the source code written in C and C++. Let's take the 9th version of OpenJDK. The code of this implementation of Java platform is available at the Mercurial repository.
During verification, the analyzer found different errors in the project including: copy-paste, bugs in the operation precedence, errors in logical expressions and in pointer handling and other bugs, which are described in detail in this article.
It's always amusing to check a project which is used and maintained by a large number of people. The better and more accurate the code is, the more safely and effectively the program will work. Those bugs we found, are another proof of the usefulness of an analyzer, as it allows the detection of such errors which would otherwise be hard to detect doing simple code review.
Do you know how much memory the string has? I have heard all kinds of answers to this question, ranging from "do not know" to "string has 2 bytes". Here are some more questions: How much space does empty string take? How much space does the class object of Integer take? How much space will take your own class object with three Integer fields? It is funny, but none of my Java programmer friends could answer these questions ... Most of us do not need it, and nobody will think about it in the real java projects. After all, this is the same as you would not know the engine capacity of vehicle that you drive every day. You can be a great driver and did not even know what 2.4 or 1.6 means on your car. But I am sure that there are few people who are not familiar with the meaning of these numbers. So why do java programmers know so little about this part of their tool?
Integer vs int
We all know that in java - everything is an object. Except, perhaps, primitives and references to the objects themselves. Let us consider two typical situations:
This article explains how to implement some data structures in Java. It will be useful for beginners that use a programming language Java, as well as those who already know how to write a new ArrayList (), but have little knowledge what is happening inside.
Let us talk about the ArrayLists
ArrayList implements the List interface. As we know, Java arrays have a fixed length, and after the array is created, it cannot increase or decrease. ArrayList can change its size at runtime, but it does not necessarily indicate the size when an object is created. The elements of ArrayList can be any types, including null.