Thursday, February 26, 2009

Bulma Y Chichi Fusion

Create Java Native functions ... DLL in Java Classpath

Well sometimes it is necessary to create functions that are dependent System and therefore can not be implemented in Java, that's what JNI (Java Native Interface), used to call native functions of the system and can be in a DLL (in Windows). Well now we will see how to create a native function that is being called in Java. The first thing we do is create a class, and has defined a native method, in turn, charge a class library that is called "Project1" (that's how I got my C compiler hahaha) then the main , instantiate the object and call the function:
 
public class HelloWorld {public

native void sayHello ();
{static

System.loadLibrary ("Project1");


} public static void main (String [] args) {
new HelloWorld (). SayHello ();

}}



The example is very simple, we only have one class with a native method, a static block to load a library named Project1 and a main, which creates the instance and sends método.Y call now just compile the class: javac HelloWorld.java
 


Now we have to do is create a C header, which contains the definition of the role we have to implement, Java has a tool for this and then go to the command line again and type:
 

javah HelloWorld

Go to the folder where there was our class and we can see that there is a file called HelloWorld.h
 
/ * DO NOT EDIT THIS FILE - it is machine generated * / # include

/ * Header for class HelloWorld * / # ifndef _Included_HelloWorld


# define _Included_HelloWorld

# ifdef __cplusplus extern "C" {# endif

/ *
* Class: HelloWorld
* Method: sayHello
* Signature: () V
* / JNIEXPORT void JNICALL Java_HelloWorld_sayHello

(JNIEnv *, jobject);

# ifdef __cplusplus}


# endif # endif


This Header contains the definition of the function to be called the library, now we just have to create an implementation that will look more or less like this:

 

# include # include "HelloWorld.h"
# include
JNIEXPORT void JNICALL

Java_HelloWorld_sayHello (JNIEnv * env, jobject obj)

{printf ("Hello world Im a C Function \\ n");
return;}



And we have to compile it in a DLL, which is the part a bit tedious but if you've ever used a compiler for C or C + + has no big problem, you can use Borland Blodshed Dev C + + or Visual C + +. I compile with Blodshed Dev C + + and here are the instructions:

1 .- Once you have the file HelloWorld.h opens the Bloodshed Dev C + + and create a new project in the same folder where the file, the project type specified as DLL. (Here's because my dll is called Project1 haha)

2 .- Go to Tools-> Compiler Options, when you open the dialog box, go to the Directories tab and then to C + + Includes. (Or C includes the type of project you've created) Ahi click on the button that is like a doily, and go to where your Java is installed and add the following folders $ JAVA_HOME \\ include and $ JAVA_HOME \\ include \\ win32 , where $ JAVA_HOME = directory where you installed Java in my case: C: \\ Program Files \\ Java \\ jdk1.6.0_11, then my routes are as follows:
C: \\ Program Files \\ Java \\ jdk1.6.0_11 \\ include
C: \\ Program Files \\ Java \\ jdk1.6.0_11 \\ include \\ win32

3 .-. cpp file that automatically creates the IDE copy the following code:
 

# include # include "HelloWorld.h"
# include

JNIEXPORT void JNICALL
Java_HelloWorld_sayHello (JNIEnv * env, jobject obj)
{
printf ("Hello world Im a C + + \\ n");
return;
}

and go to Execute-> Compile , and your program should compile and generate a file named "Project1.dll" (or whatever you've placed the project.

Then just go to command line again and run: java

 
HelloWorld


And the result must be: Hello world
Im a C Function

And so you call a native function: D Congratulations!

I hope you have served

Greetings!

Best Cleaning Kit For Ar-15

SEPARATION-DIVORCE CONSULTATION

With this section we try to give a concrete solution and as accurate to the many questions that will arise in our relationship and we always wanted to know. If you want to know the answer to that question you just have to dejarnosla and seek a solution together. Thanks

How To Get A Homemade Trailer Title In Il



Well, as we begin to program in Java, there is always question: What is the Classpath? Well, it's very simple, as the name implies is the classpath that will be used to compile and / or run a program. And his role is to access classes outside the project, how some external library, there are two main ways to configure a Classpath, the 1st is to set an environment variable named CLASSPATH system, and there you go placing each of the folders or files *. jar we have. The 2nd is writing directly to the Classpath Compiling as a parameter to the compiler in this way:

 
javac-cp "PATH"
HolaMundo.java

Well now, to find a use, imagine that we have a standard library of classes the folder C: / lib, and there is the class "Libreria"

 
public class Bookstore {public static


void print (String message) {
System.out.println (message);
}}




Now imagine you want to use it in another program:
 

public class HelloWorld {public static void main
( String [] args) {

Library l = new Library ();
l.imprimir ("Hello World");
}}




order to compile this, we must tell the compiler the CLASSPATH, which will be used to compile the classes and for that we do this:

 
javac-cp "C: \\ lib"
HolaMundo.java

And also to run the program requires specifying the classpath in the same manner as otherwise get NoClassDefFoundError, because you will not find all the necessary classes. So what we do is very similar, except that this time we must also specify the path where we are and this is done with a "point":

 
java-cp "C: \\ lib;." HelloWorld


And with that we can run our class.


Greetings!

Monday, February 16, 2009

Bone Cancer In Dogs Neutropenia

Sending packets between VLANs accounts

order to send packets between VLANs have to make use of a Layer 3 device, either a router or Layer 3 Switch.

The configuration for a Cisco Router is:

Router # (config) interface f0/0.X & # 160, / / \u200b\u200b[interface.nú ; meroVlan]

Router # (config-if) encapsulation dot1q X / / [X = Number VLAN]

Router # (config-if) ip address address mask

must be configured interface f0 / 0 for each of the VLANs

Sunday, February 15, 2009

Non Lame Things To Write On A Wedding Card

Use Live ID email as a package

If we have any account other than "@ msn, @ hotmail, @ live" we can still have access to now the whole suite Live provides. To do this we must enter:

http://www.passport.net

We click the link where we can add an existing account, we ask our data, add and READY ! we can start using our email account (eg Gmail) to Live services.

NOTE: In the part of the password is not required that is the same password we use to access our mail, and remember that the same changes to the password of mail will not make changes to the Live ID password

Friday, February 13, 2009

Withdrawal Symptoms From Zeldox

Compiling java

When you compile a java file have to use the tool "javac" javac

Archivo.java

The problem we have when we have the files in packages and we have to compile these packages. We could compiilar file by file, but we would have problem if these files have references between them so it would compile in order specific files. To solve this we have to put in "root" of the project and apply the tool javac: javac

package / subpackage / *. java

This will compile all the files in that package without problems, without having to be compiled individually.

Thursday, February 12, 2009

Happy Birthday Wishes My Boss

Singleton: Singleton in Java Enhanced

Singleton, I presented in my previous entry is the most common implementation of a Singleton, but still has some defects, among them is that if we do that class serializable in every run would create different levels of singleton and would have to create a method to protect it. And we also have the problem that you can access the private constructor using the Reflection API. So here's a more elegant way to create a Singleton:




 


Singleton {public enum

INSTANCE;

public void doSomething () {}



}





And then when you would like to use, all you would have to do is this:


 

public class Main {public static void

main (String [] args) {
Singleton.INSTANCE.doSomething ();
}}






And with that we have a better and simpler implementation of a Singleton ensures that we will always be a single instance.
saludoss!



References:

Blooch, J. Effective Java 2nd Edition

Monday, February 9, 2009

21st Birthday Facebook Event Description



Well, a very general Singleton is an object which can only have one instance (ie we can only construct an object of that class during program execution). Schedule a Singleton in Java is very simple, all you have to do is prevent other classes have access to singleton constructor of my class, and how is that done? Well just have to make the private constructor, and then make a method that returns the only instance we created.


 
public class Singleton {


/ / THE ONLY INSTANCE TO BE CREATED
/ / SINCE THE CHARGE CREATING THE CLASS
private static Singleton instance = new Singleton ();


/ / DO THE BUILDER PRIVATE
/ / FOR INSTANCE CAN ONLY ITEMS FROM THE SAME CLASS
private Singleton () {}



/ / method to get the public
INSTANCE Singleton getInstance () {
return instance;}




}





In this example, the instance is created, since it creates the class, but sometimes it is better to create the instance until it is requested, then the code would be something like :

 
public class Singleton {



/ / CREATE THE REFERENCE
/ / EVEN TO TOP TARGETS NULL
private static Singleton instance;


/ / DO THE PRIVATE BUILDER
/ / so that only INSTANCE ITEMS FROM THE SAME CLASS
private Singleton () {}



/ / METHOD FOR THE INSTANCE
public Singleton getInstance () {
if (instance == null) / / If NULL
instance = new Singleton (); / / instantiate it
return instance;}




}



And with this Singleton create our class, and then we can schedule additional methods that are services to be offered. Greetings

Sunday, February 8, 2009

How To Make 1 Inch Billiards Triangle

Delete Files with Java Introduction to ANT

order to delete files from hard disk, we must first make a File class java.io.File file =

 java.oi.File ("String with the path"); 
file. delete ();



This method We return a boolean if he could erase.

In case we need to create temporary files are erased when you finish the program, we can use another method of the class file.


 java.io.File file = java.oi.File ("String with the path"); 
file.deleteOnExit ();



This method is void, because as it is not instantaneous secure file deletion. The files are erased when the program is called closure.

Monday, February 2, 2009

Why Does My Testical Go Up Into My Abdomen



Level: Intermediate

ANT is a tool used when doing a project programming and must be repeated repetitive tasks such as compilation and construction. Ant is written in Java and is very similar to Make, but with the advantages of being platform and not dependent on the operating system instructions, but is configured with XML files. ANT is an open-source project of the Apache Software Foundation.

OK to start using ANT, the first thing to do is download page for apache can write to google ANT and will be one of the first results, but here's the link:

http://ant. apache.org / bindownload.cgi

Once you've downloaded ANT, unzip the arcihvo, go to the / bin and add that directory Computer to PATH, so in this way, you can easily call and not have to type the complete path from the command line. You probably have some problems with the name of the folder, points and hyphens, what I did was change the name of the folder and so I was so PATH: C: \\ ant \\ bin. Also you need to have at least Java 1.4. Finally, to verify that you did well written in a command line (MS-DOS). Ant-version

And if you set it then you'll see information about the version of Ant you've downloaded, but is properly configured will tell you that ant is not a recognized command.

Well, now if we are to use the ANT: D. As I mentioned ANT is a tool for processes that need to be repeated many times when we are developing a project, how for example be compiled and we have a good organization directories, and we want to separate our source files already compiled. And also will automatically generate a jar to run.

ANT To all we have to do is create an XML configuration file which will contain instructions that is what we do. In ANT we have set a target, which is next to be executed and then the tasks that we want to do when you select that goal. Well to start, we will establish a new project, create a folder called introduccionant, and that will put two files:

HolaMundo.java (The file that we compile and run with ant) \u200b\u200bbuild.xml
(The configuration file ANT)

HolaMundo.java
 public class HelloWorld {public static 

void main (String [] args) {

System.out.println ("Hello World");}





} build.xml

 

basedir = "."
default = "compile">


debug = "true"
deprecation = "false"
optimize = "false"
FailOnError = "true">






first define a project, give it a name, we put the base directory, in this case is the same and we are putting the "." and Target which by default will run is to build name.

After that we must define the target, which has compiled name (the default) and then placed the tasks we perform, in this case we just want to call javac to compile files, our target directory will be the same and also put some additional options. Also when using javac, it is imperative that we have defined where the source files that define the source directory also in this case and for simplicity is also the same.

Now all you have to do is go to a command line introduccionant go to the directory and run the command:

ant

After this the result will say that the build has been successful and those who have used NetBeans, see the console output is equal to the IDE, this is because NetBeans uses Ant to do the build of our projects. And if you go to the directory using Explorer you will see your file. Class has been created and can write in the command line:

java HelloWorld

Linea de Comandos con Ant

Well with that we our first program compiled using ant, now all you have to do is add more options to our build.xml file so we can get more done using ANT.

Greetings