On this page
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. Lots of companies create products using Java. That means that lots of teams write Java code and then the code is joined together. Sometimes young developers make mistakes. In this way experienced developers should check changes in the code. Some changes are correct and must be accepted, while others are wrong and must be rejected. GroupDocs.Comparison is the best solution for these cases.
The only thing you need to do is to configure GroupDocs.Comparison library in your project. After that, writing just a few lines of code, you can solve the issue.
Firstly, add GroupDocs repository to the project to make it possible to download the library automatically
Add GroupDocs repository
Secondly, specify required library dependency
The latest version of Comparison library can be found here
Add GroupDocs.Comparison dependency
GroupDocs.Comparison is very modern and powerful library. There are lots of facilities for comparing files, getting details of changes, analyzing changes, accepting or rejecting them, retrieving coordinates for each change and so on. In this article are shown just a small part of capabilities. More details about other facilities can find in the documentation
To compare source and target Java code files do next
As a result, you will find next two files:
.javaresult file with special marks, which mark each change in the document
.htmlhuman-readable result comparison file
These files can be used to analyze changes that were made in target document in comparison with source one. But it is not finish, the next step is much more useful and interesting.
With GroupDocs.Comparison you can compare lots of file formats. Moreover, you can get list of changes, reject or accept them applying to the result Java file. It can be very useful when some changes are invalid and must be reverted while other are good and must be applied to the document.
Example of applying or rejecting changes in Java code file
In the example above it gets list of changes to analyze each of them. The code checks the value of
getSourceText() method. When it contains
for (int i = 0; i < HASH_TABLE_SIZE (parts of changed lines in Java code file), the change will be accepted to be kept, otherwise change will be rejected to keep line like it was in source file. In order to understand described above, check images below. After rejecting or accepting, changes are applied and saved as a new file.
As a result you will find two files:
.java- valid Java code file where rejected changes were reverted while accepted changes were kept
.html- human-readable file, very similar to result that was generated on the previous step, but without changes which were rejected
Here are screenshots of all generated files:
|Source Java code file||Target Java code file||Result Html file||Result Html file with changes applied|
On the images you can see that changes
5 were rejected, while changes
++ were saved. The valid Java code file was also saved. You can see it below
|Resultant Json file|
In Comparison library are lots of facilities, for example, sensitivity of comparison, generating summary page and much more. Some of them are available only with valid license. You can get a free temporary license to use the API without evaluation limitations.
Along with full-featured Java/Kotlin library we provide simple, but powerful free applications.
You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSG, XML and other documents with free to use online GroupDocs Comparison Application.
There are much more examples of using GroupDocs.Comparison with Java/Kotlin available on our GitHub page. You are free to change and use them in order to compare photos, Excel, Word, code files, PowerPoint Presentations and much more supported file formats.
- How to compare documents in the easiest way
- How to compare json files applying or rejecting changes with Java or Kotlin
- How to compare images using Java or Kotlin
- How to see comparison and contrast of essays
- How to compare Text, Word or PDF in Java or Kotlin
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.