By Hilliam – Junior Developer at futureCoders
The IntelliJ (Intelligent Java) IDE boasts a numerous amount of features that aid the development of Java code, both writing and executing. Like a normal IDE, it provides the general necessary features for writing code. This includes the auto-indentation of code, syntax highlighting and auto-completing variable or method names, all as to reduce the wastage of time.
As a specialised Java IDE, one can create various file types for classes and methods using different modules and packages. Upon starting a new project, different libraries can be imported upon request if needed, and templates can be used when starting the first class of a given project. The basis for a class starts off with a .java file under a name that is the class name within that .java file. For example, the class runJson inhabits the runJson.java file. This file is held within a package or folder of files, often named a JAR if the folder has been compressed. A general base package within the IntelliJ IDE is the com.company package, a package having the purpose of organising Java classes within itself so that those classes can interact with each other. A main.java file within a project is the foundation for the entire project, with the class within the file being called main. Different methods from other files within the project, given public access by its class, can be used within any file, however, it is a standard to often call the primary methods using the main.java file as to run the whole program.
After the creation of a new project, a project tree is often given, giving ease to switching between classes within the same package. Within the classes, methods can be created under that class, for the purpose of executing a procedure or taking in a parameter given in between the parentheses when calling the method and returning a value. Methods essentially drive the program by executing specific code as to manipulate data and provide an appropriate output upon its usage.
To execute classes, the green play button, upon the top right corner of the platform, can be clicked on as to execute the entire class that is stated to its left. This may be the Main(.java) class, or another class created within the same project. If a ‘Main’ class is not defined within any of the files within the project folder, a primary main class must be defined by editing the configurations, by using the simplified pathname ‘com.company.<class name>’. This can be done, or the primary class that runs the necessary procedures to execute the entire project can be refactored (menu bar) through renaming that file and class to Main.java. Upon execution, all processes within the class through the calling of methods will occur. To execute individual methods, the same green play button will be visible within the code editor but diminished; once clicked, it will run that method, starting from the line the play button was present upon.
It is important to also make use of the debugging feature given, denoted as the green insect next to the green play button. This creates an instance upon a virtual machine that will run your Java class(es) and check for errors or bugs in the code. This is only for the checking of syntax errors, those that break the formal structure of Java code and thus will break the Java program. Before code can be executed or debugged, it must be compiled or built, which can be done through the IntelliJ IDE, as to turn the human language Java code into object code, a translated form of the code that the computer system can understand. This object code will then be sent to the computer system to execute and the result is outputted upon the IntelliJ IDE in a run window. These processes of building and running the code can be seen upon the bottom bar of the IDE, along with the time it takes to complete the processes upon completion.
The IntelliJ IDE also allows for the usage of test frameworks such as JUnit. Such a framework like JUnit can be used as to test for logical errors within the code and check whether outputs from given inputs are correct to your understanding. To add a test to a given class, click on the class within the code editor and after a few seconds, a lightbulb should appear. Clicking on it will give the options as to create a test. Clicking this will create a test file, with a class to test the code. If JUnit is not configured yet, pressing Alt + Enter upon the red @Test annotation will allow you to add the JUnit jar to the classpath. This will import the JUnit test module. If need be, the JUnit testing configuration may need to be set up if it is not present upon the left of the green play button. To do this, the run configurations must be accessed, next to the green play button. From here, a new JUnit configuration must be added with the green plus button. The usage of the pathname ‘com.company.<testfile>’ should be necessary as the class being run by the JUnit configuration. It can then be run when given the necessary checks to run within the test file using Hamcrest matchers by importing the module using the words ‘import static org.hamcrest.CoreMatchers.*’. Configurations can be changed between testing and normally running the program by the configuration dropdown menu, making it easy to test and execute code.
Aside from being able to change the settings of the file, the top menu bar also gives options for the editing, analysing and scanning of code.
The view and the window menu will give a series of visuals for the structure of the code but also the shape of the IDE. Additional tool windows can be added via this menu or by clicking upon the bottom left image of a screen. The navigate menu is useful for scaling to a needed section, if scrolling through the code for a class is a journey. Code can be reformatted and move around using the commands within the code menu and the analyse menu gives features to provide facts and statistics about the code. The VCS menu is useful for looking at the changes between saves of the class. By viewing the local history, the current version of the java class can be reverted back to that previous version of the class.
With that being said, that should be a rough baseline guide of the IntelliJ IDE playground as to start programming in Java. Thank you for reading!