Concordia University Department of Electrical & Computer Engineering Introduction to Telecommunication Networks ELEC 463 Mohammad Altahat Lab 1: Introduction to Java Programming on Eclipse 1. Objectives: 1- Introduction to Java Programming. 2- Introduction to Graphical Interfaces. 2. Lab Experiment: In this lab, we are going to learn the programming basics for Java. Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. It runs on different platforms including Windows, MacOS, and Linux. Java is object oriented language, where everything is an object. It is simple and platform independent which means it is not compiled into platform specific machine. It is compiled into independent byte code that is interpreted by the Java Virtual Machine on any platform it is being run on. The tools needed for this lab are: - Windows XP/7 or higher, or Linux operating system. - Java JDK installed. - Eclipse development environment. 2.1.First Java Program (Hello World) This simple code prints the sentence “Hello World”. public class helloworld { public static void main(String[] args) { System.out.println("Hello World"); } }
16
Embed
Concordia University Department of Electrical & …m_altaha/teaching...Concordia University Department of Electrical & Computer Engineering Introduction to Telecommunication Networks
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
Concordia University
Department of Electrical & Computer Engineering
Introduction to Telecommunication Networks
ELEC 463
Mohammad Altahat
Lab 1: Introduction to Java Programming on Eclipse
1. Objectives:
1- Introduction to Java Programming.
2- Introduction to Graphical Interfaces.
2. Lab Experiment:
In this lab, we are going to learn the programming basics for Java. Java is a high-level
programming language originally developed by Sun Microsystems and released in 1995. It runs
on different platforms including Windows, MacOS, and Linux.
Java is object oriented language, where everything is an object. It is simple and platform
independent which means it is not compiled into platform specific machine. It is compiled into
independent byte code that is interpreted by the Java Virtual Machine on any platform it is being
run on.
The tools needed for this lab are:
- Windows XP/7 or higher, or Linux operating system.
- Java JDK installed.
- Eclipse development environment.
2.1.First Java Program (Hello World)
This simple code prints the sentence “Hello World”. public class helloworld {
public static void main(String[] args) {
System.out.println("Hello World"); } }
Using Eclipse to write, compile, and run java programs
Eclipse is an integrated development environment (IDE) used in computer programming, and
is the most widely used Java IDE. It contains a base workspace and an extensible plug-in
system for customizing the environment. Eclipse is written mostly in Java and its primary use
is for developing Java applications, but it may also be used to develop applications in other
programming languages.
To implement the Hello World program in Eclipse you need to follow these steps:
a. Open Eclipse, then select from the menu: File → New → Java Project.
b. Enter "helloworld" as the project name. Keep rest of the settings as shown in the following
screenshot and then click Finish. Eclipse IDE will generate the java project.
c. Right click on “src” folder and select from context menu New → Package.
d. Write “elec463.helloworld” in the 'Name' field and click "Finish" button.
e. Right click on “elec463.helloworld” package and select from context menu New → Class.
f. Write “HelloWorld” in the “Name” field and select the check-box for “public static void
main(String[] args)” to automatically write the main function.
g. Click “Finish” button. Eclipse will generate a java class and open the java editor as
shown below.
h. Type the code “System.out.println("Hello World");” inside the main function.
i. To run the code: Right click on “HelloWorld.java” and select from context menu “Run As”
→ “Java Application”.
j. The output will be shown in the console window of Eclipse.
2.2.Programming Basics Tutorial
1. Decision Making:
a. if statement:
if (Boolean_expression) {
// Statements will execute if the Boolean expression is true
}
Example:
b. if else statement:
if (Boolean_expression) {
// Executes when the Boolean expression is true
} else {
// Executes when the Boolean expression is false
}
c. switch statement:
switch (expression) {
case value :
// Statements
break; // optional
case value :
// Statements
break; // optional
// You can have any number of case statements.
default : // Optional
// Statements
}
2. Loops
a. while loop
while (Boolean_expression) {
// Statements
}
b. for loop
for (initialization; Boolean_expression; update) {