Hi guys
API is an acronym for Application Programming Interface, which is a set of libraries that we may use when we are coding our own Java programs.
There are three kinds of Java APIs:
Core Java API
The oficial Java API. Please take a look at the Java API docs at Oracle website:
http://docs.oracle.com/javase/6/docs/api/
JSR - Java Specification Request
The JCP (Java Community Process) defines specifications in order to extend Java functionallity. Any vendor may develop an API according to a JSR and we can download their libraries and use in our own code.
Third party APIs
Other kind of libraries developed to extend Java functionallity, but not related to a JSR.
Beginning Java
Sharing experiences about Java
2012/05/29
2010/12/03
Formatting Dates
It's very easy to use the SimpleDateFormat from the java.text API to format a date variable:
Explaining the code:
You may find more information at:
http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
Date currentDate = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); System.out.println("Date without any format: " + currentDate); System.out.println("Our beautiful formatted date: " + formatter.format(currentDate));
Explaining the code:
- First we instantiated a variable called currentDate using the default constructor of the java.util.Date class, which creates a Date object with the value as the current date and time
- Then we got a instance of the SimpleDateFormat class, specifying the pattern "yyyy/MM/dd" which means year with four digits, month with two digits (01 to 12) and day of the month with two digits (01 to 31).
- We displayed on the console the currentDate variable (we used the default toString() method to display the variable value)
- Then we displayed the formatted value using the method format of the SimpleDateFormat class
You may find more information at:
http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
What’s the difference between JDK and JRE?
While the Java Runtime Environment (JRE) is a set of libraries and programs which enables the final user to run Java applications, the Java Development Kit (JDK) is a product aimed at Java developers. With the JDK we are able to develop, debug and run a Java application on any platform.
The JDK has a lot of components, but the main are:
javac
A compiler which converts source code (text files with extension .java) to a bytecode file (mainly .class files)
java
It´s the loader for Java applications. It interprets the bytecode file generated by javac compiler to the operational system.
What`s the difference between JSE, JME and JEE?
Java is a program language that enables the development on many platforms. It´s possible to run Java programs on small devices (like mobile phones), on personal computers and even on mainframes. To be able to do that Java has three development environments: JSE, JME and JEE.
The other two environments (JME and JEE) are based on JSE.
JME – Java Micro Edition
Java Platform, Micro Edition, or Java ME, is a Java platform designed for embedded systems (mobile devices are one kind of such systems) . Target devices range from industrial controls to mobile phones (especially feature phones) and set-top boxes.
JEE – Java Enterprise Edition
The Java platform Enterprise Edition differs from the Java Standard Edition Platform (JSE) in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier Java software, based largely on modular components running on an application server.
More information at:
JSE – Java Standard Edition
Java Platform, Standard Edition or Java SE is a widely used platform for programming in the Java language. It is the Java Platform used to deploy portable applications for general use. In practical terms, Java SE consists of a virtual machine, which must be used to run Java programs, together with a set of libraries (or "packages") needed to allow the use of file systems, networks, graphical interfaces, and so on, from within those programs.
Java Platform, Standard Edition or Java SE is a widely used platform for programming in the Java language. It is the Java Platform used to deploy portable applications for general use. In practical terms, Java SE consists of a virtual machine, which must be used to run Java programs, together with a set of libraries (or "packages") needed to allow the use of file systems, networks, graphical interfaces, and so on, from within those programs.
The other two environments (JME and JEE) are based on JSE.
JME – Java Micro Edition
Java Platform, Micro Edition, or Java ME, is a Java platform designed for embedded systems (mobile devices are one kind of such systems) . Target devices range from industrial controls to mobile phones (especially feature phones) and set-top boxes.
JEE – Java Enterprise Edition
The Java platform Enterprise Edition differs from the Java Standard Edition Platform (JSE) in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier Java software, based largely on modular components running on an application server.
More information at:
2010/12/02
What's the JVM?
JVM means Java Virtual Machine which is the environment where we run computer programs written in Java language. Java was conceived with the concept of WORA: "write once, run anywhere". This is done using the Java Virtual Machine.
A Java program is compiled into a standardized portable binary format (a bytecode file), which typically comes in the form of .class files. The JVM executes the .class files, interpreting the commands to the operational systems.
You may find more info at:
A Java program is compiled into a standardized portable binary format (a bytecode file), which typically comes in the form of .class files. The JVM executes the .class files, interpreting the commands to the operational systems.
You may find more info at:
What's Java?
So, what's Java?
According to Wikipedia:
Java is a programming language originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from Cand C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere". Java is currently one of the most popular programming languages in use, and is widely used from application software to web applications.
Basically, Java is a object-oriented programming language that runs over a virtual machine. The Java Virtual Machine (JVM) enables our programs to run under almost all operational systems on any platform, from desktops to television sets.
You may find more information at:
2010/11/29
Formatting numbers
It´s possible format numbers and dates using the java.text API.
Formatting a number is pretty simple. We use the DecimalFormat class to specify a custom format:
There are a lot of patterns you could use to format numbers.
Just take a look at http://download.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
Formatting a number is pretty simple. We use the DecimalFormat class to specify a custom format:
NumberFormat formatter1 = new DecimalFormat("#,###"); System.out.println(formatter1.format(123123)) // displays 123,123 NumberFormat formatter2 = new DecimalFormat("0.00"); System.out.println(formatter2.format(123123)) // displays 123123.00 NumberFormat formatter3 = new DecimalFormat("#,##0.00"); System.out.println(formatter3.format(123123.123)) // displays 123,123.12
There are a lot of patterns you could use to format numbers.
Just take a look at http://download.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
Subscribe to:
Posts (Atom)