Archive

Posts Tagged ‘Java’

Java – javadoc

January 5, 2010 Leave a comment

Javadoc element

Element      desc

/**

@author  = name of the programmer

@deprecated = markeert de methode als verouderd (deprecated).

@exception =

@param =

@return

@returns =

@see

@since

@throws

@version


Categories: Java Tags:

Java – Tips

December 31, 2009 Leave a comment

Interface:
============

// when we say interface we dont use function brackets;
public interface MainCar {

//
int shamun(int a);

}

// when we say “Implements” we add function brackets
public class A implements MainCar {

int shamun(int a){
// more…..
}
}

public interface groupInterface extends interface1,interface2 {
double E = 2.33;
void newMore(int i);
}

Inheritance:
============
When you want to create a new class and there is already a class that includes
some of the code that you want, you can derive your new class from the existing
class. In doing this, you can resuse the fields and methods of the existing
class without having to write
(and debug !) them yourself.

An Example of Inheritance
Here is the sample code for a possible implementation of a Bicycle class that was presented in the Classes and Objects lesson:

public class Bicycle {

// the Bicycle class has three fields
public int cadence;
public int gear;
public int speed;

// the Bicycle class has one constructor
public Bicycle(int startCadence, int startSpeed, int startGear) {
gear = startGear;
cadence = startCadence;
speed = startSpeed;
}

// the Bicycle class has four methods
public void setCadence(int newValue) {
cadence = newValue;
}

public void setGear(int newValue) {
gear = newValue;
}

public void applyBrake(int decrement) {
speed -= decrement;
}

public void speedUp(int increment) {
speed += increment;
}

}

A class declaration for a MountainBike class that is a subclass of Bicycle might look like this:

public class MountainBike extends Bicycle {

// the MountainBike subclass adds one field
public int seatHeight;

// the MountainBike subclass has one constructor
public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) {
super(startCadence, startSpeed, startGear);
seatHeight = startHeight;
}

// the MountainBike subclass adds one method
public void setHeight(int newValue) {
seatHeight = newValue;
}

}

MountainBike inherits all the fields and methods of Bicycle and adds the field seatHeight and a method to set it. Except for the constructor, it is as if you had written a new MountainBike class entirely from scratch, with four fields and five methods. However, you didn’t have to do all the work. This would be especially valuable if the methods in the Bicycle class were complex and had taken substantial time to debug.

Polymorphism:

Categories: Java Tags:

Java – Frameworks

December 29, 2009 Leave a comment

Java Tree

o— java SE (standard edition)
o———- desktop/workstation/server
o— java EE
(enterprise edition)
o— java ME (micro edition)
o———- MIDP/CLDC/JSR

Like other languages we have also frameworks and groups

1. Apache Tomcat
2. Jboss

– jboss (Red Hat) is a group which has sub items like

Product features (wiki)

its competitors or similars are

a. BEA Weblogic (oracle staffs)

b. IBM WebSphere

2. Liferay

– is a portal, jsp/servlet with predefined modules

Categories: centOS, Fedora 12, Java Tags:

Java – Basic Rules

December 1, 2009 Leave a comment

Very basics law of java.

1. package directant;  // like namespace or under a same folder

2.  import javax.swing.*; import java.awt.*;  // like include

3. Must have main

public class Main {
public static void main(String[] args){
// call gui window

}
}

Categories: Java Tags:

Java – How to Ant Gui?

December 1, 2009 Leave a comment

Just a small but a very handy.
##############################################
1. GUI – will eat time – we used seperate GUI builder jvider.com
2. Action collect centrally
3. Programming
##############################################

Main.java
=========

// Simple Ant procedure
package directant;
/**
*
* @author shamun
*/
public class Main {
/**
* @param One main execute
*/
public static void main(String[] args) {
// Other tasks can be done here.
// Calling GUI
Gui gui = new Gui();
gui.setVisible(true);
}
}

// Simple Ant procedurepackage directant;
/** * * @author shamun */public class Main {
/**     * @param One main execute     */    public static void main(String[] args) {        // Other tasks can be done here.                // Calling GUI        Gui gui = new Gui();        gui.setVisible(true);    }
}

Gui.java
=======
package directant;

import javax.swing.JPanel;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;

import java.awt.*;

import java.awt.event.*;

/**

*

* @author shamun

*/

public class Gui extends JFrame implements ActionListener{

static Gui theGui;

JPanel pnPanel0;

JButton btBut0;

JButton btBut1;

public static void main( String args[] ) throws UnsupportedLookAndFeelException{

try

{

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

}

catch ( ClassNotFoundException e )

{

}

catch ( InstantiationException e )

{

}

catch ( IllegalAccessException e )

{

}

catch ( UnsupportedLookAndFeelException e )

{

}

theGui = new Gui();

}

public Gui(){

super( “TITLE” );

pnPanel0 = new JPanel();

GridBagLayout gbPanel0 = new GridBagLayout();

GridBagConstraints gbcPanel0 = new GridBagConstraints();

pnPanel0.setLayout( gbPanel0 );

btBut0 = new JButton( “shamun”  );

gbcPanel0.gridx = 1;

gbcPanel0.gridy = 2;

gbcPanel0.gridwidth = 15;

gbcPanel0.gridheight = 4;

gbcPanel0.fill = GridBagConstraints.BOTH;

gbcPanel0.weightx = 1;

gbcPanel0.weighty = 0;

gbcPanel0.anchor = GridBagConstraints.NORTH;

gbPanel0.setConstraints( btBut0, gbcPanel0 );

pnPanel0.add( btBut0 );

btBut1 = new JButton( “foo”  );

gbcPanel0.gridx = 7;

gbcPanel0.gridy = 11;

gbcPanel0.gridwidth = 11;

gbcPanel0.gridheight = 4;

gbcPanel0.fill = GridBagConstraints.BOTH;

gbcPanel0.weightx = 1;

gbcPanel0.weighty = 0;

gbcPanel0.anchor = GridBagConstraints.NORTH;

gbPanel0.setConstraints( btBut1, gbcPanel0 );

pnPanel0.add( btBut1 );

setDefaultCloseOperation( EXIT_ON_CLOSE );

setContentPane( pnPanel0 );

pack();

setVisible( true );

// Mannually created – Attach button actions

btBut1.addActionListener(this);

btBut1.addActionListener(new EventCentral());

}

// Mannually created

public void actionPerformed(ActionEvent e) {

//throw new UnsupportedOperationException(“Not supported yet.”);

System.out.print(“First thread \r\n”);

}

}// End of GUi

EventCentral.java
===============

// namespace

package directant;

// includes

import java.awt.event.*;

// Event Actions are listening on here.

public class EventCentral implements ActionListener {

// Not in use, we can use it as __construct.

public EventCentral(){}

// This is getting trigger by Gui.Java

public void actionPerformed(ActionEvent e) {

System.out.print(“Second thread \r\n”);

}

}

Categories: Java Tags:

Java – Swing | Awt | SWT

December 1, 2009 Leave a comment

Performance:

Prefer SWING to use. Performance issues and latest. Even if SWING is written on top of Awt. Most other experts advised also that both maybe used by with correct implementations.

Default:

Swing GUI prefered

Button action:
private javax.swing.JButton jButton1;

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

jTextArea1.setText(“Shamun wt….!”);
JFrame gui = new NewJFrame1();   // Another module
gui.setVisible(true);
}

Categories: Java Tags:

Java – How to Ant

December 1, 2009 Leave a comment

Just a small but a very handy.
##############################################
1. GUI – will eat time
2. Action collect centrally
3. Programming
##############################################

Main.java
=========
package directant;

import javax.swing.*
import java.awt.*;

public class Main {
public static void main(String[] args){
// call gui window

}
}

Gui.java
=======
package directant;

EventCentral.java
===============

Categories: Java Tags: