360 likes | 506 Views
.NET and Visual Studio. IS 135 Business Programming. .NET Framework. The most recent MS announcement An attempt to enter the “enterprise” arena Good programmer tools Excellent access to universal resources Will allow many languages Large Base Library for all languages. .NET Continued.
E N D
.NET and Visual Studio IS 135 Business Programming
.NET Framework • The most recent MS announcement • An attempt to enter the “enterprise” arena • Good programmer tools • Excellent access to universal resources • Will allow many languages • Large Base Library for all languages
.NET Continued • Only on Windows at the moment • However, the Intermediate Language (IL) that results from compilation is possibly machine independent • This portable executable (PE) is part of the familiar .EXE file
.NET Continued • The idea is to create programs in .NET • Compile them in the “common language runtime” (CLR)… more later • The code is translated into native code • Any language that is compliant will run
.NET Continued • MS used existing concepts and improved on them to create .NET • It has: robust CLR • Extensive class library • Internet based inter process communication • Multiple languages
.NET Framework Web Forms WIN forms Web Services Data Access XML Classes Base Classes .NET Framework Operating System
Class Library • Saves you writing common routines • Contains over 2500 classes • Classes contain commonly used routines like printing, display etc • Available to all languages under .NET through CLR
CLR- Simplify App Dev • 2500 classes, programmer can reuse • Organizations can create their own reusable code • Memory management simple with auto garbage collection
CLR - Performance • High level languages always worse than assembler • JIT compiles method into native code first • Next time it executes directly in native code • Allocation of memory is next available storage • Deallocation done by garbage collector
Why CLR? • Without it, compiler has to create safety • But there are many compilers, some 3rd party • All languages do not have safety features • Some compiler implementations are slow
CLR Design • Interpreter or compiler • Interpreter does work at runtime, slow • Modern systems, have front-end compiler, back-end runtime
CLR – Intermediate Language • Front end does all checking, creates IL • JIT can create reusable native code • Better runtime performance
CLR and JVM • Java Virtual Machine widely used • Very similar to CLR • Most important differences: • CLR supports many languages • Java implemented on many platforms
Types • Other OOs call them a class • Abstraction of data and behavior together • Fields, methods, properties, events
Common Type System • Provides wide range of modern operations • Shared by CLR, compilers, tools • Framework for cross-language operation • Integer 16 on some machines, 32 on others • Limited code reuse between languages • Each language has some types • CTS establishes rules for cross-language calls
Managed Data, Garbage Collect • CLR reserves a contiguous block for initialized data – Managed Heap • Fast allocation from it • Older languages had to search for available space • CLR performs deallocation as part of garbage collection • When memory is low, frees up unreferenced memory
Getting started … • From Program select Visual Studio .NET • Be sure to select NEW PROJECT • Then Visual C# Project and • From the right hand window choose CONSOLE APPLICATION • In the bottom window change the NAME to your assignment number
OUR style Rules After USING statement, there are /// (comments) Keep // but replace line 1 with YOUR NAME After // in line 2 replace text with the assignment # After // in line 3 replace text with DUE date Always insert a comment after } Ex: } // end namespace Now look at the example…
Helpful Hints • No semicolons when: • Next character is a { • The current character is a } • The line of text is over 1 line long • For the next few weeks, every program will have a Main() method.
Example • Please watch carefully… • First we will enter VS, C# • Then we will modify the skeleton program • We will try to make it run • First compile (check syntax etc) Build solution • Correct errors • Run program Debug, Start w/o debugging • Check results • Print results (next slide)
How to print program, results From Visual studio, print program Run the program (Debug/Start) With the output (black) screen visible: press print screen on top of keyboard on top left of black screen right click icon press select all again press copy Start WORD, paste copied material there
Assignment 0Due Date: NEXT CLASS • Write a program to display 3 lines of text. • Line 1 your name • Line 2 your grad year • Line 3 your major Display instruction in C#: Console.WriteLine(“XXX”); (where XXX is the text to be displayed)
How to get started • Turn off the monitor • get paper and pen • What results are expected? • What data are you given? • Is that enough to produce output? • In English, list variables if needed • List steps needed to display results ex: display my name • Write C# instructions • Turn on Monitor, enter program
Assignment 0aDue Date: Next Class • Write a program to allow user input for name, reason for taking course, and your major.
Develop logic • Turn off the monitor • get paper and pen • What output is expected? • What data are you given? • Is that enough to produce output? • In English, list variables if needed • List steps needed to meet user request ex: allow user input for name display my name … • Write C# instructions • Turn on Monitor, enter program
More on Input/Output Console.Readline(); Console.Write (or WriteLine); Example: string Name; // declare variable Name=Console.ReadLine(); Console.WriteLine(“My name is ” + Name); or Console.WriteLine(“My name is {0}”, Name);
string name; string street; string city; Console.Write(“Please enter your Name ”); name = Console.ReadLine(); Console.Write(“Please enter your Street ”); street = Console.ReadLine(); What would go here? city = Console.ReadLine(); Console.WriteLine(“my bio {0} {1}, {2}”, name, street, city); Output: my bio smith 123 street, ffld More on Input/Output
Program Style • We listed some // comments earlier • We also should have 4 sections in every program //declare section (where you assign variables etc) //input section (accept user input) //computations (where you do calculations) //display results • IN THAT ORDER
using System; namespace WTprog1 { // wt // program 1 // due date: 1/31/05 class Class1 { static void Main(string[] args) { // declare section // input section // computation section // display section {// end Main {//end class {// end namespace