In this course we will use Eclipse as the Integrated Development Environment. Eclipse has been installed on the Computer Science Department machines in the Undergrad Labs used as the First Year Teaching Environment (MC 8, 10, 230, 235).
In Integrated Development Environments such as Eclipse, Netbeans, VisualStudio, etc. we need to create a project in order to run a program. Most programs consist of multiple files. A project contains all the information about the program, such as a list of program files (source files, class files) and IDE settings. You will create a new project in Eclipse for every program that you wish to run.
Create a folder called (for example) Eclipse or CS1027b to hold all your Eclipse projects for this course. This folder will contain the project files themselves. The Java source files may be in this folder also (as in Exercises 1 and 3), or in some other (external) folder (as in Exercise 2).
main in your class. When executing a java program the java
interpreter will start execution at method main; therefore, every
java program must have a main method.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
In this exercise, you will create a new project to run the sample Social Networking application whose files are posted on the sample code section of the CS1027 Course web page. (We will not concern ourselves with what this code does at present; you will merely use the files to practice this part of the Lab.)
MyFriends.java (the
little red "X" at the bottom left corner of the icon for MyFriends.java),
since the provided code does not yet have the getNumFriends() method defined in SocialNetwork.java.
Double click on the MyFriends.java icon. To fix this error, comment out the offending line of code in MyFriends.java (add
"//" at the beginning of the line marked with the little red "X"; this indicates that everything after the "//" is a comment)main method which displays your name and email
address on the screen.
main method.
import java.util.Scanner;
before the line
   public class Calculator {
This will tell java to include the library called java.util.Scanner to your program.
This library contains java code that your program can use, among other things, to read user input from the
computer keyboard.
main method do the following:
x and y and one
character variable c. The syntax for declaring an integer variable is
   int variable_name;
and for a character variable
   char variable_name;
c so it stores the character '+'.
Scanner input = new Scanner(System.in);
Now, to read an integer from the computer keyboard and to store it in variable x you can use this
code:
   x = input.nextInt();
To read a character from the computer keyboard and store it in variable c you can use
   c = input.next().charAt(0);
while (c == '+' || c == '-') {
  }
{    } of the while loop add code to perform the following steps:
x.
y.
c.
if (c == '+') System.out.println("Result = "+(x+y));
  else if (c == '-') System.out.println("Result = "+(x-y));