PHP
  Home arrow PHP arrow Page 3 - Using PHP with Java
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Using PHP with Java
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2002-04-03

    Table of Contents:
  • Using PHP with Java
  • Getting Started
  • Rank And File
  • A Custom Job
  • Passing The Parcel
  • An Exceptionally Clever Cow
  • Beanie Baby

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using PHP with Java - Rank And File


    (Page 3 of 7 )

    Let's begin with a simple example to verify that everything is working as advertised. This script uses built-in Java methods to check for the existence of a particular file on your system and display its size.

    <?php $fp = new Java("java.io.File", "/home/john/test.txt"); if($fp->exists()) { echo "The file ". $fp->getAbsolutePath() . " is ". $fp->length() . " bytes"; } else { echo "The file " . $fp->getAbsolutePath() . " does not exist"; } ?>
    This is fairly simple, and should be clearly understandable to anyone who knows basic Java programming. The first line of the script instantiates an object of Java's File class, and stores it in the PHP variable $fp.

    $fp = new Java("java.io.File", "/home/john/test.txt");
    In case you're wondering, it's possible to pass parameters to the class constructor by specifying them as arguments when creating the object. In the example above, the second argument to the class constructor contains the location of the file to be displayed.

    Once the object has been instantiated, it becomes possible to access the methods and properties of the Java class using regular OOP syntax.

    if($fp->exists()) { echo "The file ". $fp->getAbsolutePath() . " is ". $fp->length() . " bytes"; } else { echo "The file " . $fp->getAbsolutePath() . " does not exist"; }
    In this case, the exists(), getAbsolutePath() and length() methods are all methods of the File class; however, I've managed to use them in a PHP script by virtue of the Java connectivity built into PHP.

    Here's what the output of the script above looks like:

    The file /home/john/test.txt is 385 bytes

    More PHP Articles
    More By Harish Kamath, (c) Melonfire


     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway