Martes, Oktubre 15, 2013

All About Java

The Java Programming Language

Java, the language, is a high-level object-oriented programming language, influenced in various ways by C, C++, and Smalltalk, with ideas borrowed from other languages as well (see O'Reilly's History of Programming Languages). Its syntax was designed to be familiar to those familiar with C-descended "curly brace" languages, but with arguably stronger OO principles than those found in C++, static typing of objects, and a fairly rigid system of exceptions that require every method in the call stack to either handle exceptions or declare their ability to throw them. Garbage collection is assumed, sparing the developer from having to free memory used by obsolete objects.

One of Java's more controversial aspects--widely accepted at the time of its release but increasingly criticized today--is its incomplete object-orientation. Specifically, Java primitives such as int, char, boolean, etc. are not objects, and require a completely different treatment from the developer: as int is not a class, you cannot subclass and declare new methods on it, cannot pass it to a method that expects a generic Object, and so on. The inclusion of primitives increases Java performance, but at the arguable expense of code clarity, as anyone who's had to work with the so-called "wrapper classes" (Integer, Character, and Boolean) will attest. Java 5.0 introduces an "autoboxing" scheme to eliminate many uses of the wrapper classes, but in some ways it obscures what is really going on.

Philosophically, Java is a "fail early" language. Because of its syntactic restrictions, many programming failures are simply not possible in Java. With no direct access to pointers, pointer-arithmetic errors are non-existent. Using an object as a different type than what it was originally declared to be requires an explicit cast, which gives the compiler an opportunity to reject illogical programming, like calling a String method on an Image.

Many Java enterprise frameworks require the use of configuration files or deployment descriptors, typically written in XML, to specify functionality: what class handles a certain HTTP request, the order of steps to execute in a rule engine, etc. In effect, they have to go beyond the language to implement their functionality. Critics point out that this has the perverse effect of not only escaping Java's compiler checks, but also that a developer can no longer determine how a program will operate just by looking at its source code. Java 5.0 adds annotations to the language, which allows the tagging of methods, fields, and classes with values that can then be inspected and operated on at runtime, usually through reflection. Many programmers like annotations because they simplify tasks that might otherwise be addressed by deployment descriptors or other means. But again, they can make it difficult to understand Java code, as the presence or absence of an annotation may affect how the code is executed, in ways that are in no way obvious from the annotation.

Despite these criticisms, Java is generally understood to be the most popular general-purpose computing language in use today. It is a widely used standard in enterprise programming, and in 2005, it replaced C++ as the language most used by projects on SourceForge. What it has going for it is immense: free tools (on multiple platforms: Linux, Windows, Solaris, and Mac can all compile and execute Java apps), a vast base of knowledge, and a large pool of readily available developers.

The Java language hits a specific point in the tradeoff between developer productivity and code performance: CPU cycles keep getting cheaper, developers largely don't, so it is perhaps inevitable to accept another layer of abstraction between the developer and the execution of CPU opcodes, if it allows the developer to create better software faster. In fact, critics of Java's productivity, such as Bruce Tate in Beyond Java, may simply be observing this trend continuing past Java to a new sweet spot that further trades performance for developer productivity.

Java Security Exploit

A term that refers to any number of security exploits in Oracle's Java software, which has a long history of being vulnerable to security flaws. The most recent Java Security Exploit appeared in early 2013, and affected all versions of Java up to Java 7 Update 10.

This zero-day security vulnerability, referenced as CVE-2013-0422 by the CVE, carried a payload of malware that could result in identity theft as well as rendering the host machine an unauthorized botnet that could then be used in denial-of-service (DoS) attacks against other machines.

Oracle periodically releases software patches developed to address Java security exploits, and it released one as Java 7 Update 11 two days after the most recent vulnerability was discovered. Only days after that patch debuted, a new zero-day Java security exploit was publicized and marketed by crimeware sites for $5,000.




Top Ten Things Every Java Programmer Should Know

These are in no particular order, but these are things that all Java programmers should probably know.

Who Invented Java, and when?

James Gosling, at Sun Labs, around 1992; the group was building a set-top box and started by "cleaning up" C++ and wound up with a new language and runtime.

What does Java stand for?

Java is not an acronym (not even Just Another Vague Acronym :-)). The language was first named Oak, after the tree outside James' window. The lawyers found another language called Oak so, legend has it, the gang went out to the local cafe to discuss names and wound up naming it after the beverage Java (which is in turn named after the island of Java). Possible confirmation of this theory.

What is the JLS?

JLS is The Java Language Specification. Every developer should buy or download (free) this specification and read it, a bit at a time.

How do changes get into Java?

JCP (Java Community Process).

Why is there no printf-like function in Java?

