DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > 3 Ways to Diff Java Code in IntelliJ [Video]

3 Ways to Diff Java Code in IntelliJ [Video]

IntelliJ has an inbuilt diff tool which you can use to compare files, classes or code with the clipboard. Just right-click and choose Compare.

Alan Richardson user avatar by
Alan Richardson
·
Oct. 16, 17 · Java Zone · Tutorial
Like (5)
Save
Tweet
9.73K Views

Join the DZone community and get the full member experience.

Join For Free

I was busy refactoring code in RestMud this morning because I want to try and open source the basic game engine, and then later the Web/REST API, but I want to tidy up the code a little first.

I've been working through the code:

  • Moving classes into new packages
  • Splitting classes to make code clearer and easier to manage
  • New classes make code easier to test

And the more I tidy it up in general, the easier it is to spot smaller problems of code duplication.

Sometimes I fix the duplication by:

  • Extracting code into a new class and delegating functionality off to the class
  • Extracting code into private methods

IntelliJ has an incredibly useful piece functionality to help with that in the form of the Compare Tool.

The Compare Tool

The compare tool is a built-in diff tool.

I can use it in three different ways:

  • Right-click on a file and "Compare" then choose a file on my hard drive to compare with
  • Select two classes in the project view and right click to "Compare"
  • Select code, add it into the clipboard, then highlight a different block of code and "Compare with Clipboard"

They all use the same 'diff' view, which is much easier than:

  • Using a separate tool like WinMerge to compare files outside of the IDE.
  • Splitting the window and visually trying to compare code

I show all three approaches in this short YouTube video.


Diff intellij Java (programming language)

Published at DZone with permission of Alan Richardson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Debugging Deadlocks and Race Conditions
  • How to Leverage Method Chaining To Add Smart Message Routing in Java
  • How to Hash, Salt, and Verify Passwords in NodeJS, Python, Golang, and Java
  • Application Scalability — How To Do Efficient Scaling

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo