background preloader

Learn Java by Examples

Learn Java by Examples

Objects and Classes Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts: PolymorphismInheritanceEncapsulationAbstractionClassesObjectsInstanceMethodMessage Parsing In this chapter, we will look into the concepts Classes and Objects. Object - Objects have states and behaviors. Objects in Java: Let us now look deep into what are objects. If we consider a dog, then its state is - name, breed, color, and the behavior is - barking, wagging, running If you compare the software object with a real world object, they have very similar characteristics. Software objects also have a state and behavior. So in software development, methods operate on the internal state of an object and the object-to-object communication is done via methods. Classes in Java: A class is a blue print from which individual objects are created. A sample of a class is given below: A class can contain any of the following variable types. Constructors: Example:

5 Best Core Java Books you must read as a developer Looking for best java books? We have short listed some of the highly recommended Java books for beginners and senior experienced programmers. The core java books may help you easily thrive as a Java developer. The job of a Java developer is to write efficient programs to solve critical business problems. If you want success in Java, you do not need to enroll in a class. When you refer to a good JAVA book, you are also more likely to get detailed and current information than you would from a teacher or from self-education since good JAVA books are written by authorities in the field, authorities with years of experience in JAVA coding and an educational background in the same. The fact that there are many options available is also a big plus. Thinking in Java (By: Bruce Eckel) "Thinking in Java" is one of the best java book. This awesome book is also available for Free online at this site. Java(TM) Puzzlers: Traps, Pitfalls, and Corner Cases (By: Joshua Bloch , Neal Gafter) (By: Joshua Bloch)

JScience Introduction to Computer Science using Java This is a course in Java programming for beginners. It covers the fundamentals of programming, roughly the same material that is covered in a beginning programming course in a university or in a high school AP Computer Science course. For maximum benefit, go though these notes interactively, thinking about and answering the question at the bottom of each page. There are about 20 pages per chapter. If you spend about 3 minutes per page each chapter will take about 60 minutes, or longer if you copy and run some of the programs. If you are a beginning programmer, plan on spending more than a month with this. These notes assume that you have the Java version 5.0 or later from Oracle, Inc. at and a text editor such as Notepad. For more about these notes check the frequently asked questions. A German translation of these notes, done by Heinrich Gailer, is available at www.gailer-net.de/tutorials/java/java-toc.html.

Vector or ArrayList -- which is better? Q: Vector or ArrayList -- which is better and why? A: Sometimes Vector is better; sometimes ArrayList is better; sometimes you don't want to use either. I hope you weren't looking for an easy answer because the answer depends upon what you are doing. There are four factors to consider: APISynchronizationData growthUsage patterns Let's explore each in turn. In The Java Programming Language (Addison-Wesley, June 2000) Ken Arnold, James Gosling, and David Holmes describe the Vector as an analog to the ArrayList. Synchronization Vectors are synchronized. Data growth Internally, both the ArrayList and Vector hold onto their contents using an Array. Usage patterns Both the ArrayList and Vector are good for retrieving elements from a specific position in the container or for adding and removing elements from the end of the container. It means that if you want to index elements or add and remove elements at the end of the array, use either a Vector or an ArrayList. Learn more about this topic

Free Java Tutorials & Guide | Java programming source code Introduction to Programming in Java: An Interdisciplinary Approach Vector example in Java Vector implements a dynamic array. It is similar to ArrayList, but with two differences: Vector is synchronized, and it contains many legacy methods that are not part of the collections framework. With the release of Java 2, Vector was reengineered to extend AbstractList and implement the List interface, so it now is fully compatible with collections. Here are the Vector constructors: Vector( ) Vector(int size) Vector(int size, int incr) Vector(Collection c) The first form creates a default vector, which has an initial size of 10. All vectors start with an initial capacity. Vector defines these protected data members: int capacityIncrement; int elementCount; Object elementData[ ]; The increment value is stored in capacityIncrement. Because Vector implements List, you can use a vector just like you use an ArrayList instance. The following program uses a vector to store various types of numeric objects. The output from this program is shown here:

The Best Java Tools You Never Knew Existed 2inShare I was at an awesome presentation at JavaOne of the long tail of Java tools that not many people have come across, which I had to share. So, in no particular order, and with my own emotive comments: Apache Abdera - work easily with Atom feeds. Feel free to add any gems that you have come across in the comments! Learning Java - Chapter 10 : Java In the discussion of Vector we mentioned the Enumeration class, which provides for stepping through the elements of a list such as a Vector. However, Iterator, introduced with Java 1.2, is now preferred to Enumeration. Iterator differs from Enumeration in 2 ways: Elements can be safely removed from Vector using the remove (int index) without causing the Iterator to fail.. The hasMore () and next () methods in Iterator are short and direct as opposed to the corresponding long and boring methods nextElement () and hasMoreElements () in Enumeration. All the old container classes were retro-fitted with the Java 1.2 release to support the Iterator interface and the new container classes added in JDK 1.2 with the Collections Framework support only the Iterator interface. The syntax for iterating over the elements in a Vector is as follows Vector vec = new Vector; // Populate it... Again, we retrieve Object types from the Iterator. // Build an ArrayList and populate it with integers from 0 to 19.

Wrong Time with System.currentTimeMillis () (Java) Java: Multiple class declarations in one file Formatter (Java 2 Platform SE 5.0) java.lang.Object java.util.Formatter All Implemented Interfaces: Closeable, Flushable public final class Formatterextends Objectimplements Closeable, Flushable An interpreter for printf-style format strings. Formatters are not necessarily safe for multithreaded access. Formatted printing for the Java language is heavily inspired by C's printf. Examples of expected usage: StringBuilder sb = new StringBuilder(); // Send all output to the Appendable object sb Formatter formatter = new Formatter(sb, Locale.US); // Explicit argument indices may be used to re-order output. formatter.format("%4$2s %3$2s %2$2s %1$2s", "a", "b", "c", "d") // -> " d c b a" // Optional locale as the first argument can be used to get // locale-specific formatting of numbers. Convenience methods for common formatting requests exist as illustrated by the following invocations: // Writes a formatted string to System.out. Like C's sprintf(3), Strings may be formatted using the static method String.format: Organization Summary

command line - Java println formatting so I can display a table

Related: