Eclipse provides an option to detach a view so that it can be moved to the desired place. Detached views are used if you are not comfortable with the placing of a view and want it to be move to someplace that is more feasible. This is done as follows: Right-click on the viewSelect "Detached" from the menuPlace the view where you choose Thing to remember is that one can also drag and drop ...
Unit testing brings a lot of benefits but there is some cost for this. Lets talk about this. Unit tests require skill and time. Often managers dont appreciate unit tets because they regard it something othere than development. Ofcource client in not interested in unit tests but management needs to understand that these tests will save a lot of debugging effort in future. For unit testing to really deliver, all developers need to use it. Mostly due to lack of communicationm ...
Its right to say that final keyword improves performance. For example, if you declare a method as final, then you cannot override it in derived classes. When this is told to compiler in advance using final keyword, it improves performance. Java Code: public final void doSomethng() { ... } Knowing that a method cannot be overridden, complier inline that method into its derived classes. Final variables, especially static final variables, ...
public final void doSomethng() { ... }
You are aware of the fact that garbage collection collects and removes all the unwanted objects from memory without used intervention. But sometimes, you run into memory leaks problems that demands investigation. I will shed some light on this issue in the next few posts. The Java GC process is a low-priority thread and it constantly searches memory for unreachable objects that are not reachable by any live thread. Different JVMs use different algorithms to determine how to collect ...
Abstract Java ArrayList (ArrayList (Java 2 Platform SE 5.0)) class is a fastest and easiest way to represent one-dimensional array. ArrayList not synchronized, that is cross thread access may cause problems. It holds an ordered item sequence of items (objects) like an array, but there are differences: Size of an ArrayList could change dynamically, by adding or removing elementsAn ArrayList can hold only object references, not primitives ...
Want to add a so called "Global" Keylistener to your Java application even if it is a JWindow or JFrame without having focus on it. Just download the file in the link and extract, add the jhook.jar file to your project library and use this demo code to get the keys pressed. Java Code: Keyboard kb=new Keyboard(); kb.addListener(new KeyboardListener() { public void keyPressed(boolean keydown, int vk){ System.out.println(vk); ...
Keyboard kb=new Keyboard(); kb.addListener(new KeyboardListener() { public void keyPressed(boolean keydown, int vk){ System.out.println(vk);
Updated 10-19-2011 at 09:33 AM by DuvanSlabbert
Each contact entry in a PIM Contact database is represented by Contact. This post is all about retrieving contact fields from PIM. The supported field list for a Contact depends on vCard specification from the Internet Mail Consortium. These set of fields included in this Contact class provides relevant information about a contact. ContactList restricts what fields a Contact can retain. This reflects that some native Contact databases do not support all o the fields available in a ...
Methods called on the asynchronous proxy will be executed asynchronously, and the results can be obtained later on. To execute methods asynchronously in EJB 3.0, one can use asynchronous proxy. This allows calling methods at an instance, and collecting the results later. Good thing is that there exist a JBoss extension to EJB 3.0, which allows obtaining asynchronous proxy from the remote or local interface of a stateful session bean, stateless session bean or service bean. ...
I've spent the past few days looking up Java window transitions that work with Swing components & containers (JFrame, JPanel, etc.). Yes, there are packages such as JavaFX which includes a Timeline & Transition framework. I also came across these: Trident: Project Kenai — We're More Than Just a Forge FRC: Filthy Rich Clients (find the Animation jar (org.jdesktop.animation)) However, I've been impatient lately ...
Declaring a Class Java Code: class ClassName{ ...code... } Declaring a Class with Parent Java Code: class ClassName extends parentClassName{ ...code... } Declaring a class with Interface Java Code: class ClassName implements interface1, interface2, interface3{ ...code... } Declaring a Class with Fields Java Code: class ClassName{ public ...
class ClassName{ ...code... }
class ClassName extends parentClassName{ ...code... }
class ClassName implements interface1, interface2, interface3{ ...code... }
class ClassName{ public
Updated 10-18-2012 at 01:30 AM by penguinCoder
A string is a piece of text, that is zero or more characters in length. In Java, strings are considered to be pre-built objects. The variable for a string does not store the value of the string, rather it is a reference point, or pointer, to the storage location of where the string is kept. Declaring a String: Java Code: String s1; Assigning a Value On Declaration: Java Code: String s1 = "Hello World!"; Assigning ...
String s1;
String s1 = "Hello World!";
Updated 10-18-2012 at 01:29 AM by penguinCoder
The Scanner class can be used for many things other then just getting input from the user; however this cheat sheet/tutorial is just going to be about getting input from the user. Defining the Scanner Class Java Code: import java.util.Scanner; public class ClassName{ ...code... } It will tell the translator to look in that directory for the code defining the Scanner class. Declaring the Scanner If you ...
import java.util.Scanner; public class ClassName{ ...code... }
Importing the Library Before you can use an ArrayList, you must first import the necessary library. Java Code: import java.util.ArrayList Creating a Generic ArrayList Generic ArrayList is an ArrayList with a type; no other type is allowed to be inserted into the ArrayList. Java Code: ArrayList<type> listName = new ArrayList<type>(); Example of this would be: Java Code: ArrayList<String> myArrayList = new ArrayList<String>(); ...
import java.util.ArrayList
ArrayList<type> listName = new ArrayList<type>();
ArrayList<String> myArrayList = new ArrayList<String>();
Updated 10-29-2012 at 08:29 PM by penguinCoder
The methods of the javafx.application.Application class that define the life cycle of a JavaFX application are the following: public void init()public abstract void start(Stage primaryStage)public void stop() The init() method is called right after an Application object is instantiated, and can be used for application-specific initializations; however, GUI operations such as creating stages or scenes cannot be done from within this method, because at the time ...
Updated 12-11-2016 at 07:16 PM by JavaFX
JavaFX has a powerful event dispatch mechanism that allows different Node elements in a scene graph to intercept GUI events before and after they are delivered to their target node. Every time a new event is generated, an event dispatch chain is built for that event: this chain starts from the stage of the application window, continues with the scene displayed on that stage, and then follows the scene graph down to the target node of the event. For example, when a user clicks on a button in an application, ...
If you think that you cannot access private data members of a class from some other class, then think again. With Reflection, this is possible. Using reflection, we can see / view / access a private member, private variable, private method. Some people will not like this with argument that this actually means messing up the laws of encapsulation. I use it for unit testing private methods. Example follows: Java Code: import java.lang.reflect.Field; ...
import java.lang.reflect.Field;
In this article I plan to create a quick, easy to locate post about good books that I have encountered. Feel free to comment and add your book recommendations. I plan to include more than just Java books in this post. I will start with Java, moving onto c++, and other languages. The end of the post with books I have on my short list. These books will be finished shortly and I will put them here, and update my thoughts as the books are finished. Starting out - Which book to get? ...
Greetings, the previous blog article talked a bit about the Visitor design pattern. This article talks a bit about additional functionality that is sometimes wanted, i.e. the functionality is optional. Assume there is a lot of optional functionality that people want. This article discusses the Decorator (or 'Wrapper') pattern. For the sake of the example we'll use array manipulation. People always fiddle diddle with arrays, i.e. they copy values from one array to another, ...
Updated 07-23-2011 at 03:45 PM by JosAH
Eclipse provides an easy way to generate stubs for the parent classes and implemented interfaces. Right click the your class and select Source > Override/Implement methods. You will be presented a window where you can select all the methods that you want to override/implement. This methods will be from the implemented interface or extended class. Really saves time. Do try this.
Recursion: Recursion is defined as: 1. the act or process of returning or running back 2. logic, maths the application of a function to its own values to generate an infinite sequence of values. The recursion formula or clause of a definition specifies the progression from one term to the next, as given the base clause f (0) = 0, f ( n + 1) = f ( n ) + 3 specifies the successive terms of the sequence f ( n ) = 3 n In this article, I hope to make ...
Updated 06-20-2011 at 05:48 AM by sunde887
jmap is one of the lesser known jdk provided utilities, which are worth mentioning. Very oftenly we feel the need to peek into the jvm and see which thread is taking how much of heap space - jmap is jdk’s answer to this. This utility was introduced in jdk1.5 and is as an experimental utility (oracle may discontinue to ship this utility with future releases) Some of the notable features of jmap are: 1. can print shared object memory maps or heap memory ...
Programmers are usually confused between "Comparable" and "Comparator" interface. Comparable interface has "compareTo" method which is normally used for natural ordering but Comparator interface has "compare" method which takes two arguments. It can be used where you want to sort objects based of more then one parameter. Following example will make it more clear. Java Code: package test;/* ** Use the Collections.sort to ...
package test;/* ** Use the Collections.sort to
Sometimes you are required to fetch and store data from web pages. If there are too many pages to parse, then obviously this cannot be done manually. Java provides support for web text extraction. The approach is simple. You have to fetch all the HTML contents of a webpage and then you can write your own parser to extract the required info. For example: you might be asked to only store the text in table data tag with caption Hobbies. So you will store all the HTML contents of web ...
This post briefly explains the 5 tiers in Java Enterprise Edition. Client A web browser, a hand held device or an application which remotely accesses the services of an enterprise application are examples of a Client tier. In other words a Client tier can consists of all the types of components that are clients of an enterprise application. Presentation Filters, Java Servlets, JavaServer Pages, JavaBeans and other utility classes ...
Java Code: public class ArrayLister { private static int arraySearcher(int[] arrayToSort,int numberToFind,int left,int right){ int middle = (left + right) / 2 ; System.out.println(middle); if(middle==arrayToSort.length-1) { if(arrayToSort[middle] == numberToFind) { return middle; } else return -1; } if(arrayToSort[middle] == numberToFind) { return ...
public class ArrayLister { private static int arraySearcher(int[] arrayToSort,int numberToFind,int left,int right){ int middle = (left + right) / 2 ; System.out.println(middle); if(middle==arrayToSort.length-1) { if(arrayToSort[middle] == numberToFind) { return middle; } else return -1; } if(arrayToSort[middle] == numberToFind) { return
SQL files can be created manually in any existing eclipse project. It's simple and useful. I'll list the required steps. Open Database Development perspectiveSelect File > New > Other, expand SQL Development, select SQL File, and click NextThis will open the New SQL File wizard.To create a new project, click "Create Project" and follow the wizard instructions. Now provide the SQL file name.Select a connection profile type from the Connection profile ...
In mathematics a singleton (not to be confused with a simpleton) is a set with exactly one element. In computer science Singleton is a pattern which enforces the existence of only up to one instance of a class. Singleton is sometimes considered an anti-pattern, and it's famous for being considered unnecessary in the world of Python (where you duck type). Singleton is however useful, it is a nice and clean why to restrict the number of instances, to only one. In ...
Updated 08-12-2011 at 07:13 PM by Hibernate (typo)
Java Code: package decoratorPattern; public abstract class Beverage { String description; int size; public Beverage(int size) { this.size = size; } public String getDescription() { String mySize = null; if(size == 1) mySize = "Small"; else if(size==2) mySize="Medium"; else if(size==3) mySize="Large"; ...
package decoratorPattern; public abstract class Beverage { String description; int size; public Beverage(int size) { this.size = size; } public String getDescription() { String mySize = null; if(size == 1) mySize = "Small"; else if(size==2) mySize="Medium"; else if(size==3) mySize="Large";
Java Code: package observerPatternBuiltIn; import java.util.Observable; public class MyObservable extends Observable { int integerToBeObserved; public void setInt(int i) { integerToBeObserved = i; setChanged(); notifyObservers(); } public int getInt() { return integerToBeObserved; } } package observerPatternBuiltIn; import ...
package observerPatternBuiltIn; import java.util.Observable; public class MyObservable extends Observable { int integerToBeObserved; public void setInt(int i) { integerToBeObserved = i; setChanged(); notifyObservers(); } public int getInt() { return integerToBeObserved; } } package observerPatternBuiltIn; import
Originally Posted by .paul. i used Dates in this particular case, as they were better suited to the application. but i also created a java TimeSpan class, similar to the .Net Framework TimeSpan class: Java Code: package javaTimeSpans; /** * * @author Paul */ public class TimeSpan { private int _days; private int _hours; private int _minutes; private int _seconds; public int Days(){ ...
package javaTimeSpans; /** * * @author Paul */ public class TimeSpan { private int _days; private int _hours; private int _minutes; private int _seconds; public int Days(){