2 getting to know your programing environment

40
Getting to know your Programming Environment

Upload: dm-technologies

Post on 24-May-2015

733 views

Category:

Technology


2 download

DESCRIPTION

Getting to know your programing environment

TRANSCRIPT

Page 1: 2 Getting To Know Your Programing Environment

Getting to know yourProgramming Environment

Page 2: 2 Getting To Know Your Programing Environment

ObjectivesAt the end of the lesson, the student should be able to:● Create a Java program using text editor and console in theLinux, Solaris, Windows, Mac OS, or any other OSenvironment● Differentiate between syntax-errors and runtime errors● Create a Java program using NetBeans

Page 3: 2 Getting To Know Your Programing Environment

Definitions● Console– This is where you type in commands– Examples are Terminal (Linux), MSDOS Command Prompt(Windows)

Page 4: 2 Getting To Know Your Programing Environment

Definitions● Text Editor– Examples: Notepad, Wordpad, Vi

Page 5: 2 Getting To Know Your Programing Environment

Definitions● Integrated Development Environment or IDE– a programming environment integrated into a software applicationthat provides a GUI builder, a text or code editor, a compiler and/orinterpreter and a debugger.

Page 6: 2 Getting To Know Your Programing Environment

My First Java Program1 public class Hello {23 /**4 * My first Java program5 */6 public static void main( String[] args ){78 //prints the string “Hello world” on screen9 System.out.println(“Hello world”);1011 }12 }

Page 7: 2 Getting To Know Your Programing Environment

Using Text Editor andConsole● Step 1: Start the Text Editor– To start the Text Editor in Linux, click on Menu-> Accessories-> TextEditor● Step 2: Open Terminal– To open Terminal in Linux, click on Menu-> System Tools->Terminal● Step 3: Write your the source code of your Java program inthe Text Editor

Page 8: 2 Getting To Know Your Programing Environment

Using Text Editor andConsole● Step 4: Save your Java Program– Filename: Hello.java– Folder name: myjavaprograms– To open the Save dialog box, click on the File menu found on themenubar and then click on Save.– If the folder myjavaprograms does not exist yet, create the folder

Page 9: 2 Getting To Know Your Programing Environment

Using Text Editor andConsole● Step 5: Compiling your program– Go to the Terminal window– Go to the folder myjavaprograms where you saved the program– To compile a Java program, we type in the command:javac [filename]– So in this case, type in:javac Hello.javaDuring compilation, javac adds a file to the disk called[filename].class, or in this case, Hello.class, which is theactual bytecode.

Page 10: 2 Getting To Know Your Programing Environment

Using Text Editor andConsole● Step 6: Running the Program– To run your Java program, type in the command:java [filename without the extension]– so in the case of our example, type in:java Hello– You can see on the screen after running the program:"Hello world!"

Page 11: 2 Getting To Know Your Programing Environment

Using NetBeans IDE

Page 12: 2 Getting To Know Your Programing Environment

Using NetBeans IDE

Page 13: 2 Getting To Know Your Programing Environment

Using NetBeans IDE

Page 14: 2 Getting To Know Your Programing Environment

Using NetBeans IDE

Page 15: 2 Getting To Know Your Programing Environment

Using NetBeans IDE

Page 16: 2 Getting To Know Your Programing Environment

Using NetBeans IDE

Page 17: 2 Getting To Know Your Programing Environment

Using NetBeans IDE

Page 18: 2 Getting To Know Your Programing Environment

1.What is the name of the package here?

2.Can we create program without package?

3.What is the name of class?

4.What is the difference between class and Class?

5. we are writing main() method to execute program. why not other name like m1()?

6.Can we write more than one main() method ?7.Why main() method is public?8.Why main() method is static?9.Can we write main() method with different argument?

Quiz :

Page 19: 2 Getting To Know Your Programing Environment

6.Can we write more than one main() method in a class ?

7.Why main() method is public?

8.Why main() method is static?

9.Can we write main() method with different argument?

Quiz :

Page 20: 2 Getting To Know Your Programing Environment

1.What is the name of the package here?

2.Can we create program without package?

3.What is the name of class?

4.What is the difference between class and Class?

5. we are writing main() method to execute program. why not other name like m1()?

6.Can we write more than one main() method ?7.Why main() method is public?8.Why main() method is static?9.Can we write main() method with different argument?

Quiz :

Page 21: 2 Getting To Know Your Programing Environment

1.What is the name of the package here?

2.Can we create program without package?

3.What is the name of class?

4.What is the difference between class and Class?

5. we are writing main() method to execute program. why not other name like m1()?

6.Can we write more than one main() method ?7.Why main() method is public?8.Why main() method is static?9.Can we write main() method with different argument?

Quiz :

Page 22: 2 Getting To Know Your Programing Environment

Errors : Syntax Errors● Syntax Errors Syntax– errors are usually typing errors● Common Syntax Errors:– misspelled a command in Java– forgot to write a semi-colon at the end of a statement

Page 23: 2 Getting To Know Your Programing Environment

Example: Syntax Error

Page 24: 2 Getting To Know Your Programing Environment

Example: Syntax Error

Page 25: 2 Getting To Know Your Programing Environment

About main() method

Calling non-static method from main() :Syntax Error

Page 26: 2 Getting To Know Your Programing Environment

About main() method

Calling static method :Correct Syntax

Page 27: 2 Getting To Know Your Programing Environment

About main() method

In different flavor :Type 1

Page 28: 2 Getting To Know Your Programing Environment

About main() method

In different flavor :Type 2

Page 29: 2 Getting To Know Your Programing Environment

About main() method

In different flavor :Type 3

Page 30: 2 Getting To Know Your Programing Environment

About main() method

Type 1:Runtime error

Page 31: 2 Getting To Know Your Programing Environment

About main() method

Type 1a:Runtime error

Page 32: 2 Getting To Know Your Programing Environment

About main() method

Type 1b:Runtime error

Page 33: 2 Getting To Know Your Programing Environment

About main() method

Type 2:Runtime error

Page 34: 2 Getting To Know Your Programing Environment

About main() method

Type 2a:Runtime error

Page 35: 2 Getting To Know Your Programing Environment

About main() method

Type 3:Runtime error (without static)

Page 36: 2 Getting To Know Your Programing Environment

About main() method

Type 4:Runtime error (without “public” i.e “default” modifier )

Page 37: 2 Getting To Know Your Programing Environment

About main() method

Type 4a:Runtime error (should use “public” modifier)

Page 38: 2 Getting To Know Your Programing Environment

About main() method

Type 5:Runtime error (return type should be “void”)

Page 39: 2 Getting To Know Your Programing Environment

Errors: Runtime Errors● Run-time Errors– errors that will not display until you run or execute your program– Even programs that compile successfully may display wronganswers if the programmer has not thought through the logicalprocesses and structures of the program.– Examples:● You want your program to print 100 strings of “Hello world”, but it only printed 99.● Your program gets an input from the

Page 40: 2 Getting To Know Your Programing Environment

Summary● My First Java Program● Using a Text Editor and Console– Write program– Compile program– Run program● Errors– Syntax Errors– Runtime Errors