JAVA Solutions

JAVA Solutions

Share

Supplier of education requirements

24/07/2018

Good evening programmers

08/01/2018

Java Netbeans available

24/09/2017

We are calling for exchange of ideas on JAVA programming. Especially use of Netbeans.

29/10/2016

Example: A Simple Java Program
The code shown in Listing 1 is a simple Java program called WelcomeMsg.java that asks the user to enter a name. After entering the name, when the user presses Enter, a welcome message appears, including the name the user typed. For example, if the user enters the name "Kelly," the message, "Welcome Kelly!" appears on the screen.

Listing 1 Code in WelcomeMsg.java.
import java.io.* ; #1

class WelcomeMsg {
public static void main(String args[])
{
InputStreamReader istream = new InputStreamReader(System.in) ; #2
BufferedReader bufRead = new BufferedReader(istream) ; #3
try { #4
System.out.println("Enter your name: "); #5
String name = bufRead.readLine(); #6
System.out.println("Welcome "+ name + " !"); #7
}
catch (IOException err) { #8
System.out.println("Error reading line");
}
}
}
In WelcomeMsg.java, statement #1 imports the packages required for input/output operations. Statement #2 creates a reader called istream. The reader will read from the standard input stream (System.in); that is, from the keyboard. The entered text is stored in the form of Unicode characters. Statement #3 uses the istream reader to convert the data into string form. Statement #4 defines a try..catch block to check for any errors that might have occurred while the reader entered the text. Statements #5 and #6 ask the user to enter a name that is then assigned to the string name. The entered name is then displayed on the screen by statement #8.

When the program is run, it asks the user to enter a name. After the user types a name and presses Enter, the welcome message is displayed with the entered name, as shown in Figure 1.


Figure 1 Output of the Java program

Creating an Android Project Similar to the Java Program
Now let's create the same application in Android. Assuming that the Java Development Kit (JDK) is installed on your machine, download Android Studio. Then follow these steps:

Double-click the downloaded executable file to install Android Studio.
After the installation completes successfully, launch Android Studio. The first screen that opens is a welcome screen, displaying icons such as New Project, Import Project, Open Project, and so on. Click the New Project icon to create a new Android project.
In the New Project dialog, enter information for the new project, as shown in Figure 2.
In the Application Name box, enter the name of the Android project. Let's name the application WelcomeMsg. The Module Name entry is assigned automatically; by default, it's the same as the application name. To make it a unique identifier, the Package Name assigned is com.yourname.welcomemsg. The location to store the Android project is specified in Project Location box.
Select API 8: Android 2.2 (Froyo) from the Minimum Required SDK drop-down list, to indicate that the application requires at least API level 8 to run. Select API 17: Android 4.2 (Jelly Bean) as the Target Platform, as we expect this to be the version commonly used by your target audience. Select API 17: Android 4.2 (Jelly Bean) as the platform to compile the project. The default Theme assigned to the project is Holo Light with Dark Action Bar.
The Create Custom Launcher Icon checkbox is checked by default. This feature allows you to configure the launcher icon for the application. Because we want to create a blank activity, click the Create Activity checkbox and then click the Next button.


Figure 2 Creating a new Android project

The next dialog is Configure Launcher Icon, which is used for configuring the icon for the application. Because we want to use the default icon for our application, keep the default options selected in the dialog box, and click Next.
The next dialog prompts us to create an activity. Because we want to create a blank activity, select the BlankActivity option from the list and then click Next.
The next dialog asks us to enter information about the newly created activity. Name the activity WelcomeMsgActivity. The layout file is assigned the default name activity_main.xml. Keeping that default name for the layout file, click Finish to create the Android project.
Android Studio will automatically create several files and folders for our new Android project (see Figure 3). To customize our new project, we just need to work with two files:

activity_main.xml. This file is shown at right in Figure 3, in the node WelcomeMsg > src > main > res > layout. It's an XML file in which we'll define the controls (TextView, EditText, Button, etc.) for our Android app's graphical user interface. Through this file, the user interacts with the Android project.
WelcomeMsgActivity.java. This file is in the node WelcomeMsg > src > main > java > com.yourname.welcomemsg. This Java file loads the controls defined in the layout file activity_main.xml, listens for various events, and runs the required code if any of those events occur.


Figure 3 Project Explorer windows showing files and folders of our new Android project in collapsed mode (left) and expanded mode (right)

10/10/2016

Classes in JAVA Programming to open soon

24/08/2016

A number of open source softwares under development. Soon we shall have a publication.

Want your school to be the top-listed School/college in Mungwi?

Click here to claim your Sponsored Listing.

Location

Category

Telephone

Website

Address


Mungwi Town Centre
Mungwi
50100