java and c# [this is a bonus – it is not a required lesson] aco101: introduction to computer...

Post on 13-Jan-2016

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Java and C#[this is a bonus – it is not a required lesson]

ACO101: Introduction to Computer Science

Runtime environments

Java • Java Runtime Environment

– Includes the JVM and Common Code Libraries

• JVM = Java Virtual Machine• The JRE was originally

designed to support interpreted execution with final compilation as an option.

• The Java compiler produces Java bytecode

C#• Common Language Runtime• The CLR is designed to

execute fully compiled code.

• The C# compiler produces Common Intermediate Language instructions.

Program execution

Java• bytecode is loaded by the

Java runtime and either interpreted directly or compiled to machine instructions and then executed

C#• the runtime loads Common

Intermediate Language code and compiles to machine instructions on the target architecture

Installation Check

JDK• Go to Start > Run > type

“cmd” in the box to launch a command prompt– Type in the window (where

the cursor is) java –version

.NET Framework Software Development Kit (SDK)

Location

Java• C:\Program Files\Java

– In folder named jdk1.6.0_21

• click into the bin in that folder– C:\Program Files\Java\

jdk1.6.0_21\bin– javac.exe is the compiler

C#• C:\Windows\

Microsoft.NET\Framework• You will see several

different versions– Inside a version folder you

will see a csc.exe– This is the compiler program

CSC.EXE

• The command line C# compiler is a program named CSC.EXE.

• This program makes use of a dynamic link library named CSCOMP.DLL that contains the actual compiler code.

To DIY you will need

The Java SE Development Kit 6 (JDK 6)

• http://www.oracle.com/technetwork/java/javase/downloads/index.html

• Download and follow the installation wizard

.NET Framework Software Development Kit (SDK)

• http://www.microsoft.com/downloads/details.aspx?FamilyID=fe6f2099-b7b4-4f47-a244-c96d69c35dec&displaylang=en

• Download and follow the installation wizard

• Or install Visual Studio 2008 and/or Visual Studio 2010

Hello world

Javapackage hello;

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

C#namespace Hello {

public class HelloWorld { public static void Main(string[] args)

{ System.Console.WriteLine("Hello, World!");

System.Console.ReadLine(); }

}}

Save as….

Java• myfirstjavaprog.java

C#• myfirstcharpprog.cs

Bring up a command prompt

For java - Start > Run > cmd For c#

Change the directory to the location of

Java – the compilerC:\Program Files\Java\jdk1.6.0_21\bin C# -- the file to be compiled

(it will different on your computer than on mine)

Now send the your file to the compiler (these have both been run in the screenshot)

javac [location and name of .java file] csc /target:exe [name of file]

Now go check to see if you have a

java C#• .exe file• .class file

Let’s run it –

Java: go to the location of the class (current working directory) and pass the name of the class to the Java runtime

C# • Double click on the exe

Success!

Java C#

Hungry for more?

Java• http://

download.oracle.com/javase/tutorial/java/package/packages.html

• http://en.wikipedia.org/wiki/Java_package

C#• http://

msdn.microsoft.com/en-us/library/ms379563%28VS.80%29.aspx#csharpcompiler_topic4

• http://www.csharphelp.com/2006/02/namespaces-in-c/

top related