JAVA TECH

Java is a computer programming language that is synchronized, class-based, object-oriented, and purposely designed to have as few implementation dependencies as possible. It is intended to let application developers “write once, run anywhere” (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java applications are typically compiled to bytecode (class file) that can run on any Java virtual machine (JVM) regardless of computer architecture.

 

Java is, as of 2012, one of the most popular programming languages in use, particularly for client-server web applications, with a reported 9 million developers. Java was originally developed by James Gosling at Sun Microsystems(which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems’ Java platform. The language derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them.

The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1991 and first released in 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java (bytecode compiler), GNU Classpath (standard libraries), and IcedTea-Web (browser plugin for applets).

 

Major release versions of Java, along with their release dates:

  • JDK 1.0 (January 21, 1996)
  • JDK 1.1 (February 19, 1997)
  • J2SE 1.2 (December 8, 1998)
  • J2SE 1.3 (May 8, 2000)
  • J2SE 1.4 (February 6, 2002)
  • J2SE 5.0 (September 30, 2004)
  • Java SE 6 (December 11, 2006)
  • Java SE 7 (July 28, 2011)
  • Java EE 7 (October 27, 2013)

 

The syntax of Java is largely derived from C++. Unlike C++, which combines the syntax for structured, generic, and object-oriented programming, Java was built almost exclusively as an object-oriented language. All code is written inside a class, and everything is an object, with the exception of the primitive data types (i.e. integers, floating-point numbers, boolean values, and characters), which are not classes for performance reasons.

Unlike C++, Java does not support operator overloading or multiple inheritance for classes. This simplifies the language and aids in preventing potential errors and anti-pattern design.

Java uses similar commenting methods to C++. There are three different styles of comments: a single line style marked with two slashes (//), a multiple line style opened with /* and closed with */, and the Javadoc commenting style opened with /** and closed with */. The Javadoc style of commenting allows the user to run the Javadoc executable to compile documentation for the program.

// This is an example of a single line comment using two slashes

/* This is an example of a multiple line comment using the slash and asterisk.
 This type of comment can be used to hold a lot of information or deactivate
 code, but it is very important to remember to close the comment. */

/**
 * This is an example of a Javadoc comment; Javadoc can compile documentation
 * from this text.
 */

/** Finally, an example of a method written in Java, wrapped in a class. */
package fibsandlies;
import java.util.HashMap;

public class FibCalculator extends Fibonacci implements Calculator {
    private static HashMap<Integer, Integer> memoized = new HashMap<Integer, Integer>();
    static {
        memoized.put(1, 1);
        memoized.put(2, 1);
    }

    /** Given a non-negative number FIBINDEX, returns
     *  the Nth Fibonacci number, where N equals FIBINDEX.
     *  @param fibIndex The index of the Fibonacci number
     *  @return The Fibonacci number itself
     */
    @Override
    public static int fibonacci(int fibIndex) {
        if (memoized.containsKey(fibIndex)) {
            return memoized.get(fibIndex);
        } else {
            int answer = fibonacci(fibIndex - 1) + fibonacci(fibIndex - 2);
            memoized.put(fibIndex, answer);
            return answer;
        }
    }
}

Another example:

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}

Yet another one:

// OddEven.java
import javax.swing.JOptionPane;

public class OddEven {

    private int userInput; // a whole number("int" means integer)

    /**
     * This is the constructor method. It gets called when an object of the OddEven type
     * is being created.
     */
    public OddEven() {
        /*
         * In most Java programs constructors can initialize objects with default values, or create
         * other objects that this object might use to perform its functions. In some Java programs, the
         * constructor may simply be an empty function if nothing needs to be initialized prior to the
         * functioning of the object. In this program's case, an empty constructor would suffice.
         * A constructor must exist; however, if the user doesn't put one in then the compiler
         * will create an empty one.
         */
    }

    /**
     * This is the main method. It gets called when this class is run through a Java interpreter.
     * @param args command line arguments (unused)
     */
    public static void main(final String[] args) {
       /*
        * This line of code creates a new instance of this class called "number" (also known as an
        * Object) and initializes it by calling the constructor. The next line of code calls
        * the "showDialog()" method, which brings up a prompt to ask you for a number.
        */
       OddEven number = new OddEven();
       number.showDialog();
    }

    public void showDialog() {
        /*
         * "try" makes sure nothing goes wrong. If something does,
         * the interpreter skips to "catch" to see what it should do.
         */
        try {
            /*
             * The code below brings up a JOptionPane, which is a dialog box
             * The String returned by the "showInputDialog()" method is converted into
             * an integer, making the program treat it as a number instead of a word.
             * After that, this method calls a second method, calculate() that will
             * display either "Even" or "Odd."
             */
            userInput = Integer.parseInt(JOptionPane.showInputDialog("Please enter a number."));
            calculate();
        } catch (final NumberFormatException e) {
            /*
             * Getting in the catch block means that there was a problem with the format of
             * the number. Probably some letters were typed in instead of a number.
             */
            System.err.println("ERROR: Invalid input. Please type in a numerical value.");
        }
    }

    /**
     * When this gets called, it sends a message to the interpreter.
     * The interpreter usually shows it on the command prompt (For Windows users)
     * or the terminal (For *nix users).(Assuming it's open)
     */
    private void calculate() {
        if ((userInput % 2) == 0) {
            JOptionPane.showMessageDialog(null, "Even");
        } else {
            JOptionPane.showMessageDialog(null, "Odd");
        }
    }
}

 

  • The import statement imports the JOptionPane class from the javax.swing package.

 

  • The OddEven class declares a single private field of type int named userInput. Every instance of the OddEven class has its own copy of the userInput field. The private declaration means that no other class can access (read or write) the userInput field.
  • OddEven() is a public constructor. Constructors have the same name as the enclosing class they are declared in, and unlike a method, have no return type. A constructor is used to initialize an object that is a newly created instance of the class.

 

  • The calculate() method is declared without the static keyword. This means that the method is invoked using a specific instance of the OddEven class. (The reference used to invoke the method is passed as an undeclared parameter of type OddEven named this.) The method tests the expression userInput % 2 == 0 using the if keyword to see if the remainder of dividing the userInput field belonging to the instance of the class by two is zero. If this expression is true, then it prints Even; if this expression is false it prints Odd. (The calculatemethod can be equivalently accessed as this.calculate and the userInput field can be equivalently accessed as this.userInput, which both explicitly use the undeclared thisparameter.)

 

  • OddEven number = new OddEven(); declares a local object reference variable in the main method named number. This variable can hold a reference to an object of type OddEven. The declaration initializes number by first creating an instance of the OddEven class, using the new keyword and the OddEven() constructor, and then assigning this instance to the variable.

 

  • The statement number.showDialog(); calls the calculate method. The instance of OddEven object referenced by the number local variable is used to invoke the method and passed as the undeclared this parameter to the calculate method.

 

  • userInput = Integer.parseInt(JOptionPane.showInputDialog(“Please Enter A Number”)); is a statement that converts the type of String to the primitive data type intby using a utility function in the primitive wrapper class Integer.

Swing Demo:

// Hello.java (Java SE 5)
import javax.swing.*;

public class Hello extends JFrame {
    public Hello() {
        super("hello");
        super.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        super.add(new JLabel("Hello, world!"));
        super.pack();
        super.setVisible(true);
    }

    public static void main(final String[] args) {
        new Hello();
    }
}

 

 

Sun has defined and supports four editions of Java targeting different application environments and segmented many of its APIs so that they belong to one of the platforms. The platforms are:

  • Java Card for smartcards.
  • Java Platform, Micro Edition (Java ME) — targeting environments with limited resources.
  • Java Platform, Standard Edition (Java SE) — targeting workstation environments.
  • Java Platform, Enterprise Edition (Java EE) — targeting large distributed enterprise or Internet environments.

The classes in the Java APIs are organized into separate groups called packages. Each package contains a set of related interfaces, classes and exceptions. Refer to the separate platforms for a description of the packages available.

The set of APIs is controlled by Sun Microsystems in cooperation with others through the Java Community Process program. Companies or individuals participating in this process can influence the design and development of the APIs. This process has been a subject of controversy.

Sun also provided an edition called PersonalJava that has been superseded by later, standards-based Java ME configuration-profile pairings.

 

13 Comments to JAVA TECH

  1. Gora says:

    I’m more than happy to find this website. I want to to thank you for ones time just for this fantastic read!!
    I definitely enjoyed every part of it and I have you bookmarked to look at
    new information in your web site.

  2. justin says:

    ” after receiving a strange letter in the mail that claimed I had “won” 2 “free” round trip tickets worth up to $1400 to any place in the continental United States. Dont worry following is solution for this question. But be careful, if you want to try out these apps, be sure to keep a close eye on your internet traffic, they tend to be very data intensive.

  3. zellakwok says:

    When comparing the Sony Tablet S and the i – Pad, it’s best to start with a head-to-head comparison of features.
    There are units with small screens, large screens, varying camera specifications and an array of features that would baffle the average consumer.
    Un-root: for removing the root access to your tablet, this option does not require a restart.

  4. jenniferelia says:

    x android Ice Cream Sandwich in the last days of November in 2011 and
    they have done it with a grand launch of Custom Android Tablet 9 on February 13, 2012.
    This digital tablet is 10inch wide and is run on the
    Android os operating-system. But be careful, if you want to try out these apps,
    be sure to keep a close eye on your internet traffic, they
    tend to be very data intensive.

  5. johncushman says:

    magnificent post, very informative. I ponder why the opposite experts
    of this sector don’t realize this. You should continue your writing.
    I’m sure, you’ve a huge readers’ base already!

  6. Luigi Fulk says:

    I just want to say I’m new to weblog and actually savored your website. Almost certainly I’m planning to bookmark your site . You surely have great articles. Regards for revealing your blog.

  7. harmongreen says:

    My wife and that i are actually now delighted that Albert could perform his studies because of the strategies he had by means of your web page. It really is once in a while perplexing to simply often be gifting away actions which many people could have…

  8. Nat says:

    Informative and precise

    Its hard to find informative and accurate information but here I found

  9. Very interesting topic , thankyou for posting .
    “I do not pretend to know where many ignorant men are sure-that is all that agnosticism means.” by Clarence Darrow.

  10. I know this if off topic but I’m looking into starting my own blog and was wondering what all is needed to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web smart so I’m not 100% certain.
    Any recommendations or advice would be greatly appreciated.

    Cheers

  11. utewragge says:

    Hi there, just became alert to your blog through Google, and found that
    it is truly informative. I am going to watch out for brussels.
    I will appreciate if you continue this in future.
    A lot of people will be benefited from your writing.
    Cheers!

  12. Melody says:

    I see a lot of interesting content on your website. You have to spend a lot of time writing, i know how to save you a lot of time, there is a tool that creates unique, google
    friendly articles in couple of seconds, just search in google –
    laranita’s free content source

  13. Enriqueta says:

    I read a lot of interesting articles here. Probably you
    spend a lot of time writing, i know how to save you a lot of time, there is an online tool that creates high quality, google friendly posts in seconds,
    just search in google – laranitas free content

Leave a Reply

Your email address will not be published. Required fields are marked *

^