Because you?ve decided to open this book, you probably already know that IntelliJ IDEA is a next-generation integrated development environment (IDE) for Java. As the term IDE implies, IDEA combines all the tools you need to develop Java software into a single application and interface. In other words, IDEA is a tool that helps you develop Java applications more quickly, easily, and intelligently. IDEA can help you with every phase of your project, from design and development to testing and deployment?provided you know how to make the most of it. This book will give you all the information you need to become an IDEA expert.
IntelliJ IDEA in Action is an independent and authorized book. This means the publisher, Manning, is independent of the vendor, JetBrains. It?s authorized because from day one we have had the full cooperation, approval, and contributions of Eugene Belyaev and his team at JetBrains. We?ve had the best of both worlds in creating this book?complete editorial freedom to tell you everything you need to know about IDEA, and also the expert advice and assistance of the JetBrains team.
If you?re already a user of IntelliJ IDEA, then by now you?ve discovered that it provides a powerful environment for managing your Java projects and source files as well as building and testing your applications. Its support for popular industry standards like J2EE, Ant, JUnit, XML, and various revision control systems ties together all the core aspects of Java development under a single tool.
Beyond the integrated tools, fancy editor, and snazzy project management features, IDEA provides a huge number of features aimed at increasing your productivity and improving your development experience. IDEA can help improve your efficiency by eliminating mundane and repetitive coding tasks, alerting you to errors before compilation, tracking code changes, and enabling powerful refactoring. By digging a little deeper into IDEA and embracing these features, you can become a more effective Java developer, because you?re free to spend time on project design rather than code management.
Without some educational investment on your part, however, IDEA can be just another editor. That, then, is the purpose of this book: not only to get you up and running quickly, but also to teach you how to use IDEA?s multitude of powerful software development tools to their fullest advantage. We assure you that by digging into the many features, tips, and tricks covered in this book, you?ll learn time-saving techniques or have at least one ?Eureka!? moment that will make it worth your while many times over, even if you?re an experienced IDEA user.
If you?re new to Java development or a coder graduating from Notepad to your first real IDE, you?ll find additional benefits in this text as we introduce you to the debugger, source code control, and code-generation tools you may not be familiar with. Mastery of these types of concepts is essential for taking your coding to the next level.
That said, we assume you have at least some experience with Java and basic software development concepts. This is primarily a book about how to use IDEA, so we won?t cover any particular Java technology too deeply. If there are areas you aren?t familiar with (or don?t care about), the structure of the book makes them easy to bypass.
This book is geared primarily to coders on the front line, but it can be useful to development managers who are evaluating IDEA or other development environments. Not only will it give you a good background on IDEA?s capabilities, but it can also help you determine the best way to integrate IDEA into your team?s development process.
The book is written in two main sections, divided into chapters in a manner that makes it easy for experienced users to jump straight to topics they want to dig deeper into while providing a logical, linear progression for users unfamiliar with IDEA and IDE development.
The first eight chapters cover the basics of working with IDEA. These chapters focus on getting started and hammering out your project from its basic components. This is the grunt work, the essentials, and where everyone new to IDEA should start.
The final chapters cover more advanced topics or areas of interest to particular types of developers, such as those working with Swing or J2EE. If you have a particular interest in these topics, you should feel free to skip ahead to chapters 9 and up, but we?ll assume that you?re comfortable working with other aspects of the IDE by this point.
Many tools are required to help a developer create applications. Modern IDEs strive to bundle all these tools into a cohesive system, making access to the tools simpler and more productive. Chapter 1 introduces you to IDEA by demonstrating a simple programming task from implementation to execution. As complex as the software is, walking through this main development path allows new users to observe all the basic features they need to get their job done. Following up on the core knowledge, the rest of the book expands into the far corners of IDEA, showing you all the other features that will help increase your development efficiency.
The most prominent feature of IDEA is the source code editor. If you?ve been using VI or Notepad to edit your Java source, we think you?ll be pleasantly surprised at the number of conveniences IDEA offers over these tools. The IDEA editor can automatically format your source code, check it for syntax errors, and color-code Java keywords?all in real time as you type. The editor?s awareness of code structure lets you navigate by method or block, collapse JavaDoc, hide inner classes, and take advantage of other conveniences. You can search and replace text, and even code usages, across your entire project. Compared to tools like a plain text editor, it?s the difference between a nail file and a Swiss Army knife. This chapter introduces the editor?s core features that will help you from day to day, line by line.
After becoming familiar with the editor, you can knuckle down and get to work. The editor provides the means to write program code with a feature set like many others. However, the IDEA editor truly understands Java syntax and the Java API. This is where the editor can start to reduce your workload. If you forget the parameters for a method call, the editor can remind you. It can even bring up the JavaDoc for the method or class to give you additional insight. Convenient code-generation features eliminate the drudgery of creating accessor methods, implementing interfaces, and creating JavaDoc. Common coding tasks like iterating over the elements of an array are reduced to single keystrokes, thanks to the editor?s innovative LiveTemplates feature. This chapter covers the power features within the IDEA editor.
IDEA makes it easy to manage complex development projects. Through an innovative modular approach to project management, IDEA allows you to separate your application into discrete modules that can be developed, built, and tested independently. In addition, third-party resource packages are seamlessly combined with your own application through the use of handy code libraries. Dependency management ensures that nothing gets out of sync. Modules and libraries can even be shared across projects, promoting reuse and simplified project management. This chapter covers managing your projects.
The IDE is also used for compiling your project and making sure it runs. If you manage to create syntax errors, IDEA will help you locate them quickly and get them resolved. Integration with the Ant build framework lets you design powerful build scripts to automate not only the compiling but also the packaging and deployment of your projects. Building and running your project are covered in chapter 5.
Got bugs? Sure, you do. If you?ve been using
You can help root out some of those nasty bugs that management is always complaining about, and keep them from coming back, by employing a suite of rigorous unit tests. IDEA supports JUnit, the de facto standard unit-testing framework for Java. With the IDEA test runner, you can run entire test suites, individual test cases, or individual tests with a single click. All of your unit test results are combined into a single report that tracks much more than a simple pass/fail. IDEA records the output generated by each individual test and tracks the amount of time and memory required to run each of them. JUnit and IDEA?s unit testing support are discussed in this chapter.
IDEA also understands how to work with most popular version control systems, eliminating the need to manage your source tree from another tool. You can check out, edit, and commit files, as well as view their histories and examine the changes made between versions. Another innovation in IDEA is the local history, your own private source code control system that tracks your changes each time you successfully build the project or compile your unit tests. You can even tag your source with your own version label at any time, creating a fallback position when developing new features. You can view differences and roll back changes at any time, all without having to commit your code to the team?s source code repository. The version control features of IDEA are discussed in chapter 8.
When you?re ready to dig deeper, you?ll want to check out IDEA?s code analysis and refactoring features. For example, the code inspector tool can examine individual files or your entire source tree and locate redundant statements, missing JavaDoc comments, unused code, calls to deprecated methods, and other common design problems. It can even fix many of the problems it finds automatically!
IDEA?s support for refactoring allows you to fine-tune your architecture without the headaches. For example, if you want to rename a class or move it between packages, IDEA will take care of moving the file and fixing all of the references to it. You can even reorder a method?s parameters or change the signature without breaking all source code dependencies. With support for dozens of refactoring operations, IDEA enables you to keep your code clean and elegant in a way impossible to do by hand. This topic is covered in chapter 9.
Moving beyond basic text editing, IDEA adds a new graphical editor for building Swing interfaces. Using the Swing form designer, you can drag and drop components such as radio buttons and text fields directly where you want them on the interface. Then, you can easily configure the components? properties and tell IDEA how the graphical interface should be bound to your code. The development of Swing applications is covered in this chapter.
If you do a lot of JSP, web, or EJB development, you?ll be happy to know that IDEA hasn?t forgotten about you. In fact, IDEA has some of the best J2EE development tools around. IDEA?s code-aware features and refactoring support works inside JSP pages, and the editor has full support for tag libraries as well. You can take advantage of integrated support for Tomcat, WebLogic, and other web application servers to ease debugging and deployment. Web deployment tools make configuring and deploying web applications quick and painless. EJB tools make the creation of all the necessary interfaces and classes a snap. J2EE development is covered in chapter 11.
If you?re like us, you?re particular about your code layout, fonts, colors, indentation, beer, barbeque sauce, and other critical software development aspects. The folks at JetBrains must be, too, because IDEA is one of the most customizable tools we?ve ever seen. In chapter 12, we?ll tell you how to adjust things to your liking.
IDEA provides a number of convenient tools and accessories that span the functionality of the project. In chapter 13, we?ll cover things like using bookmarks and macros, and extending IDEA using plugins and external tools.
The conventions described below are used throughout the book.
We use the following styles throughout the text when describing the keystrokes and mouse combinations required:
fixed width fontto separate it from ordinary text. Additionally, method names, class names, package names, and object properties are also presented using
fixed width font.
Because it?s an extremely common development platform, Microsoft Windows XP serves as the basis for all the screenshots in the book. If you?re on another platform such as Mac or Linux, your interface may look slightly different. Additionally, we show IDEA in its default look and feel. If you?ve selected an alternate look and feel through the IDEA Preferences dialog, your interface will obviously look different.
With the exception of features new to 5, the screenshots in this text were created with version 4.5 under the Windows operating system. Version 5 of IDEA ships with a new look and feel, known as Alloy, and thus may appear slightly different. In addition, there maybe some slight differences between the versions 4.5 and 5 interfaces.
Throughout the text are callouts that focus attention on various aspects of using the software. You?ll encounter tips that point out clever or time-saving tricks, and warnings that alert you to particularly nasty situations you?d do well to avoid. You?ll also see IDEA 5 callouts like this:
At the time of the first writing, IDEA 5 was still in development. Although we have worked closely with JetBrains to ensure accuracy, some of the 5 features may have changed slightly before the final release. We added IDEA 5 callouts throughout the text to highlight the differences between versions 4.5 and 5.
Source code for all of the examples used in this book is available for download from the publisher?s website www.manning.com/fields3.
Purchase of IntelliJ IDEA in Action includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/fields3. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.
Manning?s commitment to our readers is to provide a venue where a meaningful dialog between individual readers and between readers and the authors can take place. It is not a commitment to any specific amount of participation on the part of the authors, whose contribution to the AO remains voluntary (and unpaid). We suggest you try asking the authors some challenging questions lest their interest stray!
The Author Online forum and the archives of previous discussions will be accessible from the publisher?s website as long as the book is in print.
Duane K. Fields, web applications developer and Internet technologist, has an extensive background in the design and development of leading-edge Internet applications for companies such as IBM and Netscape Communications. With over 12 years? experience in software development, Duane currently works for upstart Internet company Pluck. He has published numerous articles on all aspects of Java applications development and is coauthor of the bestselling Web Development with JavaServer Pages. He is a Sun Certified Java programmer, is an IBM Master Inventor, and holds an engineering degree from Texas A&M University. Duane lives in Bastrop, just outside of Austin, Texas, with his wife and young son. He can be reached at his web site at http://www.duanefields.com.
Stephen Saunders is a enterprise Java software engineer with a decade of experience spanning numerous industries, including knowledge management, financial services, and master data management. He?s been using IDEA exclusively as his development environment of choice since version 1.0. He holds a BSc in Computing Sciences and a BA in English from Dalhousie University. Stephen lives in Halifax, Nova Scotia, on the rocky eastern shore of Canada, with his wife and their two young boys.
Eugene Belyaev is co-founder, president, and chief technology officer of JetBrains. With a PhD in Economics and a MS in Computer Science, Eugene has more than nine years of experience working with human-computer Interaction (HCI) as he has honed his skills at user interface design and software usability on a wide range of end-user application development projects. For the past five years, he has focused on creating and perfecting complex tools for developers in the real world. The popular Java IDE, IntelliJ IDEA, is one of his well-known creations. Eugene lives and works in St. Petersburg, Russia.
The figure on the cover of IntelliJ IDEA in Action is a ?Subaltern Officer of the Janissaries.? The Janissaries were elite troops that served as bodyguards of the sultan in the Ottoman Empire. The illustration is taken from a collection of costumes of the Ottoman Empire published on January 1, 1802, by William Miller of Old Bond Street, London. The title page is missing from the collection and we have been unable to track it down to date. The book?s table of contents identifies the figures in both English and French, and each illustration bears the names of two artists who worked on it, both of whom would no doubt be surprised to find their art gracing the front cover of a computer programming book...two hundred years later.
The collection was purchased by a Manning editor at an antiquarian flea market in the ?Garage? on West 26th Street in Manhattan. The seller was an American based in Ankara, Turkey, and the transaction took place just as he was packing up his stand for the day. The Manning editor did not have on his person the substantial amount of cash that was required for the purchase and a credit card and check were both politely turned down. With the seller flying back to Ankara that evening the situation was getting hopeless. What was the solution? It turned out to be nothing more than an old-fashioned verbal agreement sealed with a handshake. The seller simply proposed that the money be transferred to him by wire and the editor walked out with the bank information on a piece of paper and the portfolio of images under his arm. Needless to say, we transferred the funds the next day, and we remain grateful and impressed by this unknown person?s trust in one of us. It recalls something that might have happened a long time ago.
The pictures from the Ottoman collection, like the other illustrations that appear on our covers, bring to life the richness and variety of dress customs of two centuries ago. They recall the sense of isolation and distance of that period?and of every other historic period except our own hyperkinetic present.
Dress codes have changed since then and the diversity by region, so rich at the time, has faded away. It is now often hard to tell the inhabitant of one continent from another. Perhaps, trying to view it optimistically, we have traded a cultural and visual diversity for a more varied personal life. Or a more varied and interesting intellectual and technical life.
We at Manning celebrate the inventiveness, the initiative, and, yes, the fun of the computer business with book covers based on the rich diversity of regional life of two centuries ago? brought back to life by the pictures from this collection.