CPSC2800 - Introduction to Operating System Linux Hands-on Series 1 CPSC 2800 Linux Hands-on Lab # 2 Developing Linux Application in Java, C and C++ Project 2-1 Develop a Java test program in NetBeans • If you have not installed Netbeans IDE yet, install it by typing sudo apt-get install netbeans in a terminal window. • Enter root password “123456” for old version of Linux or “12345678” for new version of Linux. • And type Y when it is asked. • If you have not launched NetBeans IDE yet, start it by typing command netbeans in a terminal window. • Click on menu item “File|New Project …” to launch the “New Project” window. Make sure Categories selection chooses “Java”, and Projects selection chooses “Java Application”, as shown below. • Click on the Next button and see the “New Java Application” window. Type “Test” in the “Project Name” text field, as shown below. Make sure that the checkboxes for “Create Main Class” and “Set as Main Project” are checked.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
CPSC2800 - Introduction to Operating System Linux Hands-on Series
1
CPSC 2800 Linux Hands-on Lab # 2 Developing Linux Application in Java, C and C++
Project 2-1 Develop a Java test program in NetBeans
• If you have not installed Netbeans IDE yet, install it by typing sudo apt-get install netbeans in a
terminal window.
• Enter root password “123456” for old version of Linux or “12345678” for new version of Linux.
• And type Y when it is asked.
• If you have not launched NetBeans IDE yet, start it by typing command netbeans in a terminal
window.
• Click on menu item “File|New Project …” to launch the “New Project” window. Make sure
Categories selection chooses “Java”, and Projects selection chooses “Java Application”, as
shown below.
• Click on the Next button and see the “New Java Application” window. Type “Test” in the
“Project Name” text field, as shown below. Make sure that the checkboxes for “Create Main
Class” and “Set as Main Project” are checked.
CPSC2800 - Introduction to Operating System Linux Hands-on Series
2
• Click on the Finish button, and you will see a screen similar to the following one:
CPSC2800 - Introduction to Operating System Linux Hands-on Series
3
• In the body of method main, enter “System.out.println(“Hello”);”, as shown below.
CPSC2800 - Introduction to Operating System Linux Hands-on Series
4
• In the left-upper project pane, right-click on file “Main.java” and choose “Run File” on the
popup menu, as show below:
CPSC2800 - Introduction to Operating System Linux Hands-on Series
5
• The program will be saved to hard disk, compiled into a bytecode file, and executed. The
execution output is displayed under the “Output” tab, as shown below:
CPSC2800 - Introduction to Operating System Linux Hands-on Series
6
• Click on menu item “File|Close Project” to close this project, and use “File|Exit” to shut
down NetBeans IDE.
• Your NetBeans projects are saved under “/home/user/NetBeansProjects”.
Project 2-2
In this project you create and run a simple C program.
To write a simple C program:
1. Use the vi or other editor (such as gedit or nedit) to create and save the file inchines.c
(Remember that the C complier uses the .c extension to identify a file containing C source code).
Enter this code:
/* this program converts 10 feet to inches. */
#include <stdio.h>
int main(){
int inches, feet;
CPSC2800 - Introduction to Operating System Linux Hands-on Series
7
feet = 10;
inches = feet * 12;
printf("There are %d inches in %d feet. \n", inches, feet);