Monthly Archives: February 2011

Solving gcc in linux64 – -static-libgcc-B/usr/lib/gcc/i386-redhat-linux6E/4.4.0


Recently i wanted to install php and apache on Oracle Enterprise linus which was upgraded to linux64.

When I tried the solution given in

http://www.lamphowto.com/

http://wiki.apache.org/tomcat/UsingPhp

http://dan.drydog.com/apache2php.html

I keep getting the following error when I

make
or
make install

the error is like

#> gcc
gcc.orig: unrecognized option '-static-libgcc-B/usr/lib/gcc/i386-redhat-linux6E/4.4.0'
gcc.orig: no input files

This clearly proves that there is a problem in the linux64
I tried all possible tricks on earth but could get away with it.
Finally i tried the following and it worked..

#> which gcc
#> /usr/bin/gcc
#> ls /usr/bin/gcc*
#> gcc gcc34 gcc41 gccmakedep gcc44 gcc.orig
#> mv /usr/bin/gcc /usr/bin/gcc_old
#> mv /usr/bin/gcc34 /usr/bin/gcc
#> gcc: no input files
Advertisements

Interesting Questions


Why map is not a collection?

collection acts upon values. map acts on key value pair

Why the finalize method is protected?

Finalize method is for the JVM to execute before GC.imagine if finalize is public then any object can call directly which is not what we wanted. If you have some open connection you can write cleanup codes in the finalize method in your class and leave the rest of the work to the JVM to call the finalize method.

The finalize method is made protected for the subclass to override it or any finalize operations.

Can a finalize method be called for twice?

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the <code>finalize</code> method causes the finalization of this object to be halted, but is otherwise ignored.

why the clone is protected?

clone is protected because it is something that ought to be overridden so that it is specific to the current class.It’s protected so you don’t use the one in object (it’ll just throw an exception anyway). They want you to override it in a class, then you make it public

How to convert BigDecimal to Integer?


BigDecimal b = new BigDecimal("123");

Integer i = new Integer(String.valueOf(b));

Why Serializable and Cloneable is not having anything?

Serializable and Cloneable are called marker or tag interface because they tag all derived class on purpose. Java has a default clone() method in Object class which should not be applied for all the class. So whenever user creates a class the object is not cloneable. The object is cloneable only when it has the marking of Cloneable interface. if any class implements Cloneable then it is understood by the JVM that the object is eligible for cloning and Object by default provides the cloning method this also provide the class to implement their own clone operation by making it protected

The class is marked Serializable for the JVM to understand that the class can be serialized

 

Breaking singleton pattern


Singleton pattern in java can be implemented by the approaches explained here

Now here is the code to break it using reflection


public class NormalClass{

 private NormalClass(){ //having private constructor
 }

 private void print(){
 System.out.println(&amp;quot;broken&amp;quot;);
 }

}

/////////////////////////////////

public class Main{

 public static void main(String[] args) throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {

 Class c = NormalClass.class;
 final Constructor con = c.getDeclaredConstructor();
 System.out.println(con);

 final Method meth = c.getDeclaredMethod(&amp;quot;print&amp;quot;, null);

//---- You will get IllegalAccessException without this ---
AccessController.doPrivileged(new PrivilegedAction() {

public Object run() {
 con.setAccessible(true);// turning off the access check
 meth.setAccessible(true);// turning off the access check
return null;
 }

});

 NormalClass n = (NormalClass)con.newInstance(null);
 meth.invoke(n,null);
 }

}

Java Annotations


Why do we use Annotations?

Annotations give information about the java program and is not part of the program itslf
They give inforamtion to the compiler for Compiler time processing, deployment time processing and runtime processing

Some of the annotations are

@Author(
 name="vinod",
 date="3/12/2010"

)
public class MyClass{}

@suppressWarnings{value="unchecked"}
public void myMethod(){}

@override
public void run(){}

@Deprecated
public void printWriter(){}

There are two types of annotations

Simple and Meta Annotations

Simple Annotations – provided by JDK5

* Override
* Deprecated
* Suppresswarnings

Meta Annotations – Annotations of Annotation

* Target
* Retention
* Documented
* Inherited

Target – target element for which the annotation is applicable

* @Target(ElementType.TYPE) – applied to any element of a class
* @Target(ElementType.FIELD) – applied to a field or property
* @Target(ElementType.METHOD) – applied to a method level annotation
* @Target(ElementType.PARAMETER) – applied to the parameters of a method
* @Target(ElementType.CONSTRUCTOR) – applied to constructors
* @Target(ElementType.LOCAL_VARIABLE) – applied to local variables
* @Target(ElementType.ANNOTATION_TYPE) – indicates that the declared type itself is an annotation type

Retention – how long the annotations should be retained

* RetentionPolicy.SOURCE – retained only at the source level and will be ignored by the compiler
* RetentionPolicy.CLASS – retained by the compiler at compile time, but will be ignored by the VM
* RetentionPolicy.RUNTIME – retained by the VM so they can be read only at run-time

Documented – should be documented in by the javadoc tool

Inherited -annotations of the parent class is inherited to the subclass

Producer and Consumer Problem


Self explanatory Producer and Consumer problem

Producer.java

package com.producer;

import java.util.ArrayList;

import java.util.Random;

public class Producer implements Runnable{

//Engine Batch ID reference

ArrayList engineList;

//Engine No is stored here

String str;

//Assigning the BATCH ID reference

public Producer(ArrayList engineList) {

this.engineList = engineList;

}

/*

* Produce Engines

*/

public void produce(){

//Random number for engine number

str = ""+Math.abs(new Random(System.currentTimeMillis()).nextLong());

//Only one thread can enter the BATCH for any operation

synchronized (engineList) {

//Add the Engine to the batch

engineList.add(str);

//Notify all other threads that the new engine is added to the BATCH

engineList.notifyAll();

}

//Print Engine Number

System.out.println("Produced :: ENGINE CHASIS NO ["+ str + "]");

}

@Override

public void run() {

System.out.println("Production started");

//10 Engine is to be produced

for(int i=0;i<10;i++){

try {

//Produce the engine

this.produce();

//Sleep for 2 seconds for the next operation

Thread.sleep(2000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

Consumer.java


package com.producer;

import java.util.ArrayList;

public class Consumer extends Thread{

//Engine Batch ID reference

ArrayList<String> engineList;

//Engine No is stored here

String str;

//Assigning the BATCH ID reference

public Consumer(ArrayList<String> engineList) {

this.engineList = engineList;

}

/*

* Consume Engines from the BATCH

*/

public  void consume(int index) throws InterruptedException{

//Only one thread can enter the BATCH for any operation

synchronized (engineList) {

//if the Batch has no engines

while(engineList.size() == 0){

//then wait for some time until you get a new engine to consume

engineList.wait();

}

//If the engine is deployed to the BATCH

if(engineList.size() >= 0){

//The consume the engine from the respective position

str = engineList.get(index);

}

}

//Print Engine Number that it has been consumed

System.out.println("Consumed :: -------> ENGINE CHASIS NO ["+ str + "]" );

}

@Override

public void run() {

//10 Engine has to be consumed

for(int i=0;i<10;i++){

try {

//Produce the engine

this.consume(i);

//Sleep for 3 seconds for the next operation

Thread.sleep(3000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

Main.java


package com.producer;

import java.util.ArrayList;

public class Main {

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

//ArrayList to store the produced engines - BATCH

ArrayList<String> engine = new ArrayList<String>();

//Producer taking the engine BATCH ID Reference

Producer producer = new Producer(engine);

//Consumer taking the reference of the engine BATCH ID Reference

Consumer consumer = new Consumer(engine);

//Threads

Thread prodThread = new Thread(producer);

Thread conThread = new Thread(consumer);

//Starting the production

prodThread.start();

//Start Consumption

conThread.start();

}

}


oracle.jbo.InvalidOwnerException


oracle.jbo.InvalidOwnerException: JBO-25030: Failed to find or invalidate
owning entity: detail entity Emp, row key oracle.jbo.Key[-5 ].
at oracle.jbo.server.EntityImpl.internalCreate(EntityImpl.java:1048)
at oracle.jbo.server.EntityImpl.create(EntityImpl.java:811)

if you the above exception whn u create master /detail table then do the following

  1. Cascade Update Key Attributes” in association should be checked
  2. In viewRowImpl add
@Override
public void setNewRowState(byte state) {
 if (state != Row.STATUS_INITIALIZED || getNewRowState() != Row.STATUS_NEW) {
 super.setNewRowState(state);
 }
}

oracle.jbo.InvalidOperException: JBO-25011


if you get the following error when you set Access Mode“=”Range Paging” to avoid all the records to be fetched and cached in ADF BC

oracle.jbo.InvalidOperException: JBO-25011: Rowset _LOCAL_VIEW_USAGE_model_EmployeesView_DepartmentsView1_0 is forward only

The “ListRangeSize” property of the List of Value is always set to “-1”  contradicting that

  • you are using the “Range Paging” “Access Mode”, you fetches a limited number of records for the View Object
  • you are using the “ListRangeSize” = -1 fetches ALL the records for the List Of Values

so to avoid the above error increase the ListRangeSize property