1 / 57

Beginning Java and/or J# and/or C#

Beginning Java and/or J# and/or C#. Dr. Burns. About this course, Instructor. A first course in computer languages Which language?? Your instructor is familiar with Visual Basic Java, C# and C++. How to reach me??. Office hrs: 11-11:45 T Th Office phone: 742-1547

laken
Download Presentation

Beginning Java and/or J# and/or C#

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Beginning Java and/or J# and/or C# Dr. Burns

  2. About this course, Instructor • A first course in computer languages • Which language?? • Your instructor is familiar with Visual Basic Java, C# and C++

  3. How to reach me?? • Office hrs: 11-11:45 T Th • Office phone: 742-1547 • Email: jburns.@ba.ttu.edu • Website: http://burns.ba.ttu.edu

  4. Pedagogical Requirements • 2 exams, each worth 20% • 1 project worth 20% • Homework worth 20% • Presentations worth 20% • Students will be asked to present material in class five times during the semester

  5. Some 3-hour classes are organized as… • 1.5 hours of lecture by me (80-90 min) • 1.5 hr lecture by one of you • .75 hr by one student (40 min) • .75 hr by another student (40 min)

  6. A bit of History • Java was developed at Sun Microsystems by a programmer named James Gosling who originally had in mind a language to control robots • June 1991 to 1995 was the development period • It is platform-independent and will run on any operating system or computer

  7. More Java history • Development goals were to create a language with a C/C++ like syntax, but with WORA (Write Once, Run Anywhere) • The language was also made much simpler than C++ • No pointer variables, no pointer arrays, no destructors, etc.

  8. Java Standard • The Java standard is a de facto standard (not one that is controlled by ANSI or ISO) that is controlled by the Java Community Process

  9. Java Language Goals • It should be object-oriented • It should allow the same program to be executed on multiple operating systems and microprocessors using different machine languages • It should contain built-in support for use of computer networks • It should be executable from remote sources • It should be easy to use (Wikipedia)

  10. J# Programming language • A transitional language to assist Java programmers to transition to Microsoft’s .NET platform • J# can work with Java bytecode as well as source, so it can be used to transition applications that use 3rd-party libraries • It was developed by the Hyderabad-based Microsoft India Development Center at HITEC City in India

  11. Fundamental differences between J# and Java • Both use the same general syntax • There are non-Java conventions in J# to support the .NET environment • J# does not compile Java language source code to Java bytecode and does not support Java applet development or the ability to host applets directly in a web browser

  12. Future of J# • J# is not considered a language on a par with C# or VB.NET and does not have the same level of support, samples or updates as the other languages do • Nevertheless, J# is a usable .NET language and has access to all the CLR features

  13. What is CLR? • CLR stands for Common Language Runtime and is the virtual machine component of Microsoft’s .NET platform. It is Msft’s implementation of the Common Language Infrastructure (CLI) standard. • Developers using the CLR write code in a language such as C# or VB.Net.

  14. History of J# • J# is Microsoft’s version of Java • J# will run only on Windows machines • Uses different methods names than Java • Within Visual Studio, it can be mixed and matched with Visual C++, Visual Basic, Visual C#, ASP.net, etc.

  15. Which language works best for your needs? • Let me suggest Java or Visual C#

  16. Reserved Words/Objects in C# or Java • Only about 48 of them, compared to over 200 in Visual Basic • Is Object-oriented • But doesn’t support pointer variables, nor is the programmer allowed to destroy objects, unlike C++

  17. abstract assert boolean break byte case catch char const continue default do double else enum extends final Reserved Words

  18. finally float for goto if implements import instanceof int interface long native new package private protected public return More reserved words

  19. short static strictfp super switch synchronized this throw throws transient try void volatile while Still more reserved words

  20. Notice…. • None of the reserved words begins with an uppercase character (both C# and Java have case sensitive identifiers) • The reserved words shown in RED are also C# reserved words • C# has 75 reserved words (listed on page 31 of your text)

  21. Identifiers • These are words you choose for… • Class libraries (Java) • Classes • Namespaces (C#) • Variables • Methods • They cannot be reserved words

  22. More on Identifiers • Class names should start with uppercase • Method and variable names should start with lower case • No spaces • You can only use letters (lower and uppercase), digits and the underscore character

  23. Some bad class names • An employee Space char is bad • Inventory Item Space char is bad • Class a reserved word • 2009Budget can’t begin with digit • Phone# # is illegal

  24. Operators • Supports only the basic operators • ! {the logical NOT} • * / % {multiplication, division, modulus} • + - {addition, subtraction} • > < >= <= {Relational} • == != {Equality} • && {Logical AND} • || {logical OR}

  25. Operators in C++ that are not supported • ++ -- • Many others

  26. Object Technology • Inheritance -- gives rise to REUSE • Encapsulation • Information hiding • Polymorphism • Contains attributes (data and methods) • Objects are called classes • No support for procedural programming—which is the direct opposite to object-oriented programming

  27. Class—an object • Encapsulates both data and behaviors • Behavior is delineated with a method—a collection of code • Consider the class Sedan(…) • Contained within it are constants like • Wheels = 4, chassis = 1, engine = 1, doors = 4 • Color = RED

  28. The class Sedan() has methods that describe its behaviors • Accelerates(…) • Slows_down(…) • Consumes_gas(…) • Creates_pollution(….) • Each of these is a method, a collection of code that acts as a group to produce the behavior

  29. Method • A self-contained block of program code, similar to a procedure or subroutine

  30. Procedural vs. Object-oriented programming • Procedural programming • What I did using Fortran as a software engineer working for the Boeing Company in the 1970’s • Just long lists of code • Object-oriented programming—organizes code into objects—allows for reuse

  31. The generic structure for an Object • First, a list of all the possible header declarations—to support polymorphism • Second, a list of all the data types and their initializations • Third, a list of all the methods, coupled with their code declarations

  32. Objects and their instantiations • OBJECT INTSTANTIATION • truck fordF150 • automobile chevyMalibu • animal dog

  33. Header declarations—the same in Java and C# • Java: • public static void main(String[] args) • C#: • static void main(String[] args) • public static void main(String[] args) • Notice—no semicolon after header dec

  34. What is main(String[] args)? • Is it a class? • Is it an instance of a class? • Is it a method? • Is it a function?

  35. What do the reserved words mean? • public—the method is accessible to everyone, not just other methods inside the class • static—the method stays alive and functional while the program is running • void—the method does not return a value through its name

  36. Instantiations • We use the keyword ‘new’ to create an instantiation of an object: • New automobile Toyota • Here Toyota is an instance of the class automobile

  37. Inheritance • The ability of a class to inherit the data and methods of another previously defined class. • my1997ToyotaCorolla() extends Sedan()_ • Inherits all of the data and methods of Sedan()—reuses them—they don’t have to be redefined

  38. Polymorphism • Literally means ‘many forms’ • Allows methods to be used differently in different contexts • Run() can be a footrace, an execution of a computer program, or a business process • It is correctly understood in context • The method eat() will be different depending on what kind of animal is eating

  39. Code for a Class Public class First { public static void main(String[] args) { System.out.println(“First Java app”); } }

  40. The Membership Operator • Is simply the . • Examine…………… System.out.println(“First Java app”); • We see that println() is a method within a class out which is a class within a class called System • Unfortunately, J# and C# do not use these names

  41. What is (“First Java app”)? • “First Java app” is a literal string of characters – placed within double quotes • This string is an argument of the method System.out.println() • Methods are always followed by () parentheses • What is placed within those parentheses are called arguments

  42. Some TLA’s—Three-letter Acronyms • IDE – Integrated Development Environment • JVM – Java Virtual Machine • JRE – Java Runtime Environment • SDK—Software Development Kit • API—Application Programming Interface • CLR—Common Language Runtime (Microsoft) is part of .NET • WPF—Windows Presentation Foundation

  43. Integrated Development Environments • IDE – Integrated Development Environment—what Visual Studio and Eclipse provide—usually consisting of editor, parser, interpreter • But sometimes the IDE is capable of compiling and linking—creating a stand alone executable– ending with .exe

  44. What is the sequence leading to execution? • In any language, it is • Enter code in the editor– editor checks for errors -- result is a text file with the extension of .java or .J# • Compile code into machine language – result is a binary file with the extension .bin • Link code to other compiled objects to create a stand alone executable – result is a binary file with the extension .exe

  45. There are many variations on this sequence …. • Enter code – check for errors -- IDE saves the result as a text file. • IDE does a ‘quick’ interpret and execute without creating a stand alone executable

  46. What is the difference between interpretation and execution? • No difference as far as the output of the program is concerned. • With interpretation, a line of source code is interpreted and executed without its being compiled, linked and executed as a stand alone module • This is very slow compared to stand alone execution

  47. Microsoft .NET Common Language Runtime diagram

  48. What about the sale of commercial products? • Do you want these products interpreted or executed from a stand alone executable?

  49. Java Compilations • Java compilers typically produce bytecode rather than binary (machine language) • This makes them platform independent • JVM’s and JRE’s then interpret the byte codes upon execution • Because of this, Java programs run slower than native executables

  50. Freeware • A Java IDE (Java SE 6) that is free can be found at http://java.sun.com • A Java JRE that is free can be found at http://java.sun.com • A downloadable Java Tutorial is available at http://java.sun.com/docs/books/tutorial/

More Related