Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R#1-121 address: Group Addresses Post message:

Similar presentations


Presentation on theme: "Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R#1-121 address: Group Addresses Post message:"— Presentation transcript:

1 Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R#1-121 E-mail address: uzma_a2001@yahoo.com Group Email Addresses Post message: cs202-lab@yahoogroups.com Subscribe: cs202-lab-subscribe@yahoogroups.comcs202-lab-subscribe@yahoogroups.com  I will use this group to communicate and all the Slides will be posted on the group after each lesson CPCS-202 LAB -1

2 Prepared by Uzma Hashmi Learning Outcomes of Lab-1 1.Installation of jdk1.7 and IDE ECLIPSE 2.Understanding the IDE 3.Writing,Running and Debugging the code 4.Studying the structure of a Java Program 5.Adding Comments 6.White Spaces 7.Identifiers

3 Prepared by Uzma Hashmi In this semester we will learn JAVA The IDE (integrated development environment)we will use will be Eclipse The compiler is jdk(java development kit) Now we will see how can we install both in Part A and Part B See next slides for the installation steps

4 Prepared by Uzma Hashmi First you need to install jdk for java language compilation To do so we'll access this web link http://www.oracle.com/technetwork/java/javase /downloads/index.html

5 Prepared by Uzma Hashmi Step 1: http://www.oracle.com/technetwork/java/javase/downloads/ index.html JRE (Java Runtime Environment) on your system to run Java applications and applets. To develop Java applications and applets, you need the JDK (Java Development Kit), which includes the JRE

6 Prepared by Uzma Hashmi Quick Tip Click Start, then click on Run or Start Search. Type msinfo32.exe and then press Enter key. In “System Information”, review the value for the System Type item: For 32-bit editions of Windows, the value of the System Type item is x86-based PC.System Type For 64-bit editions of Windows, the value of the System Type item is x64-based PC.

7 Prepared by Uzma Hashmi 7

8

9 http://www.eclipse.org/downloads/

10 Prepared by Uzma Hashmi Extract the files and there you get the files listed below

11 Prepared by Uzma Hashmi Using Eclipse The system will prompt you for a workspace. The workspace is the place there you store your Java projects (more on workspaces later). Select a suitable (empty) directory and press Ok.

12 Prepared by Uzma Hashmi Click here

13 Prepared by Uzma Hashmi Creating Java Project Select from the menu File -> New-> Java project.

14 Prepared by Uzma Hashmi

15

16 Creating Packages inside the work-space

17 Prepared by Uzma Hashmi

18

19

20

21 Another way of Running your code RunDebug

22 Prepared by Uzma Hashmi Use of Refactor Once you have created your file,you can change the name of the file using the refactor option

23 Prepared by Uzma Hashmi

24

25

26 Error description in Problems

27 Prepared by Uzma Hashmi

28 Structure of the program In the Java programming language: – A program is made up of one or more classes – A class contains one or more methods – A method contains program statements These terms will be explored in detail throughout the course A Java application always contains a method called main, A Java application name must be the same as the class name.

29 Prepared by Uzma Hashmi Java Program Structure public class MyProgram {}{} // comments about the class class header must be the same As the java program name MyProgram.java class body Comments can be placed almost anywhere

30 Prepared by Uzma Hashmi 1-30 Java Program Structure public class MyProgram {}{} // comments about the class public static void main (String[] args) {}{} // comments about the method method header method body

31 Prepared by Uzma Hashmi Program.java //******************************************************************** // Program.java Author: Lewis/Loftus // // Demonstrates the basic structure of a Java application. //******************************************************************** public class Program { //----------------------------------------------------------------- // Prints a presidential quote. //----------------------------------------------------------------- public static void main (String[] args) { System.out.println ( "A quote by Abraham Lincoln:” ); //System is a predefined class that provides access to the system. //out is the output stream that is connected to the console{e.g. Monitor}. //println() - Displays the String which is passed to it. System.out.println ( "Whatever you are, be a good one.” ); }

32 Prepared by Uzma Hashmi 1-32 Comments Comments in a program are called inline documentation They should be included to explain the purpose of the program and describe processing steps They do not affect how a program works Java comments can take three forms: // this comment runs to the end of the line /* this comment runs to the terminating symbol, even across line breaks */ /** this is a javadoc comment */

33 Prepared by Uzma Hashmi 1-33 Identifiers Identifiers are the words a programmer uses in a program An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign Identifiers cannot begin with a digit Java is case sensitive - Total, total, and TOTAL are different identifiers By convention, programmers use different case styles for different types of identifiers, such as – title case for class names - Lincoln – upper case for constants – MAXIMUM – Combination(Compound Word)opt. - Camel Notation – E.g Class Name :MyProject

34 Prepared by Uzma Hashmi Identifiers cont. Often we use special identifiers called reserved words that already have a predefined meaning in the language ( such as void ) A reserved word cannot be used in any other way

35 Prepared by Uzma Hashmi 1-35 Reserved Words The Java reserved words: abstract assert boolean break byte case catch char class const continue default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while

36 Prepared by Uzma Hashmi 1-36 White Space Spaces, blank lines, and tabs are called white space White space is used to separate words and symbols in a program Extra white space is ignored A valid Java program can be formatted many ways Programs should be formatted to enhance readability, using consistent indentation

37 Prepared by Uzma Hashmi //************************************************** // Poem.java // // Prints a classic poem on four lines. //************************************************** public class Poem { public static void main(String[] args) { System.out.println("Roses are red"); System.out.println("Violets are blue"); System.out.println("Sugar is sweet"); System.out.println("And so are you!"); }

38 Prepared by Uzma Hashmi Example for white spaces //******************************************************************** // Lincoln3.java Author: Lewis/Loftus // Demonstrates another valid program that is poorly formatted. //******************************************************************** public class Lincoln3 { public static void main ( String [] args ) { System.out.println ( "A quote by Abraham Lincoln:" ) ; System.out.println ( "Whatever you are, be a good one." ) ; }

39 Prepared by Uzma Hashmi Lab Assignment


Download ppt "Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R#1-121 address: Group Addresses Post message:"

Similar presentations


Ads by Google