Actually there are! This was fixed in Java 5; see Java Cookbook (2nd Edition) Chapter 9. Java 5 (J2SE 1.5) includes printf (and scanf), String.format(), and lots more.

What is the GOF book?

The Gang Of Four book is entitled Design Patterns, by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. This is a very good book. You should read it. Not when you're just learning Java, but when you've let it sink in for about six months.

What other Java book do I need?

Most of the O'Reilly Java books. Effective Java, by Joshua Bloch Java Developer's Almanac My Java Cookbook (see below)

What is the Java Cookbook?

That's my own book of Java recipes (for the programming language, not the coffee, but some bookstores still wind up listing it under Cooking).

What other Java sites do I need to know about?

java.sun.com, Sun's main technology site
java.net, a collaborative site (run by Sun)
java.com, an advocacy/news site (run by Sun)
developer.java.sun.com, Sun's main developer site
www.javalobby.org, independent advocacy group
www.javaworld.com, Java news
www.theserverside.com, Java Review
http://www.darwinsys.com/java/, my own Java site

What else do I need to know?

Everything! But nobody can know everything about Java - the subject is now too vast. Imagine somebody saying that they know everything about every single Microsoft product and technology. If someone like that calls me, I'm always out.




Features of Java Programming, New Features of Java Language, Advanced Java Features with Examples

Features of Java Language

Java have so many features which are as -

Java is Simple
There are various features that makes the java as a simple language. because Java is easy to learn and developed by taking the best features from other languages mainly like C and C++. It is very easy to learn Java who have knowledge of object oriented programming concepts. Java provides the error free development environment for programmer because it provide automatic memory management by development environment and eliminate pointers.

Java is Platform Independent- Java provides the facility to "Write once -Run any where"(Known as plateform independent). Not even a single language is idle to this feature but java is more closer to this feature. Java Provide the facility of cross-plateform programs by compiling in intermediate code known as bytecode. this bytecode can be interpreted on any system which have Java Virtual Machine(JVM).

Java is Object-oriented- The object oriented language must support the characterstics of the OOPs. and Java is a fully object oriented language . it supports all the characterstics needed to be object oriented. In the Java every thing is treated as objects to which methods are applied.As the languages like Objective C, C++ fulfills the above four characteristics yet they are not fully object oriented languages because they are structured as well as object oriented languages. But in case of java, it is a fully Object Oriented language because object is at the outer most level of data structure in java. No stand alone methods, constants, and variables are there in java. Everything in java is object even the primitive datatypes can also be converted into object by using the wrapper class.

Java is Distributed- The widely used protocols like HTTP and FTP are developed in java. Internet programmers can call functions on these protocols and can get access the files from any remote machine on the internet rather than writing codes on their local system. Java is Secure- Java does not use memory pointers explicitly. All the programs in java are run under an area known as the sand box. Security manager determines the accessibility options of a class like reading and writing a file to the local disk. Java uses the public key encryption system to allow the java applications to transmit over the internet in the secure encrypted form. The bytecode Verifier checks the classes after loading.

No memory pointers
Programs runs inside the virtual machine sandbox.
Array index limit checking
bytecode verifier - checks classes after loading

class loader - confines objects to unique namespaces. Prevents loading a hacked "java.lang.SecurityManager" class, for example.

security manager - determines what resources a class can access such as reading and writing to the local disk.

Java is compiled and interpreted- We all know that in Java code is compiled to bytecodes that are interpreted by Java virtual machines (JVM) . This provides portability to any machine for which a virtual machine has been written. The interpreter program reads the source code and translates it on the fly into computations.The two steps of compilation and interpretation allow for extensive code checking and improved security.

Java is Robust- Java has the strong memory allocation and automatic garbage collection mechanism. It carries out type checking at both compile and runtime making sure that every data structure has been clearly defined and typed. compiler checks the program for any error and interpreter checks any run time error that every data structure is clearly defined and typed. Java manages the memory automatically by using an automatic garbage collector. all the above features makes Java language robust.

Java is Portable- The feature of java "write once -run any where" make java portable. Many type of computers and operating systems are used for programs By porting an interpreter for the Java Virtual Machine to any computer hardware/operating system, one is assured that all code compiled for it will run on that system. This forms the basis for Java's portability.

Java Compared with Other Languages

Java is a relatively new language, but it draws on many years of programming experience with other languages in its choice of features. It is worth taking a moment to compare Java at a high level with some other popular languages today, both for the benefit of those of you with other programming experience and for the newcomers who need to put things in context. We do not expect you to have a knowledge of any particular programming language in this book and when we refer to other languages by way of comparison we hope that the comments are selfexplanatory.

At least three pillars are necessary to support a universal programming language today: portability, speed, and security. Figure 1-2 shows how Java compares to a couple of other languages.

You may have heard that Java is a lot like C or C++, but that's really not true, except at a superficial level. When you first look at Java code, you'll see that the basic syntax looks like C or C++. But that's where the similarities end. Java is by no means a direct descendant of C or a next-generation C++. If you compare language features, you'll see that Java actually has more in common with highly dynamic languages such as Smalltalk and Lisp. In fact, Java's implementation is about as far from native C as you can imagine.

The surface-level similarities to these languages are worth noting, however. Java borrows heavily from C and C++ syntax, so you'll see terse language constructs, including an abundance of curly braces and semicolons. Java subscribes to the C philosophy that a good language should be compact; in other words, it should be sufficiently small and regular so a programmer can hold all the language's capabilities in his or her head at once. Just as C is extensible with libraries, packages of Java classes can be added to the core language components to extend its vocabulary.

C has been successful because it provides a reasonably feature-packed programming environment, with high performance and an acceptable degree of portability. Java also tries to balance functionality, speed, and portability, but it does so in a very different way. C trades functionality for portability; Java initially traded speed for portability. Java also addresses security issues while C doesn't.

In the early days before JIT and adaptive compilation, Java was slower than statically compiled languages and there was a constant refrain from detractors that it would never catch up. But as we described in the previous section, Java's performance is now comparable to C or C++ for equivalent tasks and those criticisms have generally fallen quiet. In fact, in 2004, ID Software's open source Quake2 video game engine was ported to Java. If Java is fast enough for firstperson- shooter video games, it's certainly fast enough for business applications.

Scripting languages, such as Perl, Python, and Ruby, are very popular, and for good reason. There's no reason a scripting language can't be suitable for safe, networked applications. But most scripting languages are not designed for serious, large-scale programming. The attraction to scripting languages is that they are dynamic; they are powerful tools for rapid development. Some scripting languages such as Perl also provide powerful tools for text-processing tasks that more general-purpose languages find unwieldy. Scripting languages are also highly portable, albeit at the source-code level.

Not to be confused with Java, JavaScript is an object-based scripting language originally developed by Netscape for the web browser. It serves as a glue and an "in the document" language for dynamic, interactive HTML-based applications. JavaScript takes its name from its intended integration with Java applets and some similarity in syntax, but the comparison really ends there. While there have been applications of JavaScript outside of the browser, it has never really caught on as a general scripting language. For more information on JavaScript, check out JavaScript: The Definitive Guide by David Flanagan (O'Reilly).

The problem with scripting languages is that they are rather casual about program structure and data typing. Most scripting languages (with a hesitant exception for Python and later versions of Perl) are not object-oriented. They also have vastly simplified type systems and generally don't provide for sophisticated scoping of variables and functions. These characteristics make them unsuitable for building large, modular applications. Speed is another problem with scripting languages; the high-level, fully interpreted nature of these languages often makes them quite slow.

Advocates of individual scripting languages would take issue with some of these generalizations and no doubt they'd be right in some casesscripting languages are growing up. But the fundamental tradeoff is undeniable: scripting languages were born as loose, less structured alternatives to systems programming languages and are generally not as suitable for large or complex projects for a variety of reasons, at least not today.

Java offers some of the essential advantages of a scripting language (it is highly dynamic), along with the added benefits of a lower-level language. Java 1.4 added a powerful Regular Expression API that competes with Perl for working with text and Java 5.0 has introduced new language features that streamline coding, such as "foreach"-style iteration over collections, variable argument lists, autoboxing and unboxing of primitives, and static imports of methods. Incremental development with object-oriented components, combined with Java's simplicity, make it possible to develop applications rapidly and change them easily. Studies have found that development in Java is faster than in C or C++, strictly based on language features.[*] Java also comes with a large base of standard core classes for common tasks such as building GUIs and handling network communications. But along with these features, Java has the scalability and software-engineering advantages of more static languages. It provides a safe structure on which to build higher-level frameworks (and even other languages).

As we've already said, Java is similar in design to languages such as Smalltalk and Lisp. However, these languages are currently used mostly as research vehicles rather than for development of large-scale systems. One reason is that these languages never developed a standard portable binding to operating-system services, such as the C standard library or the Java core classes. Smalltalk is compiled to an interpreted bytecode format, and it can be dynamically compiled to native code on the fly, just like Java. But Java improves on the design by using a bytecode verifier to ensure the correctness of compiled Java code. This verifier gives Java a performance advantage over Smalltalk because Java code requires fewer runtime checks. Java's bytecode verifier also helps with security issues, something that Smalltalk doesn't address. Smalltalk is a mature language, though, and Java's designers took lessons from many of its features.

Throughout the rest of this chapter, we'll present a bird's-eye view of the Java language. We'll explain what's new and what's not-so-new about Java and why.




Walang komento:

Mag-post ng isang Komento