Executable Java Applications
Executable Java Applications
1h 58m

In this course, we will learn the concepts of Java EE 7 with a focus on Java Basics.

Learning Objectives

  • What Java classes, Executable Java, Access Modifiers are and how they work

Intended Audience

  • Anyone looking to get Oracle Java Certification
  • Those who want to improve Java 7 EE knowledge
  • Java developers


  • Have at least 2 years of Java development experience 

Hello there. In this lesson, we'll talk about executable  Java applications. So, let's start. The OCA  Java EE 7 application developer exam requires that you understand the meaning of an executable  Java application and its requirements. That is, what makes a regular  Java class and executable  Java class?

Doesn't the  Java virtual machine execute all the  Java classes when they are used? If so, what is a  non-executable Java class? An executable  Java class is a class which when handed over to the JVM starts its execution at a particular point in the class. The main method defined in the class. The JVM starts executing the code that is defined in the main method. You cannot hand over non-executable Java class to the JVM and ask it to start executing the class. In this class, the JVM won't know how to execute it because no entry point is marked for the JVM in a non-executable class. Typically, an application consists of several classes and interfaces that are defined in multiple  Java source code files. Of all these files, a programmer designates one of the classes as an executable class. The programmer can define the steps that the JVM should execute as soon as it launches the application. For example, a programmer can define an executable  Java class that includes code to display the appropriate GY window to a user and open a database connection.

In this figure, the classes, window, user data, server connection, and user preferences don't define the main method. Class launch application defines the main method and is an executable class. The first requirement in creating an executable Java application is to create a class with a method whose signature, name, and method arguments match  the main method defined as follows. This main method should comply with the following rules. The method must be marked as a public method. The method must be marked as a static method. The name of the method must be made. The return type of this method must be void. The method must accept method argument of a string array or a variable argument of type string. It's valid to define the method parameter passed to the main method as a variable argument var args of type string. To define a variable argument variable, the ellipses should follow the type of variable and not the variable itself. A mistake made by a lot of new programmers.

As previously mentioned, the name of the string array passed to the main method need not be args to qualify it as the correct main method. Thus, the following examples are also correct definitions of the main method. To define an array, the square brackets can follow either the variable name or its type. The following is a correct method declaration of the main method. It's interesting to note that the placement of the keywords, public and static, can be interchanged, which means that the following are both correct method declarations of the main method. For example, we got four candidates. Trea, Harry, Paul, and Selvin, who are hypothetical programmers also studying for this certification exam. One of the programmers, Harry, executed a program that gave the output Java one. Now he's trying to figure out which of the following classes outputs these results. Given that he executed the class using the command  Java E Java, Java, Java, 1, 1, can you help him figure out the correct options? The answers are A and B. All the options in this question are supposed to execute using the command Java, E  Java, Java, 1, 1. The purpose of each of these terms. Term one,  Java: used to execute a  Java class. Term two E  Java: name of class to execute. Term three,  Java: passed as the first argument to the main method.

Term 4, 1: passed as the second argument to main. Term 5, 1: passed as the third argument to main. The output  Java one. The main method should output the first and either the second or the third method parameters passed to it. Options A and B are correct because they use the correct method signature of the method main. The name of the method parameter need not be args. It can be any other valid identifier. Option A outputs the values of the 1st and 3rd terms passed to it. Option B outputs the values of the 1st and 2nd terms passed to it. Option C is incorrect because this main method accepts a two-dimensional array. Hence, it won't be treated as the main method. Option D is incorrect because this code won't compile. The access modifier of a method, public, to be placed before its return type void. Otherwise, the code won't compile. So, that's it. In this lesson, we talked about executable  Java applications. Hope to see you in our next lesson. Have a nice day.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics