Top Banner
Lecture 2: An Introduction to J# and .NET
22

Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

Dec 24, 2015

Download

Documents

Norma FlOwers
Welcome message from author
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
Page 1: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

Lecture 2:

An Introduction to J# and .NET

Page 2: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

2MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-2

Objectives

“Microsoft .NET is based on the .NET Framework, which consists of two major components: a run-time execution engine and an extensive software library. The Framework supports a wide range of programming languages, including J# which brings Java to .NET... ”

• Modern program execution• J#• Visual Studio .NET

Page 3: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

3MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-3

HardwareHardware

Program execution in the 21st century

• Idea:– modern software executes using a run-time environment– why? portable and safe execution…

Operating SystemOperating System

Run-time EnvironmentRun-time Environment

Your ApplicationYour Application

Page 4: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

4MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-4

Program execution in .NET

• Based on Common Language Runtime (CLR) + .NET Framework Class Library (FxCL)

• run-time environment + large software library

HardwareHardware

Operating SystemOperating System

Common Language Runtime (CLR)Common Language Runtime (CLR)

Your ApplicationYour Application .NET Framework.NET FrameworkClass Library (FxCL)Class Library (FxCL)

Page 5: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

5MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-5

So what is .NET?

• A technology for developing & executing software…– platform independent (XP, Pocket PC, Linux (Mono), BSD )– language independent

(28 languages listed at http://www.gotdotnet.com/team/lang//)

HardwareHardware

Operating SystemOperating System

Common Language Runtime (CLR)Common Language Runtime (CLR)

Your ApplicationYour Application .NET Framework.NET FrameworkClass Library (FxCL)Class Library (FxCL)

J#J# C#C# C++C++ VBVB ……

Page 6: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

6MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-6

What exactly is J#?

• "J-Sharp" is Java on the .NET platform– J# allows you to program using the Java language yet take

advantage of the Microsoft .NET platform

• What is Java?

– Java language syntax + Java class library• What is J#?

– Java language syntax (Java 1.4) + Java class library + .NET class library

– current Java language (i.e. v1.5, a.k.a. Java 5)

– partial support for Java class library (most of v1.1, some of v1.2)

– Additional library for Swing

Page 7: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

7MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-7

Example in J#

• The infamous "hello world!" program– written in pure Java…

public class HelloApp{ public static void main(String[] args) { System.out.println("Hello world!"); }}

public class HelloApp{ public static void main(String[] args) { System.out.println("Hello world!"); }}

Page 8: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

8MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-8

How to edit, compile, run?

• Visual Studio .NET• Visual Studio is Microsoft's IDE

– "Integrated Development Environment"

• One environment for all .NET programming:– editing– compiling– running– debugging

Page 9: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

9MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-9

Step 1. Select new project…

Page 10: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

10MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-10

Step 2. Create project…

• Select application language, then template

Page 11: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

11MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-11

Step 3. Implement…

• Code the program in coding window– use "Solution Explorer" window for navigating program files

codingwindow

solutionexplorer

Page 12: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

12MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-12

Step 4. Run!

• Just press F5 and off we go!– or use Debug menu, Start…– or click VCR-like "Play" button on the toolbar…

• Go ahead and try it — what happens?

Page 13: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

13MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-13

The "console" flash

• By default, Visual Studio does the following:– opens console window– runs program– closes window

– so all you see is a flash!

Page 14: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

14MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-14

Solution

• Keep console window open until user is done…

package HelloApp;

public class HelloApp{ public static void main(String[] args) throws Exception { System.out.println("Hello world!");

// keep console window open... System.out.println(); System.out.print("Press ENTER to exit..."); System.in.read(); }//main}//class

package HelloApp;

public class HelloApp{ public static void main(String[] args) throws Exception { System.out.println("Hello world!");

// keep console window open... System.out.println(); System.out.print("Press ENTER to exit..."); System.in.read(); }//main}//class

Page 15: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

15MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-15

Very helpful IDE features…

• IntelliSense• Overloading• Tight integration of editor & compiler

– to name just a few…

Page 16: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

16MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-16

IntelliSense!

• IntelliSense is a fantastic advance– context-sensitive programming aid– reduces programming errors– encourages experimentation and exploration

// keep console window open… System.o // keep console window open… System.o

Page 17: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

17MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-17

Overloading

• J# allows multiple methods with the same name– We know this as overloading

– methods must differ in their parameter lists– VS depicts as a scrollable list…

// keep console window open… System.out.println( // keep console window open… System.out.println(

Page 18: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

18MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-18

Editor & compiler integration

• Errors are highlighted in the code like spelling mistakes:

Page 19: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

19MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-19

Working with Visual Studio

• Modes of programming:– "design": coding– "run": program is actively running– "break": program is paused (more on this later)

• How to know which mode you're in?

Page 20: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

20MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-20

Visual Studio files

• Visual Studio produces lots of files

– bin folder contains .EXE, program input files– obj folder contains temporary files

– solution (.sln) is main file for working with VS

– project (.vjsproj) tracks source files, settings

– Visual J# (.jsl) denotes source code files

Page 21: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

21MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-21

Re-opening a project

• To re-open a project and continue working…– double-click on the SOLUTION (.sln) file

or– startup Visual Studio and open .sln file

Page 22: Lecture 2: An Introduction to J# and.NET. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 2-2 Objectives “Microsoft.NET is based on the.NET.

22MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 2-22

Summary

• Modern program execution:– based on virtual machines and large class libraries– in Java, known as JVM and JCL– in .NET, known as CLR and FxCL

• J# is Java on the .NET platform• VS is a modern, sophisticated, powerful IDE