| home / infca / java (navigation links) | Excusi'm que no m'aixequi ... |
| EJB | MDB | Singleton | LAMP | GUI | Links | End |
Intro CLASSPATH RedBooks
|
Sun says : (Abr/2005)
Download JSE 5.0 [***] Java SE, JDK o JRE.
The J2SE Development Kit (JDK)
supports creating J2SE applications.
P4 - XP - JDK-1_5_0_02-WINDOWS-i586-p.exe install ( 14/4/2005 )
Instala J2SE Development Kit 5.0 Update 2
Destination : c:\Program Files\Java\JDK1.5.0_02 ( i c:\PF\Java\JRE1.5.0_02 )
PATH :
**** T30 : E:\Program Files\Java\jdk1.5.0_02\bin; ****
Documentació : 43,5 MB.
Open the docs/index.html page in a browser.
This is the front page and table of contents of the JDK documentation.
**** P4:\C:\Program Files\Java\DocuJ2SE5.0 ****
**** T30:\e:\Program Files\Java\docs\index.html ****
JAVADOC JSE 1.5, JAVADOC JEE 1.4. Linux
rpm -ivh j2re*.rpm JAVA_HOME=/usr/java/jre1.5.0_03 export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH export PATH Now, if you want to be able to execute this version of Java interpretor or compiler from any directory on your Linux system you will have to create a few symbolic links:
|
|
Test your Java Runtime Environment
|
|
|
CLASSPATH
The CLASSPATH is an environment variable that tells the Java compiler javac.exe where to look for class files to import or java.exe where to find class files to interpret. Així, apunta a directoris amb fitxers "nom.CLASS". There's a variation when using JAR files, however. You must put the name of the JAR file in the classpath, not just the path where it's located. Així, també hi ha fitxers del tipus "nom.JAR" |
|
CLASSPATH, PACKAGE and directories
If in file sebas.java I code package com.ibm.zip;, and CLASSPATH contains c:\misclases; then file sebas.java must be placed in c:\misclases\com\ibm\zip so javac or java can reach it. Also, if we are situated at c:\sebas >, and sebas.java has package a.b.c;, then we have to place sebas.java in c:\sebas\a\b\c\ and call (from c:\sebas >) javac a\b\c\sebas.java and java a.b.c.sebas (.class). |
|
How to set CLASSPATH
The lists are delimited by a colon ":" with Linux and Unix, and a semicolon ";" with Windows. You probably do not want to reassign their values but rather want to append them. To do this: Linux/Unix type: export CLASSPATH=$CLASSPATH:/path/to/program
Windows type: set CLASSPATH=%CLASSPATH%;C:\path\to\program
java.lang.NoClassDefFoundError
¿ Cómo se carga una clase ? Cuando se intenta ejecutar una clase, o acceder a ella durante la ejecución de un programa, la máquina virtual de Java debe cargar la clase. Para ello, necesita acceder al fichero compilado para la clase (el nombre de la clase con extensión .class, por ejemplo, MiClase.class). Para ello, busca este fichero entre las clases estándar de Java, y en todos los directorios establecidos en la variable de entorno CLASSPATH. En las últimas versiones de Java, si la variable CLASSPATH está vacía, busca también los ficheros en el directorio en el cual se está ejecutando la máquina virtual. Si no encuentra la clase, la máquina virtual lanza la excepción java.lang.NoClassDefFoundError. Exemple miHola.java
c:\MyJavaDir> dir
16/12/2012 13:07 <DIR> ABC
16/12/2012 13:07 404 FER.cmd
On FER.CMD conte: c:\MyJavaDir> type FER.CMD
cd ABC
javac Hola.java
cd ..
java ABC.Hola
Si el codi es: c:\MyJavaDir> type .\ABC\Hola.java
package ABC ;
public class Hola {
// main method begins execution of Java application
public static void main ( String args[] )
{
System.out.println( "Welcome to SAG Java Programming !" ) ;
} ; // end method main
} ; // end class Hola
El resultat es: c:\MyJavaDir> java ABC.Hola
Welcome to SAG Java Programming !
How to fix "java -version" (win) problems
SET PATH=$/jre/bin;%PATH%
|
|
Diferencia Applet - Aplicación
Dejando de lado las restricciones de seguridad,
An applet is a Java program that runs on a Web page. An applet is not a stand-alone application, and it does not have a main() routine. In fact, an applet is an object rather than a class. When an applet is placed on a Web page, it is assigned a rectangular area on the page. It is the job of the applet to draw the contents of that rectangle. When the region needs to be drawn, the Web page calls a subroutine in the applet to do so. An applet is a Java application that's designed to run in a browser window on an Internet user's computer. When an Internet user visits a Web page that contains an applet, the Java applet class is downloaded to the user's computer and run there. The applet takes over a portion of the page and, within that space, can do anything it wants. |
|
Características
|
|
Class and File naming rules
(from
here)
A class name must start with a capital letter. The source for that class must live in a plain text file with the same name (including case), with a *.java extension. So, filename must be "Classname.java" You cannot put more than one public class inside a *.java file. Classes in the same package are accessible to each other, even if they are in different files. To access other classes, you must import them.
The source code must be stored in a directory
with the same name as the package declared at the top of the file,
including case, with the dots replaced by \ or /
or whatever your platform uses for directory element separators.
Package names must be lower case, usually beginning com.yourwebsite to
ensure global uniqueness.
"JAVAC Name.java" produces "Name.class"
"JAVA Name" (.class is ommitted) runs the main method.
The -verbose flag is quite interesting ... but talks A LOT !
|
|
"TIJ", chapter 5 :
When you say: package mypackage;at the beginning of a file, where the package statement must appear as the first noncomment in the file, you're stating that this compilation unit is part of a library named mypackage. Or, put another way, you're saying that the public class name within this compilation unit is under the umbrella of the name mypackage, and if anyone wants to use the name they must either fully specify the name or use the import keyword in combination with mypackage (using the choices given previously). Note that the convention for Java packages is to use all lowercase letters, even for intermediate words. It's worth keeping in mind that what the package and import keywords allow you to do, as a library designer, is to divide up the single global name space so you won't have clashing names, no matter how many people get on the Internet and start writing classes in Java. Sample : in (1)
Direccion.java contains package com.ibm.sebas; and public class Direccion ... Estancia.java has import com.ibm.sebas.Direccion; and uses Direccion as public void setSalida(Direccion direccion, Estancia vecina) ... The rest of the PATH in (1) is placed in CO.BAT (and RU.BAT), as set CLASSPATH=c:\sebas\java\Gustavo\src;%CLASSPATH%;
|
|
Usual errors
Exception in thread "main" java.lang.NoSuchMethodError: main
Estamos tratando de ejecutar una clase "Prueba"
a la que no le hemos añadido el método main
java.lang.UnsupportedClassVersionError: SimplePolygons (Unsupported major.minor version 49.0)
JDK is 1.5, while JRE is 1.4 - update JRE. URL ? |
|
SDK
Interface BytesMessage
|
|
From
http://mindprod.com/jgloss/javacexe.html :
If you recompile A, and A depends on B (which has not changed) and B depends on C (which has changed), Javac will not recompile C, if you invoke it on A. |
|
Under W2K WF (VMware at T30),
JAVAC and JAVA
are located at
Under T42/XP VM it is at "c:\Program Files\IBM\Java142\bin" |
|
javac syntax
c:\> javac -help
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-help Print a synopsis of standard options
|
|
Java and WSAD
|
|
Java links
|
|
|
|
Sun tutorial : URL. Ver Links en la última página ... |
|
On-line book : URL
On-line book exercices :
URL
Curs sencer : (1,6 MB) URL - also \\Java\LlibresJava\Curs1 ! |
|
AppletViewer |
|
Tips
Using Applet Viewer the Easy way (URL) To test your applets using the applet viewer, put the following comment in your Java file: // <applet code=AnApplet.class width=200 height=200> </applet> Then you won't need an HTML file for your applet code. The applet viewer will parse the applet tag and display the applet. Now, you can test it your applet by typing this at the prompt: appletviewer AnApplet.javaBehrouz Fallahi
Maps projection
url
|
|
Applet links
|
|
Applet repository - Working & Source
All open in a new window
Dibuixem polígons - run
Simple Polygons applet -
OK
25 boles movent-se - run
Ballistic Balls applet -
OK
V 1-5 here - run Ballistic Balls v 1.5 applet -
Random position text
Simula vida - run
LifeApplet applet -
OK
Dibuixem un arbre - run
Tree applet -
OK
Cercles de colors - run
ColorCircles applet -
OK
Traffic Control -
url
Origin URLs :
Location :
|
| Servlets are Java applications that are executed on a server. Unlike applets, which are executed on a client, servlets have much more access to network and disk resources. Unlike CGI scripts, servlets don't require a separate process for each connection. |
|
java MQIVP - located at \\t30\E:\MQ\Tools\Java\base
To trace the MQIVP program, enter : java MQIVP -trace n
|
| BPEL | Business Process Execution Language |
| EAR | Enterprise Archive (JAR = Java Archive, WAR = Web Archive) |
| EJB | Enterprise JavaBeans [url] |
| J2EE | Java 2 Enterprise Edition (rival to .NET) |
| JDB | Java Debugger |
| JNDI | Java Naming and Directory Interface |
| MDB | Message Driver Bean |
| POJO | Plain Old Java Object |
| SOAP | Simple Object Access Protocol |
| XML | data type for Java |
| WSDL | Web Service Definition Language - url |
A JavaBean is a special type of Java class that you can use in several interesting ways to simplify program development. Some beans, such as Swing components, are designed to be visual components that you can use in a GUI editor to quickly build user interfaces. Other beans, known as Enterprise JavaBeans, are designed to run on special EJB servers and can run the data access and business logic for large Web applications.
In this chapter, I look at a more modest type of JavaBean that's designed to simplify the task of building Java Server Pages. In a nutshell, you can use the simple JavaBeans to build Java Server Pages without writing any Java code in the JSP itself. JavaBeans let you access Java classes by using special HTML-like tags in the JSP page.
What Is a JavaBean?
Simply put, a JavaBean is any Java class that conforms to the following rules:
REMEMBER - The property name is capitalized in the methods that access it, but the property name itself isn't. Thus setAddress sets a property named address, not Address.
That's all there is to it. More advanced beans can also have other characteristics that allow them to have a visual interface so they can be used drag-and-drop style in an IDE. And some beans implement an interface that allows their state to be written to an output stream so they can be re-created later. But those features are optional; any class that meets the three criteria stated here is a bean and can be used as a bean in JSP pages.
You've already seen plenty of classes that have methods with names like getCount and setStatus. These names are part of a design pattern called the Accessor pattern, which is covered in Book III, Chapter 2. Thus you've seen many examples of beans throughout this book, and you've probably written many bean classes yourself already.
REMEMBER - Any class that conforms to this pattern is a bean. There's no JavaBean class you have to extend, nor is there a Bean interface you have to implement to be a bean. All a class has to do to be a bean is stick to the pattern.
Java All-In-One Desk Reference For Dummies, Doug Lowe and Barry Burd.
Enterprise Java Bean (EJB) is a managed,
server-sided component
for modular construction of enterprise applications.
The EJB specification is one of the several Java APIs in the Java Platform, Enterprise Edition.
EJB is a server-side component that encapsulates the business logic of an application.
Accordingly, the EJB specification details how an application server provides:
Additionally, the Enterprise JavaBean specification defines the roles played by the EJB container and the EJBs as well as how to deploy the EJBs in a container.
An EJB container can hold three major categories of beans:
Stateless Session Beans are distributed objects that do not have state associated with them thus allowing concurrent access to the bean. The contents of instance variables are not guaranteed to be preserved across method calls. The lack of overhead to maintain a conversation with the calling program makes them less resource-intensive than stateful beans.
Stateful Session Beans are distributed objects having state, that is, they keep track of which calling program they are dealing with throughout a session.
Entity Beans are distributed objects having persistent state.
Message Driven Beans are distributed objects that behave asynchronously, that is, they handle operations that do not require an immediate response. These beans subscribe to JMS (Java Message Service) message queues or message topics. They were added in the EJB 2.0 specification to allow event-driven processing inside EJB Container. Unlike other types of beans, MDB does not have a client view (Remote/Home interfaces), i.e. clients can not look-up an MDB instance. It just listens for any incoming message on a JMS queue (or topic) and processes them automatically.
EJBs are deployed in an EJB container within the application server. The specification describes how an EJB interacts with its container and how client code interacts with the container/EJB combination.
Because these are merely Java interfaces and not concrete classes, the EJB container must generate classes for these interfaces that will act as a proxy in the client. Client code invokes a method on the generated proxies, which in turn places the method arguments into a message and sends the message to the EJB server.
A Message Driven Bean (MDB) is an Enterprise JavaBean (EJB) similar to a session bean, except it responds to a JMS message rather than an RMI event. MDBs were introduced in the EJB 2.0 specification which is supported by Java 2 Platform, Enterprise Edition 1.3 or higher. The message bean represents the integration of JMS (Java Message Service) with EJB to create an entirely new type of bean designed to handle asynchronous JMS messages.
Most commonly, you implement a singleton in Java by having a single instance of the class as a static field. You can create that instance at class-loading time by assigning a newly created object to the static field in the field declaration :
Alternatively, you can instantiate it lazily, on first demand. You keep the constructor private to prevent instantiation by outside callers.
Implementing the Singleton Pattern in Java :
Una altra descripció :
Paco : IE ( http://localhost:9080/Snoopy/SnoopyTestServlet )
|
public void service(ServletRequest arg0, ServletResponse arg1) throws
ServletException, IOException {
// TODO Apéndice de método generado automáticamente
arg1.getOutputStream().print("<HTML>");
arg1.getOutputStream().print("<HEAD>");
arg1.getOutputStream().print("<TITLE> Pagina Snoop d'en Sebas i en Fernando. </TITLE>");
arg1.getOutputStream().print("</HEAD>");
arg1.getOutputStream().print("<BODY>");
arg1.getOutputStream().print("<HR>");
arg1.getOutputStream().print("Que passa Sebas ! Com estas ?");
arg1.getOutputStream().print("<HR>");
arg1.getOutputStream().print("Properties List es : <BR>");
System.getProperties().list(new PrintStream(arg1.getOutputStream()));
arg1.getOutputStream().print("<HR>");
arg1.getOutputStream().print("JAVA.CLASS.PATH es : <BR>");
arg1.getOutputStream().print( System.getProperties().getProperty("java.class.path"));
arg1.getOutputStream().print("</BODY>");
arg1.getOutputStream().print("</HTML>");
}
|
JJ : IE ( http://localhost:9080/Snoopy/SnoopyJSP.jsp )
System.out.println("HOLA. +++ Voy a buscar SnoopyJSP.jsp ...");
arg0.getRequestDispatcher("SnoopyJSP.jsp");
System.out.println("HOLA. --- He vuelto de buscar SnoopyJSP.jsp ...");
|
SnoopyBean.java :
public class SnoopyBean {
/*
* ...
*/
public SnoopyBean() {
super();
// TODO Apendice de constructor generado automáticamente
}
public String getText() {
System.out.println("HOLA. +++ Voy a retornar un String ...");
return "El Paco es collonut ... (version DEMO) ";
}
|
SnoopyJSP.jsp :
</HEAD>
<f:view>
<BODY>
<jsp:useBean id="SnoopyBean" class="pagecode.SnoopyBean" scope="page">
</jsp:useBean>
<jsp:getProperty name="SnoopyBean" property="text"/>
<p> Hola Sebas !
<P> Fet per en Paco el 2 del 3 de 2006.</P>
</BODY>
</f:view>
</HTML>
|
Abans :
Després :
Que es configura passant-li paràmetres a la JVM :
JVM arguments are used for configuring how the JVM executed. Any changes to JVM arguments needs restart of that JVM.
WebSphere Application Server 7.0
WebSphere Application Server 6.1
WebSphere Application Server 6.0
Gracias, Francisco !
Uns quants tutorials que poden ser d'interès ...
A few years ago I worked on a very big Enterprise IBM Websphere project. We had some brilliant engineers in the project both in the development and architecture groups. I remember having had several discussions with some of the brightest people on the team regarding PHP and dynamic languages and generally they were looked upon as toy languages without a bright future. Lack of strict typing, scripting performance, and other reasons were given for why Java would persevere as the language of choice.
This was the typical reaction dynamic languages would get from the Java community. There were many believable reasons for why these languages, especially the ones gaining fame on top of the LAMP stack, would not last. However, one thing which the Java community ignored for many years was the radical shift to the Web, not only for media and e-commerce Web sites but for a large majority of business applications including CRM, ERP, reporting, document management, etc As a result Java EE (then called J2EE) was not built with the Web in mind but rather focused on enterprise integration, transaction management and other back-end processing. While Java EE has long supported Web development with servlets and JSP the companies driving the standards ignored the RESTful nature of the Web and rather continued to drive a general purpose platform.
In parallel, the LAMP-like architecture built on top of the C language's eco-system of libraries and tools started becoming the most popular platform for developing Web applications. This trend grew in the second half of the 90s and with a recession following the burst of the .com bubble it greatly accelerated due to the lower TCO that the LAMP solutions had to offer. While there are a variety of dynamic languages which make up the LAMP development and deployment paradigm, the most ubiquitous language has been PHP. As a result of PHP being domain specific to the Web it has been shaped in a way which makes it fit the Web paradigm like a glove. By focusing on solving the common Web patterns quickly and easily it holds the biggest market share on the Web. In two separate surveys of one of the most popular Ajax Web sites, the Ajaxian.com, around 50% of Rich Internet Applications developers are using PHP. The trend has also been significantly accelerated as a result of the many popular PHP packages including Wordpress, Drupal, mediaWiki, osCommerce, SugarCRM, and more
When it became apparent to the large Java vendors that the Web paradigm was being built and innovated without Java they started backing a variety of both standards and non-standards driven Java Web application frameworks which promised to adapt Java to the Web. Such frameworks included Java Server Faces, Struts, Spring MVC and others. Some of these frameworks have been more successful than others but in general none of them managed to resolve one of Javas main pain points on the Web. The strict typing and overly complex architecture of Java applications meant longer development times and a need for more skilled engineers in order to push Java applications into the market, i.e. Java's TCO on the Web was unsatisfactory.
In the meanwhile the large Java vendors were trying to hold the stick at both ends. On one hand trying to be part of the Web paradigm shift and on the other hand protecting their multi-billion dollar businesses built on the Java language. Even the pervasiveness of dynamic languages in the Web space didn't change the vendor's behavior significantly. The big change came when Microsoft aggressively pursued a multi-language runtime environment for the .NET platform. Not only did they support C# and VB on their virtual machine but they worked with their developer community to add a large amount of languages including Cobol, Eiffel, Ruby, Python, and others. As dynamic languages continued to grow to the point where industry analysts started defining categories (e.g. Forrester Research on dynamic languages) Microsoft continued to leverage their common runtime which was designed from the get go to support multiple languages.
As mentioned earlier the de-facto standard implementations of the successful dynamic languages including PHP, Perl, Python and Ruby are all written in C and leverage the breadth and depth of the eco-system of C libraries. As community driven projects these languages do not have a specification nor is their development hindered by corporate bureaucracy. On the contrary, these languages are being developed by their users who have only one end goal get the job done, quickly As a result the languages are constantly evolving often adding significant enhancements in minor releases. With the rapid changes in how modern Web applications are being built and deployed this agile nature is a must-have to keep up with the latest trends.
In addition, the LAMP deployment paradigm has significant advantages. By featuring a multi-process architecture, faults in the Web Server and dynamic language software will typically not lead to sites going down. While one process may crash all other processes serving Web requests will continue running. This is in contrast to multi-threaded environments like the JVM (Java Virtual Machine, Java's execution environment) where software faults including crashes and deadlocks will typically lead to system down situations. In addition, the ability to recycle processes after a set time will prevent memory leaks and memory fragmentation, two common software memory problems, from degrading the system efficiency over time. Another key advantage LAMP developers enjoy is the easy deployment paradigm. Software updates can easily and incrementally be pushed out to LAMP servers without requiring prolonged build and packaging processes. While this may lead to unorthodox and sometimes too lax of a process, when done correctly it makes the lives of the developers and the operations personnel much easier.
While LAMP's growth was fueled by many of these development and deployment advantages, the Java vendors were stuck with the JVM which was very closely aligned to the Java language and had little support for targeting multiple languages. Instead of shifting towards a loosely coupled model of LAMP technology and Java technology in order to deliver the best of both worlds to their customers, most hesitated to lose control over the customer's workload and entered an arms race to deliver dynamic languages on top of the JVM. With Microsoft on one side and the Java competitors on the other, each vendor set out to develop their own dynamic languages strategy.
Today Sun is investing in JRuby (Ruby) and Jython (Python) support for its Java EE solution; the IBM Websphere group has realized the ineffectiveness of the Java EE platform for running modern Web workloads and has invested heavily in Project Zero which aims to make big blue a Web 2.0 player and initially delivers support for Groovy and PHP; BEA has also had some incubation projects going but with the upcoming sale to Oracle it is unclear whether any of those efforts will materialize. Project Zero's Chief Architect is one of the first IBMers to admit in public that Java today can be considered as a system language and is not desirable for building RESTful Web applications which is Project Zero's goal (slide #4 of the presentation- see slide #11 to see how a simple "Hello, World" in Java compares to dynamic languages like Groovy and PHP). It has taken over 10 years for the Java stronghold to admit Java's poor ROI on the Web and with the current recession it is likely that many Java customers are going to be making more informed investments. As a result there will be considerable rise in uptake of dynamic languages. Similar to the mainframe Java is heavily entrenched in enterprise IT and business-critical applications and is therefore not going away. That said for fueling modern Web applications the Java language will likely see a steep decline in market share.
The question to be asked is whether the non-Microsoft Web market will buy into the JVM implementations of dynamic languages or whether they will move to the LAMP stack which hosts the de-facto standards for the most popular languages. While I believe there will be customers who are attracted to the JVM implementations especially the ones who are heavily influenced by their relationships with the Java companies, the majority of the market is going to prefer to go down the route of the LAMP stack. Reasons include:
In conclusion, it is becoming clear that dynamic languages are going to increasingly become the standard for Web development. Microsoft and the Java vendors have all recognized this trend and are now aggressively pursuing solutions on top of their software stacks. However, as the core dynamic language communities thrive outside of the .NET CLR and Java JVM software stacks the vendors will be in a challenging position if they solely depend on the uphill battle of cloning the successful dynamic languages onto their software stacks. Some vendors are aware of this challenge and have built hybrid strategies which also aim to deliver the de-facto standard dynamic languages to their customers even if they don't have full synergy with their solution stack, this includes Microsoft's investment in making PHP work with their solution stack and Sun's initial attempts to deliver native Ruby and PHP implementations to their customer base. I believe that while the JVM approach to dynamic languages may appeal to some Java customers it will never be able to catch up with the broader open-source movement around native dynamic languages implementations. The JVM dynamic languages implementations will not be enough for the Java vendors to catch up and they will need to embrace the native de-facto standard community driven dynamic languages.
posted by Andi Gutmans @ 3/24/2008 11:07:00 AM
We have detected you may be viewing this page in a 32-bit browser. If you use 32-bit and 64-bit browsers interchangeably, you will need to install both 32-bit and 64-bit Java in order to have the Java plug-in for both browsers.
Verify installed Java
You forgot to include the .java suffix when compiling the program. Remember, the command is "javac HelloWorldApp.java" not "javac HelloWorldApp"
El fitxer es diu SimplePTP i dintre porta
Add the location of your .class file to your classpath
Jython script to create a server, file create_server.py
Execute it using wsadmin:
Jython Script to check the status of listener ports of all servers of cluster
Com es fa per a que corri com un Applet ?
public class JMSTestApplet extends javax.swing.JApplet
Com es fa per a que corri as an Application ?
public static void main(java.lang.String[] args)
Identifying classpath conflicts & A general tool for resolving classpath questions
What was needed was a simple, non-intrusive way to ask a running WebSphere instance from what JAR file a particular class was being loaded at run time
\\Java\Classpath_Problems
Java 1 .. 5
|
|
Site under construction. |
|
Updated 20141209 (a)
|
|