A Simple Guide to Java Programming in Android Studio for Beginners

avatar

Greetings to "Learn2code" community on Hive.

I'm @skyehi and I'm happy to have discovered this amazing community dedicated to programming. I've had about two to three years experience with programming.

I started with the basics of Java Language and continued to developing android apps using The Android Studio IDE.

I've been able to learn how to develop many basic apps like Calculator, Alarm, Touch light, calendar and mobile browsers. I went on to develop a bit more complex apps like full Music and video players.

I'm happy to be part of this community to both learn and share my knowledge in computer programming.

Polish_20231021_130225048.jpgOriginal Image Source by hitesh0141 from Pixabay


For my very first blog post in this community, I'll share briefly a simple and short guide to Java Programming using Android Studio as our IDE.

This one's for all those that aspire to become mobile aop developers but find it difficult to understand the concept on your own.

If you're new to Android app development and want to learn Java programming in Android Studio, you're definitely in the right place. I'll break it down into easy-to-understand steps.

Alright Programmers without wasting much time, let's get into the codes.

2dk2RRM2dZ8gKjXsrozapsD83FxL3Xbyyi5LFttAhrXxr16mCe4arfLHNDdHCBmaJroMz2VbLrf6Rxy9uPQm7Ts7EnXL4nPiXSE5vJWSfR53VcqDUrQD87CZSpt2RKZcmrYrze8KanjkfyS8XmMCcz4p33NZmfHE4S9oRo3wU2.png

Getting Started

Now before we begin, you need to make sure you have Android Studio installed on your computer. Trust me guys, you don't need to be an expert, but some basic knowledge about programming will be helpful.

Since I want to discuss the coding part of the process, I may not talk about how to Android studio installed but if you need help from me, you can totally share that in the comment section and I'll help you.

Setting Up Your Environment

Installing Android Studio

  • Start by downloading and installing Android Studio. Think of it as the toolbox you need for making Android apps. It comes with templates and a platform to put in your codes and run the app you want to build or test.

Creating a New Project

  • Now after installing, open Android Studio, and when you're asked to start a new project, choose an "empty activity." This is like choosing a blank canvas to begin with. Since you're a beginner, you don't need to choose the other fancy templates just an empty activity is enough.

YpihifdXP4WNbGMdjw7e3DuhJWBvCw4SfuLZsrnJYHEpsqZFkiGGNCQTayu6EytKdg7zA3LL2PbZxrJGpWk6ZoZvBcJrADNFmaFEHagho8WsASbAA8jrpnELSvRtvjVuMiU1C5ADFX1vJgcpDvNtue9Pq83tjBKX62dqT5UoxtDk.png

Writing Your First Java Code

Now guys, it's time to write your first piece of code in Java Programming language using Android Studio.


Finding MainActivity.java

  • In Android Studio, you'll find a file named MainActivity.java in your project's folder. Think of this file as the very heart of your Android app. This is where the background codes that will determine the function of your app is written.

Understanding the Code

  • Now inside the MainActivity.java, there's a section of code that sets up your app. It looks a bit like this:
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

This code is like the foundation for your entire app.

Adding Your Code

  • Now you can put your own instructions inside the onCreate() part of the code to make your app do specific things. For example, you can use this code to show a simple message on your app which we call a Toast message. You know that short message that pops app usually at the bottom of your screen and leaves in a matter of seconds, that's the Toast message I'm talking about. Here's how that should look like;
Toast.makeText(getApplicationContext(), "Hello, Android!", Toast.LENGTH_SHORT).show();

YpihifdXP4WNbGMdjw7e3DuhJWBvCw4SfuLZsrnJYHEpsqZFkiGGNCQTayu6EytKdg7zA3LL2PbZxrJGpWk6ZoZvBcJrADNFmaFEHagho8WsASbAA8jrpnELSvRtvjVuMiU1C5ADFX1vJgcpDvNtue9Pq83tjBKX62dqT5UoxtDk.png

Running Your App

Now with this simple code you wrote, let's try to run the app and test to see how it would look like.

Connecting a Device

There are two ways you can run the test app. You can either use a built in template phone on the same Android studio which we call Virtual Device or you can use an actual device.

For me, I usually prefer an actual device so I can see in real life how the app looks like.

So let's check out how to run the app with your own android phone.


Starting Your App

When you're ready to run the app, simply click the "Run" button in Android Studio. It's usually shaped like a green triangle and you can't miss it. This action takes your code, makes it work, and shows your app on your chosen device.

YpihifdXP4WNbGMdjw7e3DuhJWBvCw4SfuLZsrnJYHEpsqZFkiGGNCQTayu6EytKdg7zA3LL2PbZxrJGpWk6ZoZvBcJrADNFmaFEHagho8WsASbAA8jrpnELSvRtvjVuMiU1C5ADFX1vJgcpDvNtue9Pq83tjBKX62dqT5UoxtDk.png

Seeing the Result

If everything goes well, you'll the app automatically open on your device with a message pop that says "Hello, Android!" Or whatever message you out inside the Toast when you were writing the code.


Congratulations guys, you've just built and run your first Java-based Android app in Android Studio.

This is just the beginning of your exciting journey into Android app development with Java. To learn more, you need to keep exploring Java basics and discover the many things you can do with Android.

In our next tutorial, we'll dive deeper into Java and how it works with Android apps.

So I'll encourage you to keep practicing, and you'll become a pro in no time! Happy coding guys!

2dk2RRM2dZ8gKjXsrozapsD83FxL3Xbyyi5LFttAhrXxr16mCe4arfLHNDdHCBmaJroMz2VbLrf6Rxy9uPQm7Ts7EnXL4nPiXSE5vJWSfR53VcqDUrQD87CZSpt2RKZcmrYrze8KanjkfyS8XmMCcz4p33NZmfHE4S9oRo3wU2.png

Thank you so much for taking the time to read today's post. Like I mentioned earlier on, if you still face a challenge of installing Android studio or writing your first code, you can comment down below and I'll respond or any other member you see it can be of help.

Have a lovely day and catch you next time on Learn2code. Goodbye ❤️



0
0
0.000
1 comments
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000