java aco101: introduction to computer science. the history of java started out as a research project...

35
Java ACO101: Introduction to Computer Science

Upload: felicity-holland

Post on 31-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Java

ACO101: Introduction to Computer Science

The History of Java

• Started out as a research project at Sun Microsystems in 1991

• Code named “Green”• Based on C and C++• Originally called “Oak” because its creator

James Gosling had an oak tree outside his office window at Sun.

History of Java – part 2

• They had to change the name from “Oak” to something else because it was discovered that there was already a language called “Oak” .

• A group of people at Sun went for coffee one day and someone suggested “Java” and it stuck.

• Between 1991 and 1993 the project faltered because Sun had anticipated that the smart consumer device market would grow faster than it did.

Java History – part 3

• When the internet boomed in 1993 the project got a new life because people saw the potential to create dynamic content for the web.

• “Java” was officially announced in May 1995.

Religious discussion

• Java vs. C#• James Gosling and Bill Joy (one of the

founders of Sun Microsystems) called C# an "imitation" of Java;

• Gosling (originator of Java) further claimed that "[C# is] sort of Java with reliability, productivity and security deleted."

More religious debate

• Klaus Kreft and Angelika Langer (authors of a C++ streams book) stated in a blog post that "Java and C# are almost identical programming languages. Boring repetition that lacks innovation."

• Anders Hejlsberg (lead the C# team) has argued that C# is "not a Java clone" and is "much closer to C++" in its design.

Why do you care?

• Because you will have to decide where you are in the debate and that will inform your career path.

• http://www.sun.com/lawsuit/• http://www.theregister.co.uk/2010/08/13/

oracle_sues_google/• http://regmedia.co.uk/2010/08/13/

oracle_complaint_against_google.pdf

Technology is constantly moving forward

• And so you will move forward with it. • I will not tell you what to think or how to be; I

will only give you the information to decide for yourself.

Knowing Both

• They are so similar that– If you know Java then you pretty much know C#

and knowing both will double your job opportunities.• http://www.indeed.com/

• Programming is one of the professions that the more you know the more you earn.

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

Side bar: bytecode and CIL instructions

• A Java programmer does not need to be aware of or understand Java bytecode at all.

• However, "Understanding bytecode and what bytecode is likely to be generated by a Java compiler helps the Java programmer in the same way that knowledge of assembler helps the C or C++ programmer.“ – Peter Haggar IBM

• The same is true for CIL instructions and C#

We are not going that deep.

• If you are interested – here are some links; but this is Intro and you are not required to understand bytecode, CIL instructions or machine code on a deeper level.– http://www.ibm.com/developerworks/ibm/

library/it-haggar_bytecode/– http://en.csharp-online.net/CIL_Instruction_Set

Lets check to see if the JDK is installed

• Go to Start > Run > type “cmd” in the box to launch a command prompt– Type in the window (where the cursor is)

java –version

• C:\Program Files\Java– Is there a 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

To DIY you will need

• The Java SE Development Kit 6 (JDK 6) – http://www.oracle.com/technetwork/java/javase/

downloads/index.html– Read the installation instructions

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

– Click on the Download JDK button• I registered (you don’t have to)• Pick your platform and click continue• Click on the link provided to download the exe• Save file, double click and run

Follow the installation wizard

Next

next

Close browsers

finish

This is optional

Hello world

• We havta do the tradition…. It would be just wrong to not have your first program be “Hello World”

• Open notepad (on a mac you can use simple text) and type this code…..

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

Save as….

• myfirstjavaprog.java

Bring up a command promptStart > Run > cmd

Change the directory to the location of javac

Now send the location of your .java file to the compiler

Now go check to see if you have a .class file (you should)

Let’s run it – go to the location of the class (current working directory) and pass the name of the

class to the Java runtime

Success!

Homework

• Is posted on the class portal