Java Queries Here..

Pathik

Google Bot
Is there any API I can use to create apps that use Bluetooth on PCs? I am not talking of the Java ME JSR 82 API. I need something which I can use with a bluetooth dongle. Thanks.
 
OP
furious_gamer

furious_gamer

Excessive happiness
Is there any API I can use to create apps that use Bluetooth on PCs? I am not talking of the Java ME JSR 82 API. I need something which I can use with a bluetooth dongle. Thanks.

AFAIK There is no such API to create apps for bluetooth except the J2ME API u mentioned.... (Correct me if i am wrong...)
 

chandru.in

In the zone
There are implementations of JSR-82 for Java SE. Have a look at bluecove project *code.google.com/p/bluecove/

Note: bluecove does not pass the TCK for JSR-82 due to deficiencies in WIDCOMM stack. *www.bluecove.org/tck/

If you are interested in commercial APIs, *www.javabluetooth.com/development_kits.html
 

Plasma_Snake

Indidiot
Does SUN provides detailed help files for JAVA like MSDN? Where? Please
I don't have detailed Java knowledge, just ur ordinary n00b but I want to try my hand at Game programming in Java and got e-book "Killer Java Game Programming" I'm just on its second chapter and my head is already cartwheeling and flipping. :-?
I want to know what tools I need exactly. I've following installed:

  1. Netbeans 6.1 (full 219MB one)
  2. Java3d-1_5_1
  3. Java_ee_sdk-5_05
  4. Jdk-6u7-windows-i586-p
What more do I need? I type just following lines and get the following error:
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;

import com.sun.j3d.utils.timer.J3DTimer;
In the last Import statement I get the following error "package com.sun.j3d.utils.timer does not exists"
This code I'm trying to compile and run is given as verified runnable as given and mentioned by author of the book. I'm just trying to code it again for the sake of my understanding. Please tell me whats wrong and help me please. :cry:
 

Bandu

Journeyman
I am not sure how MSDN help looks like. I've this page bookmared for Java: *java.sun.com/j2se/1.4.2/docs/api/

As far as your installation goes, I think you have pretty much everything you need. For beginners, however, I still recommend starting out the harder way - using simple tools like Editplus and such so that you get a complete understanding of how things work in Java - classpaths, etc. Using IDEs (like Netbeans) make the whole thing transparent to the developer. It's important to get an understanding of such things. It would help if you start out with simpler programs before jumping into advanced topics like awt, swing, etc.

For the error, make sure that you have your classpath set correctly. You probably are missing a jar file or two in the classpath. I am not sure which, but should be some j3d.jar or some 3d.jar file. Try looking for such a file somewhere in your installations and if you find it, append its path to the CLASSPATH variable.

- Bandu.
 
Last edited:

chandru.in

In the zone
I'd echo Bandhu but with a link for more recent Java release ;) *java.sun.com/javase/6/docs/api/

Regarding cartwheeling and flipping, that's what is bound to happen when you try to ride a Ducati at full throttle when you haven't yet learnt to balance a two-wheeler. :p

Put aside the book you have and get "Head First Java". Once you are crystal clear with the basics of Java programming, come back to your current book. Good luck with your adventures in Java.
 

Plasma_Snake

Indidiot
Well if u see earlier posts in this thread, I've done Java in my college in 5th Semester and 3 times in my local NIIT center so basic topics like Array, Inheritence, Overloading and Overidding are clear to me but things like Swings and Threads are what that need more practice and I seriously need to learn Java I/O ops and classes 'cause I personally feel that without it Java learning is useless.
 

chandru.in

In the zone
I didn't mean to be rude with the ducati example. I'm sorry if you had felt so.

Multi-threading is an absolute must for any Java programming. JVM,s extraordinary concurrency capabilities is what makes it such a valuable platform on servers. Concurrency is also mandatory for game programming. So, I'd suggest that you focus on Threading and it subtleties before going into full-fledged game programming.
 

Plasma_Snake

Indidiot
I wasn't offended at all, I was just giving my history with Java so as to let u know my level of Java understanding. I PMed the mods and look, the Thread now is Sticky :)
Now the question part, as mentioned by me in my earlier post I've Java 3D installer and installed it too. Now please tell me how can I use the packages and classes of this Java3D in my Netbeans or programs that I create i.e. incorporating it in Java SDK? :confused:
if I'm not wrong, the error that I was getting in one of my earlier posted problem was mainly because Netbeans wasn't able to find the mentioned package of Java 3D in its libraries or am I still missing the point? :-?
 
Last edited:
OP
furious_gamer

furious_gamer

Excessive happiness
@Plasma_Snake:
Netbeans wasn't able to detect Java 3D.... And AFA Swing and related stuffs, go thru some books like Swing Cook books and etc to get good knowledge on it.... Swings are not so tough as Java basics and once you get good knowledge in basics then swings is nothing to learn, except the API... And I/O, better learn from Head first and try some online tutorial...
Best way is try some examples urself and if u have any doubt post it here...
 

Faun

Wahahaha~!
Staff member
here is one query;

Suppose I have scanned an image and want to know its lenght and breadth. Will it be possible to get the original length and breadth irrespective of the dpi at which its scanned.

I'm able to get the resolution of an image.

Guide me...if there is some way.
 

Desi-Tek.com

In the zone
youtube's comment system is now powered by java (servlet)!

Code:
*in.youtube.com/comment_servlet?all_comments&v=GvctSMHHd7g&ytsession=p9A_Dz6f8kXK5uX7c4IxRXCHB9HQut1nIGY5pSuqgGeeKrFz1pYtma0JOAMlINEJELSf9R85VAbMqGZhLjBDGw-Jg8LGV1e2C3ZTLwiHnz5f7eHpk5aIrfFVkmJksyn4pw4ur6twt4OoW7N8aRmBD58Ft-kefWBBDA3BsU4PJ7IrnfR5Jd-HXVRcOI_fnGg1GAXU8k0OCbr-I024_h6l0AL3TaaGGAFdED_egjgErjDuWe3e_-R89fqmuZ8a8-hn-wnsNIl-O5BqZT26bLzr1wCK2f4V76Z_dO7xfKe7BQQ
 

Desi-Tek.com

In the zone
how to read value from custom annotation?
for example if i have cuustom annotation
@Permission(name="ADMIN")

how can i read the value admin during run timer?
 

Bandu

Journeyman
^Thanks to you, I learnt something new in Java 1.5 today. But, unfortunately not enough to answer your question. You might want to look into com.sun.javadoc, JSR-269 (Pluggable Annotation Processing API), and the new 1.5 reflection API.

If you do find an answer, please post a small example and solution if possible.
 

chandru.in

In the zone
@Desi

If Permission is a custom annotation defined by you, set its retention policy to RUNTIME. Here is a complete sample code.

Code:
package demo;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Permission {
	String name();
}

Code:
package demo;

public class Main {
	public static void main(String[] args) {
		Demo demo = new Demo();
		Permission permission = demo.getClass().getAnnotation(Permission.class);
		System.out.println(permission.name());
	}
}

@Permission(name = "ADMIN")
class Demo {

}
 

Desi-Tek.com

In the zone
hi is it possible to separate model from jsf's managed bean? in struts 2 we use ModelDriven interface to achieve that.

Struts example

Model
Code:
/**
 * User Model 
 **/
public class User {

    
    private String username;
    private String password;
    private int age;
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
Struts 2 acton
Code:
/**
 * Action 
 **/
public class Login extends ActionSupport implements ModelDriven<User>{

    
    private  User user;

public User getModel() {
      
        return user;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
    
    // Acton
    
    public String login (){
        return "outcome";
        
    }
    
    
}
mapping
Code:
<package name="user" extends="struts-default">
        <action name="login"
            class="com.desitek.cricket.action.Login">
            <result name="input">index.jsp</result>
            <result name="success">index.jsp</result>
            <result>index.jsp</result>
        </action>
    </package>
and jsp
Code:
 <s:actionerror/> <s:actionmessage/> 
     <s:fielderror></s:fielderror>
     
     <s:form action="login" theme="simple">
     User Name
     <s:textfield name="user.Username"></s:textfield>
     Password: <s:textfield name="user.UserPassword"></s:textfield>
      <s:submit value="login"></s:submit>
     </s:form>
 
Last edited:

chandru.in

In the zone
The same can be done in JSF too. However, unlike Struts JSF doesn't make you implement any interface. I guess your mapping is out of sync with your code. So my example may not exactly reflect your requirements.

For JSF, this is how your Login class would look.
Code:
public class LoginAction {

    
private  User user;

public User getModel() {
      
        return user;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
    
    public String login (){
        return "outcome";
    }    
}

Managed bean and Navigation rule

Code:
<managed-bean>
		<managed-bean-name>login</managed-bean-name>
		<managed-bean-class>com.desitek.cricket.action.LoginAction</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>

	<navigation-rule>
		<from-view-id>login.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>index.jsp</to-view-id>
		</navigation-case>
		<navigation-case>
			<from-outcome>failure</from-outcome>
			<to-view-id>login.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
 

Desi-Tek.com

In the zone
i tried that but it is giving this error when i submitted the form

Code:
javax.servlet.ServletException: /login.jsp(35,2) '#{user.user.username}' Target Unreachable, 'user' returned null
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
[B]root cause[/B] 
org.apache.jasper.el.JspPropertyNotFoundException: /login.jsp(35,2) '#{user.user.username}' Target Unreachable, 'user' returned null
    org.apache.jasper.el.JspValueExpression.getType(JspValueExpression.java:61)
    com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:81)
    javax.faces.component.UIInput.getConvertedValue(UIInput.java:934)
    javax.faces.component.UIInput.validate(UIInput.java:860)
    javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
    javax.faces.component.UIInput.processValidators(UIInput.java:666)
    javax.faces.component.UIForm.processValidators(UIForm.java:229)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
    javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:662)
    com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:100)
    com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
here is my model
Code:
package com.desitek.cricket.action;

/**
 * Action 
 **/
public class User {

    
    private String username;
    private String password;
    private String email;


    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
}
Code:
package com.desitek.cricket.action;

public class LoginAction {

    private User user;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String login() {
        System.out.println(user.getUsername());
        return "success";
    }
}
login.jsp
Code:
<f:view>
        This is my JSF JSP page. <br>
            <h:form>
        Username
        <h:inputText value="#{user.user.username}"></h:inputText>
        Password
        <h:inputText value="#{user.user.password}"></h:inputText>
        <h:commandButton action="#{user.login}" value="submit" ></h:commandButton>

            </h:form>
        </f:view>
Code:
<managed-bean>
        <managed-bean-name>user</managed-bean-name>
        <managed-bean-class>com.desitek.cricket.action.LoginAction</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>

    <navigation-rule>
        <from-view-id>login.jsp</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>index.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>failure</from-outcome>
            <to-view-id>login.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
 
Top Bottom