Java Newbie to Pro? Day 2 – How I Create My First Java Program

If you read my previous post, you know that Day 1 was all about setting up my Java development environment. Now that everything is ready, it’s time to write some actual Java code!

To save myself some keystrokes (and give you a more visual guide), I’ll be using video clips from Caleb Curry’s Java tutorial—because, let’s be honest, watching something is sometimes way easier than reading long explanations!

Creating a New Java Project in Eclipse

I followed the steps in this video clip to create a new Java project using Eclipse. Since the clip is from Caleb’s original tutorial, I had to make a few small tweaks because Eclipse’s default project setup has changed slightly over time. But here’s a challenge for you—try figuring out the tweaks yourself! A little bit of problem-solving will add to your technical sophistication and serve you well on your programming journey.

Creating the First Java Program

I followed the steps in this clip to create my very first Java program—smooth sailing, no hiccups! The process involves creating a Java class using the IDE. In Java, the class name must match the filename that contains it. So, in this case, I created a file named MySweetProgram.java, which holds a class with the same name: MySweetProgram.

In the next post, I’ll give a brief and superficial introduction to classes. For now, just think of a class as a container that holds different pieces of your program.

Tweak and Run the First Java Program

After setting up the program following the clip above, I used this clip to tweak the code and finally run it—successfully printing the phrase “Hello there!” to the console. Btw,these are the lines of our first program:

<span>public</span> <span>class</span> <span>MySweetProgram</span> <span>{</span>
<span>public</span> <span>static</span> <span>void</span> <span>main</span><span>(</span><span>String</span><span>[]</span> <span>args</span><span>)</span> <span>{</span>
<span>System</span><span>.</span><span>out</span><span>.</span><span>println</span><span>(</span><span>"Hello there!"</span><span>);</span>
<span>}</span>
<span>}</span>
<span>public</span> <span>class</span> <span>MySweetProgram</span> <span>{</span>
   <span>public</span> <span>static</span> <span>void</span> <span>main</span><span>(</span><span>String</span><span>[]</span> <span>args</span><span>)</span> <span>{</span>
      <span>System</span><span>.</span><span>out</span><span>.</span><span>println</span><span>(</span><span>"Hello there!"</span><span>);</span>
   <span>}</span>
<span>}</span>
public class MySweetProgram { public static void main(String[] args) { System.out.println("Hello there!"); } }

Enter fullscreen mode Exit fullscreen mode

“In the next post, we’ll learn more about the nitty-gritty of the program we’ve just finished writing.

原文链接:Java Newbie to Pro? Day 2 – How I Create My First Java Program

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
If you get tired, learn to rest, not to quit.
如果你累了,学会休息,而不是放弃
评论 抢沙发

请登录后发表评论

    暂无评论内容