By Vagish Kirubaharan COL/A-051935
By Vagish Kirubaharan COL/A-051935
By
Vagish Kirubaharan
COL/A-051935
Java is a general purpose computer programming
language that is concurrent class based object oriented
and specifically designed to have a few implementation
developments and dependencies as possible.
It is intended to let application developers "write once,
run anywhere" (WORA), meaning that compiled Java
code can run on all platforms that support Java without
the need for recompilationJava applications are
typically compiled to bytecode that can run on any Java
virtual machine (JVM) regardless of computer
architecture. As of 2016, Java is one of the most popular
programming languages in useparticularly for client-
server web applications, with a reported 9 million
developersJava was originally developed by James
Gosling at Sun Microsystems (which has since been
acquired by 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.
Writing in the Java programming language is the
primary way to produce code that will be deployed as
byte code in a Java virtual machine (JVM); byte code
compilers are also available for other languages,
including Ada, JavaScript, Python, and Ruby. In addition,
several languages have been designed to run natively
on the JVM, including Scala, Clojure and Apache Groovy.
Java syntax borrows heavily from C and C++, but object-
oriented features are modeled after Smalltalk and
Objective-CJava eschews certain low-level constructs
such as pointers and has a very simple memory model
where every object is allocated on the heap and all
variables of object types are references. Memory
management is handled through integrated automatic
garbage collection performed by the JVM.
package fibsandlies;
import java.util.HashMap;
/**
* This is an example of a Javadoc comment; Javadoc
can compile documentation
* from this text. Javadoc comments must immediately
precede the class, method, or field being documented.
*/
public class FibCalculator extends Fibonacci implements
Calculator {
private static Map<Integer, Integer> memoized = new
HashMap<Integer, Integer>();
/*
* The main method written as follows is used by the
JVM as a starting point for the program.
*/
public static void main(String[] args) {
memoized.put(1, 1);
memoized.put(2, 1);
System.out.println(fibonacci(12)); //Get the 12th
Fibonacci number and print to console
}
/**
* An example of a method written in Java, wrapped
in a class.
* 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
*/
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;
}
}
}
Examples of JavaScript
console.log("Hello World!");
factorial(3); // returns 6
function counter() {
var count = 0;
return function() {
return ++count;
};
}
Object example
function sum() {
var x = 0;
for (var i = 0; i < arguments.length; ++i) {
x += arguments[i];
}
return x;
}
sum(1, 2); // returns 3
sum(1, 2, 3); // returns 6
counter.get(); // shows 0
counter.set(6);
counter.increment(); // shows 7
counter.increment(); // shows 8
Applet
Java applets are programs that are embedded in
other applications, typically in a Web page
displayed in a web browser.
// Hello.java
import javax.swing.JApplet;
import java.awt.Graphics;
THE END
Vagish Kirubharan
COL/A 051935