Google+

285. Eclipse Automatically adds the Package Name into the newly created Java Class







Please follow the below steps to find out  how the Eclipse IDE automatically adds the package name into the newly created Java Class:

1. Create a Java Project named "SecondProject" in Eclipse IDE
2. Create a Package named "secondPackage" under the above created Project "SecondProject" as shown below:


3. Right click on the newly created Package  "secondPackage" and select 'New' -> 'Class' option as shown below:


4. Ensure that 'New Java Class' dialog is displayed and enter Class Name say "Second" into the 'Name' field as shown below and click on 'Finish' button:


5. Ensure that 'Second' Class got added and view the default code provided in the newly created Class as shown below:


6. Observe that Eclipse IDE  has automatically added Package Name to the newly created Java Class  i.e "Second" as shown below:


After looking at the above image, its very clear that on creating a Class Named "Second" under "secondPackage" package, Eclipse IDE has automatically added the Package Name "secondPackage" into the newly created "Second" Class.

But what happens when we don't create a package and add the Class without creating a Package. Lets find it out by following the below steps:

1. Create a Java Project named "ThirdProject" in Eclipse IDE
2. Don't create any Package under this Project
3. Right click on the Project "ThirdProject" and select 'New' -> 'Class' option as shown below:


4. Ensure that 'New Java Class' dialog is displayed and observe that Package text box field is displayed empty as shown below:


5. In 'New Java Class' dialog, enter the Class Name as "Third" into the 'Name' field  and observe that the warning message "The use of the default package is discouraged" is displayed as shown below:


After looking at the warning message in the above screenshot, its very clear that "Third" Class will get added to the "default" package but the Eclipse IDE informs us that adding classes under the "default" package is not recommended or generally not followed.

6. Click on 'Finish' button on the 'New Java Class' dialog and ensure that the "Third" Class will get added with the default code as shown below:


7. After looking at the above screenshot having the default code, its very clear that No Package Name got added automatically by the Eclipse IDE to the newly created "Third" Class as shown below:




Please comment below to feedback or ask questions.

Lets Start writing a Selenium WebDriver Test on our own will be explained in next post.



No comments:

Blog Index