Document Details

EnthusiasticShakuhachi

Uploaded by EnthusiasticShakuhachi

Virtual University of Pakistan

Tags

java programming computer science programming languages software development

Summary

This document is a lecture note about Java programming. It covers various aspects of Java, from its design goals to its core language and libraries. It provides a foundational understanding of Java.

Full Transcript

Web Design and Development (CS506) Lecture 1: Java Features This handout is a traditional introduction to any language features. You might not be able to comprehend some of the features fully at this stage but don’t worry, you’ll get to know about these as we mo...

Web Design and Development (CS506) Lecture 1: Java Features This handout is a traditional introduction to any language features. You might not be able to comprehend some of the features fully at this stage but don’t worry, you’ll get to know about these as we move on with the course. 1.1 Design Goals of Java The massive growth of the Internet and the World-Wide Web leads us to a completely new way of looking at development of software that can run on different platforms like Windows, Linux and Solaris etc. 1.1.1 Right Language, Right Time Java came on the scene in 1995 to immediate popularity. Before that, C and C++ dominated the software development o compiled, no robust memory model, no garbage collector causes memory leakages, not great support of built in libraries Java brings together a great set of "programmer efficient" features o Putting more work on the CPU to make things easier for the programmer. 1.1.2 Java - Buzzwords (Vocabulary) From the original Sun Java whitepaper: "Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high-performance, multi- threaded, and dynamic language." Here are some original java buzzwords. 1.1.3 Java -- Language + Libraries Java has two parts. o The core language -- variables, arrays, objects The Java Virtual Machine (JVM) runs the core language The core language is simple enough to run on small devices phones, smart cards, PDAs. o The libraries Java includes a large collection of standard library classes to provide "off the shelf" code. (Useful built-in classes that comes with the language to perform basic tasks) Example of these classes is String, ArrayList, HashMap, StringTokenizer (to break string into substrings), Date... Java programmers are more productive in part because they have access to a large set of standard, well documented library classes. © Copyright Virtual University of Pakistan Page 4 Web Design and Development (CS506) 1.1.4 Simple Very similar C/C++ syntax, operators, etc. The core language is simpler than C++ -- no operator overloading, no pointers, no multiple inheritance The way a java program deals with memory is much simpler than C or C++. 1.1.5 Object-Oriented Java is fundamentally based on the OOP notions of classes and objects. Java uses a formal OOP type system that must be obeyed at compile-time and run-time. This is helpful for larger projects, where the structure helps keep the various parts consistent. Contrast to Perl, which has a more anything-goes feel. 1.1.6 Distributed / Network Oriented Java is network friendly -- both in its portable, threaded nature, and because Common networking operations are built-in to the Java libraries. 1.1.7 Robust / Secure / Safe Java is very robust o Both, vs. unintentional errors and vs. malicious code such as viruses. o Java has slightly worse performance since it does all this checking. (Or put the other way, C can be faster since it doesn't check anything.) The JVM "verifier" checks the code when it is loaded to verify that it has the correct Structure -- that it does not use an uninitialized pointer, or mix int and pointer types. This is one-time "static" analysis -- checking that the code has the correct structure without running it. The JVM also does "dynamic" checking at runtime for certain operations, such as pointer and array access, to make sure they are touching only the memory they should. You will write code that runs into As a result, many common bugs and security problems (e.g. "buffer overflow") are not possible in java. The checks also make it easier to find many common bugs easy, since they are caught by the runtime checker. You will generally never write code that fails the verifier, since your compiler is smart enough to only generate correct code. You will write code that runs into the runtime checks all the time as you debug -- array out of bounds, null pointer. Java also has a runtime Security Manager can check which operations a particular piece of code is allowed to do. As a result, java can run untrusted code in a "sandbox" where, for example, it can draw to the screen but cannot access the local file system. 1.1.8 Portable "Write Once Run Anywhere", and for the most part this works. Not even a recompile is required -- a Java executable can work, without change, on any Java enabled platform. 1.1.9 Support for Web and Enterprise Web Applications Java provides an extensive support for the development of web and enterprise © Copyright Virtual University of Pakistan Page 5 Web Design and Development (CS506) applications Servlets, JSP, Applets, JDBC, RMI, EJBs and JSF etc. are some of the Java technologies that can be used for the above mentioned purposes. 1.1.10 High-performance The first versions of java were pretty slow. Java performance has gotten a lot better with aggressive just-in-time-compiler (JIT) techniques. Java performance is now similar to C -- a little slower in some cases, faster in a few cases. However memory use and startup time are both worse than C. Java performance gets better each year as the JVM gets smarter. This works, because making the JVM smarter does not require any great change to the java language, source code, etc. 1.1.11 Multi-Threaded Java has a notion of concurrency wired right in to the language itself. This works out more cleanly than languages where concurrency is bolted on after the fact. 1.1.12 Dynamic Class and type information is kept around at runtime. This enables runtime loading and inspection of code in a very flexible way. 1.1.13 Java Compiler Structure The source code for each class is in a.java file. Compile each class to produce “.class” file. Sometimes, multiple.class files are packaged together into a.zip or.jar "archive" file. On UNIX or windows, the java compiler is called "javac". To compile all the.java files in a directory use "javac *.java". 1.1.14 Java: Programmer Efficiency Faster Development o Building an application in Java takes about 50% less time than in C or C++. So, Faster time to market o Java is said to be “Programmer Efficient”. OOP o Java is thoroughly OOP language with robust memory system o Memory errors largely disappear because of the safe pointers and garbage collector. The lack of memory errors accounts for much of the increased programmer productivity. Libraries o Code re-uses at last -- String, ArrayList, Date, available and documented in a standard way © Copyright Virtual University of Pakistan Page 6 Web Design and Development (CS506) 1.1.15 Microsoft vs. Java Microsoft hates Java, since a Java program (portable) is not tied to any particular operating system. If Java is popular, then programs written in Java might promote non-Microsoft operating systems. For basically the same reason, all the non- Microsoft vendors think Java is a great idea. Microsoft's C# is very similar to Java, but with some improvements, and some questionable features added in, and it is not portable in the way Java is. Generally it is considered that C# will be successful in the way that Visual Basic is: a nice tool to build Microsoft only software. Microsoft has used its power to try to derail Java somewhat, but Java remains very popular on its merits. 1.1.16 Java Is For Real Java has a lot of hype, but much of it is deserved. Java is very well matched for many modern problem Using more memory and CPU time but less programmer time is an increasingly appealing tradeoff. Robustness and portability can be very useful features A general belief is that Java is going to stay here for the next 10-20 years 1.1.17 References Majority of the material in this handout is taken from the first handout of course cs193j at Stanford. The Java™ Language Environment, White Paper, by James Gosling & Henry McGilton Java’s Sun site: http://java.sun.com Java World : www.javaworld.com © Copyright Virtual University of Pakistan Page 7

Use Quizgecko on...
Browser
Browser