Intellij Idea – Introduction ”; Previous Next IntelliJ is one of the most powerful and popular Integrated Development Environments (IDE) for Java. It is developed and maintained by JetBrains and available as community and ultimate edition. This feature rich IDE enables rapid development and helps in improving code quality. What is IDE and its benefits? IDE stands for Integrated Development Environment. It is a combination of multiple tools, which make software development process easier, robust and less error-prone. It has following benefits over plain text editor − Integration with useful tools like compiler, debugger, version control system, build tools, various frameworks, application profilers and so on. Supports code navigation, code completion, code refactoring and code generation features which boosts development process. Supports unit testing, integration testing and code coverage via plug-ins. Provides rich set of plug-ins to enhance IDE functionality further. Features of IntelliJ IntelliJ IDEA has some top productive Java code completion features. Its predictive algorithm can accurately assume what a coder is attempting to type, and completes it for him, even if he doesn’t know the exact name of a particular class, member or any other resource. Deep Insight IntelliJ IDEA really understands and has a deep insight into your code, as well as the context of the coder, which makes it so unique among other Java IDEs. Smart code completion − It supports context based code completion. It gives a list of the most relevant symbols applicable in the current context. Chain code completion − It is an advanced code completion feature which lists applicable symbols accessible via methods or getters in the current context. Static member”s completion − It allows you to use static methods or constants and automatically adds the required import statements to avoid compilation error. Detecting duplicates − It finds the duplicate code fragments on the fly and gives notification/suggestion about it to user. Inspections and quick-fixes − Whenever IntelliJ detects that you”re about to make a mistake, a little light bulb notification pops up on same line. Clicking it shows the suggestion list. Developer Ergonomics IntelliJ IDEA is designed around the coding principle that developers should be allowed to write codes with as less distraction as possible. That is why in this case, the editor is the only thing visible on the screen, with dedicated shortcuts for all other coding-unrelated functions. Editor-centric environment − Quick pop-ups help in checking additional information without leaving the current context. Shortcuts for everything − IntelliJ IDEA has keyboard shortcuts for nearly everything, including rapid selection and switching between tool windows and many more. Inline debugger − Inline debugger allows you to debug application in IDE itself. It makes the development and debugging process seamless. Built-in Developer Tools To help the developers organize their workflow, IntelliJ IDEA offers them an amazing toolset, which comprises of a decompiler, Docker support, bytecode viewer, FTP and many other tools − Version control − IntelliJ supports most of the popular version control system like Git, Subversion, Mercurial, CVS, Perforce, and TFS. Build tools − IntelliJ supports Java and other build tools like Maven, Gradle, Ant, Gant, SBT, NPM, Webpack, Grunt, and Gulp. Test runner and code coverage − IntelliJ IDEA lets you perform unit testing with ease. The IDE includes test runners and coverage tools for major test frameworks, including JUnit, TestNG, Spock, Cucumber, ScalaTest, spec2, and Karma. Decompiler − IntelliJ comes with a built-in decompiler for Java classes. When you want to take a look inside a library that you do not have the source code for, you can do it without using any third-party plug-ins. Terminal − IntelliJ provides built-in terminal. Depending on your platform, you can work with the command line prompt, like PowerShell or Bash. Database tools − IntelliJ provides database tools, which allow you to connect to live databases; run queries; browse and update data; and even manage your schemas in a visual interface from IDE itself. Application server − IntelliJ supports major application servers: Tomcat, JBoss, WebSphere, WebLogic, Glassfish, and many others. You can deploy your artifacts onto application servers and debug the deployed applications in IDE itself. Docker support − Via a separate plug-in, IntelliJ provides a dedicated tool window that lets you connect to locally running Docker machines. Comparison between Ultimate and Community Edition The Ultimate Edition is designed to assist in web and enterprise development, whereas the Community Edition is designed for JVM and Android Development. Let us consider a few important points that will help us understand the comparison between the two editions − Feature Ultimate Edition Community Edition License Commercial Open-source, Apache 2.0. for commercial development. Java, Kotlin, Groovy, Scala Supported Supported Android development Supported Supported Maven, Gradle, SBT Supported Supported Git, SVN, Mercurial, CVS Supported Supported Detecting Duplicates Supported Not supported Perforce, TFS Supported Not supported JavaScript, TypeScript Supported Not supported Java EE, Spring, GWT, Vaadin, Play, Grails, Other Frameworks Supported Not supported Database Tools, SQL Supported Not supported Print Page Previous Next Advertisements ”;
Category: intellij Idea
Intellij Idea – Useful Resources ”; Previous Next The following resources contain additional information on IntelliJ IDEA. Please use them to get more in-depth knowledge on this. Useful Links on IntelliJ Idea IntelliJ Idea Wiki − Wikipedia Reference for IntelliJ Idea Useful Books on IntelliJ Idea To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;
Create First Java Project
Intellij Idea – Create First Java Project ”; Previous Next It is time we got a hands-on experience with IntelliJ. In this chapter, we will create our first Java Project. We will write and execute the traditional Hello World program. This chapter explains the compilation and running of Java application. Create Project For anything related to development, a developer has to create a new project with IntelliJ. Let us follow these steps to create a project − Launch IntelliJ. Go to File → New → Project menu. Select the Java project and appropriate SDK and click on the Next button. If you want to create a Java class with the main method, then select Create Project from the template checkbox. Select the command line app from the dialog box shown below and continue. Enter the project name and the directory location. Click on the Finish button. Create Package A package is created under Java project and can be created separately, or at the same time of creating a class. Let us follow these steps to create a package − Go to the project perspective. Right-click on Project, select the New->Module option. The new module window will be similar to the new project. Select the Java option and appropriate SDK and click on the Next button. Enter the module name. Click on the Finish button. Create Java Class In this section, we will learn how to create a Java class. A Java class can be created under a Java module. Follow these steps to create a module − Go to the Project perspective. Expand Project and select the src directory from the module. Right click on it; select the New->Java Class option. Enter the class name in the dialog-box and click on the OK button. It will open the Editor window with the class declaration. Run Java Application We will now see how to run a Java application. Follow these steps and see how it runs − Let us write a simple code, which will print a message on the console. Enter the following code in the Editor window − public class HelloWorld { public static void main(String[] args) { System.out.println(“Hello, World !!!”); } } Go to the Run menu and select the Run option. Select the Class name and click on Run. If there are no compilation errors, then it will show output at the bottom of the window. Print Page Previous Next Advertisements ”;
Intellij Idea − Databases
Intellij Idea – Databases ”; Previous Next IntelliJ provides database tool which allows you to perform database related operation from the IDE itself. It supports all major databases like MySQL, Oracle, Postgress, SQL server and many more. In this chapter, we will discuss how IntelliJ supports MySQL database. We assume that the reader is familiar with the database concepts and the required databases’ tools are installed and configured on your system. Create Database To begin with, we will create a database – test_db. Execute the following command in the command prompt − Connect to Database Follow these steps to connect to a Database − Navigate to View → Tool Windows → Database. Click on the green plus icon and select Data Source → MySQL. Enter the host address and click on the Test Connection button. If everything goes well then it’ll show Successful as shown in above image. Click on OK button to save connection. Create table Follow these steps to create a new table − Right-click on the database pane and select schema. Select the New → Table option A new window will appear. Define the table with columns, types and so on. Click on the Execute button Click on the Execute button Insert Data Follow these steps to insert data − Select table from the database pane. It will open table in the new window. Click on the plus icon to insert new row. Click on the Submit button to make the changes permanent. Retrieve Data To retrieve data, double-click on student_table from the database pane. It will show table data in new window. To ensure that the data is inserted into the table, open the command prompt and execute the following commands − Print Page Previous Next Advertisements ”;
Intellij Idea – Code Refactoring ”; Previous Next In this chapter, we will learn about Code Refactoring and how it works in IntelliJ. Code refactoring is restructuring of code without changing its functionality and usability. Code refactoring can be done to improve code readability, performance or to remove unused/duplicate functionality. IntelliJ provides great support for code refactoring. This chapter discusses various code refactoring actions. Rename Rename actions can be used to rename methods, its parameters, class attributes, local variables and so on. Let us create the following class in IntelliJ. public class Employee { private String name; private String address; private int age; public Employee() { this(“Jarvis”, “Palo Alto”, 35); } public Employee(String name, String address, int age) { this.name = name; this.address = address; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return “Employee{” + “name=”” + name + ””” + “, address=”” + address + ””” + “, age=” + age + ”}”; } public static void main(String args[]) { Employee e = new Employee(); System.out.println(e); } } Now, let us rename Employee class to Person. This action will do modifications in constructors and the main() method − Select Employee word Go to Refactor → Rename and rename it with Person. Replace Code Duplicates This is one of the powerful refactoring actions. IntelliJ identifies code duplicates and replaces it with appropriate code. Let us introduce code duplication and refactor it. Type the following code in the Editor − public class Employee { private String name; private String address; private int age; public Employee() { this(“Jarvis”, “Palo Alto”, 35); } public Employee(String name, String address, int age) { this.name = name; this.address = address; this.age = age; } public void setData(String name, String address, int age) { this.name = name; this.address = address; this.age = age; } public void showEmployeeDetail() { System.out.println(“Name = ” + name + “, Address = ” + address + “, Age = ” + age); } public static void main(String args[]) { Employee e = new Employee(); e.showEmployeeDetail(); } } In this example, Employee(String name, String address, int age) constructor and public void setData(String name, String address, int age) method are exactly identical. After refactoring, the Employee(String name, String address, int age) constructor gets modified as follows − public Employee(String name, String address, int age) { setData(name, address, age); } To replace the duplicates − Go to Refactor → Find and Replace Code Duplicates. Select refactor scope and follow on-screen steps to complete action. Copy Refactoring In this section, we will understand how to copy one class to another. Let us copy Employee class to Person class. We can copy it to the existing module or a new one. IntelliJ will do the required changes depending on it. Follow these steps to perform copy refactoring − Go to Refactor → Copy, it will open the dialog box. Enter new name and destination package. Click on the OK button and it will do the needful. Move Refactoring Move refactoring is similar to copy but instead of making another copy it moves the code to a different package or make it as inner class of another class. Follow these steps to perform move refactoring − Go to, Refactor → Move. A new window will appear. Select one of the options according to your choice and click on Refactor. Safe Delete The Safe Delete action will delete object only when it is not referenced anywhere in the project. The target for this option can be class, interface, method, field or parameter. Let us see this in action. Type the following code in Editor − public class HelloWorld { static void sayHello() { System.out.println(“Hello, World !!!”); } public static void main(String[] args) { sayHello(); } } Follow these steps to perform the safe delete action − Select the sayHello() method. Right-click on it and select the Refactor → Safe Delete option. As the sayHello() method is being used it will show an error as in the following screenshot − Change Signature The action modifies method signature. It can change the method name, its parameters, types, return values and so on. Let us take a method from the above example and change its signature. Follow these steps to perform the Change Signature action − Select method. Right-click on it and select the Refactor → Change signature action A new window will appear wherein you can perform the above actions. At the bottom of the window, it shows the preview of new signature. Type Migration The Type Migration changes the type of the symbol. This symbol can be a method parameter or class attribute. Let us consider the following method before performing the required action − static void sayHello(String name) { System.out.println(name); } Follow these steps to perform type migration − Select the “String” data type. Right-click on it and select Refactor → Type migration. Enter the required data type in the given text box. Choose scope and click on the Refactor button. Print Page Previous Next Advertisements ”;
Intellij Idea – Migrating from Eclipse ”; Previous Next Eclipse is yet another popular Java IDE. If you are a current user of Eclipse and want to migrate from it to IntelliJ, then this is a good starting point. This chapter discusses how to import Eclipse projects in IntelliJ, its terminologies equivalent to Eclipse, popular shortcuts and frequently asked questions. Import existing project In this section, we will discuss how to import an existing project. Follow these steps to import the project − Navigate to File → New → Project from Existing Sources. Select your NetBeans project directory. When the Import Project wizard opens, select the Create project from existing sources option. Follow the on-screen instructions to continue. IntelliJ vsEclipse terminology The following table compares IntelliJ and NetBeans terminologies − IntelliJ Eclipse Project Workspace Module Project Facet Facet Library Library SDK JRE Path variable Classpath variable Popular shortcuts IntelliJ is a keyboard-centric IDE. It provides shortcuts for most of the actions. The following table lists a few popular shortcuts − Action Shortcut Run java program ctrl+shift+F10 Organize imports ctrl+alt+o System.out.println() Type sout and Press ctrj+j Delete current line ctrl + y Search ctrl + shift + f Generate getter and setter alt + insert Format code ctrl + alt + l Comment out code ctrl + / Go to line ctrl + g Go to declaration ctrl + b Rename shift+F6 Move lines ctrl + shift + up/down Debugger shortcuts The following table lists down commonly used debugger shortcuts − Debug action Shortcut Debug a program Shift + F9 Choose configuration and debug Shift+Alt+F9 Step over F8 Step into F7 Smart step into Shift + F7 Step out Shift + F8 Force step over Shift+Alt+F8 Force step into Shift+Alt+F7 Resume program F9 Evaluate expression Alt+F8 Toggle breakpoints Ctrl+F8 View breakpoints Ctrl+Shift+F8 FAQsand Tips In this section, we will see a few Frequently Answered Questions and tips. The FAQs and tips are as follows − Use Eclipse Compiler While Eclipse uses its own compiler, IntelliJ IDEA uses the javac compiler bundled with the project JDK. If you want to use the Eclipse compiler − Navigate to File → Settings → Build, Execution, Deployment → Compiler → Java Compiler. Select the required compiler from User compiler dropdown. Eclipse Keymap For Eclipse users who prefer not to learn new shortcuts, IntelliJ IDEA provides the Eclipse keymap that closely mimics its shortcuts − Navigate to File → Settings → Keymap option. Select Eclipse from Keymap dropdown. Code formatting To import your Eclipse formatter settings − Navigate to File → Settings → Editor → Code Style → Java. Select the Eclipse XML profile. Working with Build Tools Like Eclipse, IntelliJ does not provide visual forms for editing Maven/Gradle configuration files. Once you have imported/created your Maven/Gradle project, you are free to edit its pom.xml/build.gradle files directly in the text editor. Print Page Previous Next Advertisements ”;
Intellij Idea – Version Control ”; Previous Next IntelliJ supports various version control systems like Git, Subversion, Mercurial, CVS, GitHub and TFS. You can perform version control related action from the IDE itself. In this chapter, we will discuss Git and Subversion (hereafter referred to as SVN). We assume that the reader is familiar with Git and SVN tool and its terminology. Git In this section, we will learn how to work with Git. Clone To clone an existing Git repository − Navigate to File->New->Project from Version Control->Git. Enter the repository URL, Parent directory and Directory name. Click on the clone button to continue. Upon successful running of the above steps, the repository will get cloned. Track changes Git will track the changes that you make in repository. Let us modify any file from the repository and compare it with the repository. Navigate to VCS → Git → Compare with Latest Repository Version. The above step will open the diff window. You can see there is a new line on the right side with green background colour. Git shows it in green as we have added new contents. If we remove any contents then it’ll be shown in red colour Revert local changes Follow these steps to discard the local changes − Navigate to the VCS → Git → Revert option. It will ask for confirmation and remove your changes. Add file to repository To add file to repository navigate to VCS → Git → Add option. This action is similar to the git add action. Commit changes The Commit operation will create local commit. It is similar to the git commit action. To perform commit − Navigate to the VCS → Git → Commit File option. Select files to be committed. Enter commit message and click on Commit button. Push changes to the remote repository The Push action will send local changes to the remote repository. To push changes − Navigate to the VCS → Git → Push option. A window will appear. Here, you can see the comitts to be pushed. Verify commit and click on the Push button to publish your changes. View history or logs To show history, navigate to the VCS → Git → Show history option. This action is similar to the git log command. It will show history as follows − Get updates Follow these steps to fetch updates from the repository − Navigate to the VCS → Git → Pull option. Select the option according to your requirements. Click on the Pull button. Add existing project to Git To add existing project under Git − Navigate to VCS → Import into Version Control → Create Git repository. Select project by browsing directory. Click on the OK button. Subversion In this section, we will understand how Subversion works in IntelliJ. Let us consider a few important actions to understand this. Checkout To checkout SVN repository − Navigate to File → New → Project from Version Control → Subversion. Enter repository URL. Click on the OK button. Track changes SVN will track changes you made in the repository. Let us modify any file from repository and compare it with repository − Navigate to VCS->Subversion->Compare with Latest Repository Version You can see there is new line on right side with green background colour. SVN shows it in with green background to indicated the addition of new content. If we remove any content then it will be shown in red colour. Revert local changes Follow these steps to revert the local changes you have made − Navigate to the VCS → Subversion → Revert option. It will ask for confirmation and remove your changes. Commit changes to remote repository Follow these steps to commit changes in the remote repository − Navigate to VCS → Subversion → Commit Files option. A new window will appear. Here, you can see the files to be committed to remote respository. Verify the files and click on the Commit button to publish your changes. View history or logs To show history, navigate to the VCS → Subverion → Show history option. This option is similar to the svn log command. It will show history as follows − Update operation To fetch latest changes navigate to VCS → Subversion → Update File/Update Folder option. Add existing project to Subversion Follow these steps to add existing project under SVN − Navigate to VCS → Import into Version Control → Import into Subverion. Enter the repository URL and click on the Import button − Print Page Previous Next Advertisements ”;
Intellij Idea − Debugging
Intellij Idea – Debugging ”; Previous Next Debugger makes application debugging much easier. Using debugger, we can stop the execution of program at a certain point, inspect variables, step into function and do many things. IntelliJ provides inbuilt Java debugger. Breakpoints Breakpoint allows stopping program execution at certain point. Breakpoints can be set by hovering the mouse over the Editor’s gutter area and clicking on it. Breakpoints are denoted using red circle symbols. Consider the breakpoint set at line 3. Consider the following steps to understand more on how the breakpoints work − Right-click on the red circle symbol. Select the More options. To remove breakpoint just click on same symbol. Follow these steps to start the debugger − Navigate to the Run menu. Select the Debug option. Step into While debugging, if a function is encountered and a step into action is selected, then debugger will stop program execution at each point of that function as if debugging is enabled for that function. For instance, when program execution reaches at line 9 and if we select the step into action then it stops the execution at each line in the sayGoodBye() function. Step out The Step out action is exactly the reverse of Step in action. For instance, if you perform the step out action with the above scenario then debugger will return from the sayGoodBye() method and start execution at line 10. Step over The Step over action does not enter into function instead, it will jump to the next line of code. For instance, if you are at line 9 and execute the step over action then it will move execution to line 10. Resume Program The Resume Program action will continue execution of program by ignoring all breakpoints. Stop action The Stop action helps stop the debugger. Smart step into While debugging, we may sometimes reach a line of code that calls several methods. When debugging these lines of code, the debugger typically allows us to use step into and leads us through all child functions and then back to the parent function. However, what if we only wanted to step into one child function? With Smart step-into, it allows us to choose the function to step into. Now, let us create a Java class with the following line of code − public class HelloWorld { public static void main(String[] args) { allFunctions(); } static void allFunctions() { System.out.println(function1() + ” ” + function2() + ” ” + function3()); } static String function1() { return “function1”; } static String function2() { return “function2”; } static String function3() { return “function3″; } } In the above code, allFunctions() calls 3 more functions. Let us set the breakpoint at this function. Follow these steps to perform smart step into − Go to run Select smart step into. Select the child function to go. Inspecting variables During debugging, IntelliJ shows value of variable in the Editor window itself. We can also view the same information in the Debug window. Evaluate expression Evaluate expression allows to evaluate expression on the fly. Follow these steps to perform this action − Start application in debugger Navigate to Run->Evaluate expression. Enter expression. In the example given below, the current value of variable ‘i’ is 0; hence, expression ‘i > 100’ will evaluate to false Print Page Previous Next Advertisements ”;
Intellij Idea – Running Projects ”; Previous Next IntelliJ provides multiple ways to create configuration. This chapter discusses the options to create temporary, permanent configuration. It also discusses method to share configuration among other users. Create Temporary Configuration Temporary configuration is created when you run or debug Java class or test case. Consider the following steps to understand how this works − Create a Java class. Right-click on it and select the Run option. After the first Run, temporary configuration is added to the run menu. Create Permanent Configuration Temporary configuration can be converted to permanent configuration by saving it with IntelliJ. To save configuration, click on the Save Configuration option from the Run menu − You can also modify the existing configuration by editing it. Create New Configuration In this section, we will understand how to create new configuration. Follow these steps to create new configuration − Navigate to the Run → Edit Configuration. Click on the Plus button to add new configuration. Select Application from the dropdown list. It will create un-named configuration. Configure it according to your requirements and click on the OK button. This saved configuration will be accessible from the Run menu along with other configurations. Sharing the Configuration Follow these steps to share configuration with others − Navigate to the Run → Edit Configuration. Select configuration from the left pane and click on the Share checkbox. It will store configuration on disk. If directory based format is used, it will save configuration in separate file under runConfiguration folder. Otherwise, it will store configuration in the .ipr file. Run Configuration To run project with specific configuration − Select configuration from the Run menu. Run the project as shown in the following screenshot − Print Page Previous Next Advertisements ”;
Intellij Idea – Home
Intellij Idea Tutorial PDF Version Quick Guide Resources Job Search Discussion IntelliJ IDEA (hereafter referred as IntelliJ) is one of the most powerful and popular Integrated Development Environments (IDE) for Java. It was developed and is maintained by JetBrains, and is available in community and ultimate edition. This feature-rich IDE enables rapid development and helps in improving code quality. This tutorial starts with a basic introduction and slowly dives deep into the advanced features. The tutorial is divided into 2 parts: beginners can start from the first 4 chapters. Others can skip over directly to Chapter-5. Audience This tutorial is targeted for first-time learners, as well as moderate users of IntelliJ. Beginners will get a fair understanding about IntelliJ and its functioning, and others will be able to take their knowledge on this subject to the next level. Prerequisites This tutorial requires that the readers have some preliminary knowledge of the software development process, along with Java programming language. In the later sections of this tutorial, we will discuss integration with build tools, unit testing frameworks, debugger, profiling, version control system and database. It is assumed that the required tools are installed and configured on system and reader is familiar with those tools. Print Page Previous Next Advertisements ”;