Your First Java Program
Your First Java Program
Shane Walsh - 04/12/22 - G00406694@atu.ie
Steps to Compile and Run your first Java Program
This will be very step by step to start out, but bear with it. For all intents and purposes I will be using TextPad 8 for my examples and steps.
Step 1 - Open TextPad and create a new file titled Hello.java, it must have the .java on the end to denote it is a java file as opposed to the vast array of alternatives such as .cpp for C++ or .py for the Python programming language.
Step 2 - create source code for your Hello World program in Java.
- Declare a class, we'll use the name "Hello".
- Declare the main method public static void main(String args[]) { }
- Now, within those curly braces, type System.out.println("Hello World"); - This prints Hello World in Java.
- java is case sensitive, please use consisting casing to what I use or as presented by other documentation.
Note:
- When we create what are known as classes, methods and more. We typically use curly braces at the end to enter them, allowing us to write code within or modify pre-existing code.
- When we want to use a method such as the println method used above, we end it in a semi-colon to denote the activation of the method.
Step 3 - Save your file Hello.java, make sure to save it somewhere you'll find convenient for later such as a JavaCode folder or within a general workspace folder.
Step 4 - Go to Tools > Compile Java to ready your code & Tools > Run Java Application to run your code in a cmd prompt.
Final Note:
If you wrote this code in a simpler manner like the base Notepad, there would be more required steps to compile and run our code. On the flip side, an even more sophisticated IDE will automatically do the compiling and execution together at the click of the button, while these programs take time for new users to come to grips with, they are very convenient and improve efficiency.
Comments
Post a Comment