140 likes | 289 Views
Last Time. Introduction to course. Course web site Syllabus Textbook. Stuff…. Remember to click on “Refresh” when viewing the course’s main index page – it does change fairly often! TA E-mails and who is doing which lab has been added to the course web site.
E N D
Last Time • Introduction to course. • Course web site • Syllabus • Textbook CISC121 - Prof. McLeod
Stuff… • Remember to click on “Refresh” when viewing the course’s main index page – it does change fairly often! • TA E-mails and who is doing which lab has been added to the course web site. • Information on tools for MAC users has been added to the resources page. • Check your WebCT login soon, and let me know if it does not work. CISC121 - Prof. McLeod
Today • Demo’s of development environments: • One time only use of JDK in DOS - just to show you what is going on “under the hood”. • BlueJ • eclipse • Note that you can use whatever development tool you wish. We officially only support eclipse. For assignments hand in your *.java files only. • Simple program structure. CISC121 - Prof. McLeod
What to Look For: • No matter the development tool: *.java file *.class file javac.exe text file compiler byte code file 01101010101101010 *.class file java.exe byte code interpreter byte code file CISC121 - Prof. McLeod
Byte Code File? • Compact. • Platform independent. • Cannot be read or edited. • When linked off a web site, it is an “applet”! • What parts of the previous slide are platform dependent? • A JVM or “Java Virtual Machine” is built into a web browser. Is it platform independent? What is it equivalent to? CISC121 - Prof. McLeod
How Java Stays Multiplatform • In order for a development tool to use the java language, they must use the JDK from Sun “under the hood”. • Enforced by the “Java Consortium”. • Once upon a time, Microsoft made their own JDK, so now they have “J++” or “J#” – not “Java” anymore! CISC121 - Prof. McLeod
Java Development Tools • Must invoke javac.exe and java.exe. • They can grab the results from these programs before it gets routed to DOS. • Advanced tools like eclipse also have pre-compilers built in to them. • Checks to see if your program will satisfy javac.exe before you even run it. • If the pre-compiler is not satisfied then it will not run your program. • You can change the “sensitivity” level for some pre-compilers. • Usually more informative and immediate error messages. CISC121 - Prof. McLeod
Tools Demo • The tool will automatically run both javac and java when you choose “Run”. • Now: a short visit to DOS. • Where are the javac.exe and java.exe programs anyways? CISC121 - Prof. McLeod
A Simple Java Program public class HelloProg { public static void main (String [] args) { System.out.println ("Hello there!"); } // end main method } // end HelloProg class • The “//” denotes an in-line comment. Everything else on the line is ignored by the compiler. CISC121 - Prof. McLeod
A Simple Java Program – Cont. • The compiler ignores any “white space” in your source code – returns, line feeds, tabs, extra spaces and comments. • Here’s our little program without white space (imagine this all on one line): public class HelloProg{public static void main(String[] args){System.out.println("Hello there!");}} • This does still run, but it is hard to read… CISC121 - Prof. McLeod
A Simple Java Program – Cont. • A Class is an “Object” in Java. All Objects in Java are Classes… • A Class is a container – it holds attributes (data) and methods (code that does something). • Our class is called “HelloProg”. Our class must be defined in a file called “HelloProg.java”. • The code “public class HelloProg” is used to declare the class. • The contents of the class are contained in a set of curly brackets: “{ }”. CISC121 - Prof. McLeod
A Simple Java Program – Cont. • Our little class does not contain any attributes (data) and only has one method called “main”. • The main method is declared using the code: public static void main (String [] args) • As before the code is contained within: “{ }”. CISC121 - Prof. McLeod
The main Method • For the runtime engine to run a program, it must know where to start. • By design, the starting point is always the execution of the main method. • The engine expects the main method to be declared exactly as shown – the only thing you can change is the name of the String array, called “args” in this little program. CISC121 - Prof. McLeod
A Simple Java Program – Cont. • Our main method contains only one line of code: System.out.println ("Hello there!"); • It prints out “Hello there!” to the screen (or “console”). We’ll talk more about I/O (“Input/Output”) later (or see Lab 1). • Note the “;” at the end of the line of code. Since the Java compiler ignores white space, it must use these characters to determine when a line finishes. CISC121 - Prof. McLeod