| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
javaObject('ClassName',x1,...,xn)
javaObject('ClassName',x1,...,xn) calls the Java constructor for class ClassName with the argument list that matches x1,...,xn, to return a new object.
If there is no constructor that matches the class name and argument list passed to javaObject, an error occurs.
Use the javaObject function to:
Use classes having names with more than 31 consecutive characters.
Specify the class for an object at run-time, for example, as input from an application user.
The default MATLAB constructor syntax requires that no segment of the input class name be longer than 31 characters. (A name segment, is any portion of the class name before, between, or after a period. For example, there are three segments in class, java.lang.String.) Any class name segment that exceeds 31 characters is truncated by MATLAB. In the rare case where you need to use a class name of this length, you must use javaObject to instantiate the class.
The javaObject function also allows you to specify the Java class for the object being constructed at run-time. In this situation, you call javaObject with a string variable in place of the class name argument.
class = 'java.lang.String'; text = 'hello'; strObj = javaObject(class, text);
In the usual case, when the class to instantiate is known at development time, it is more convenient to use the MATLAB constructor syntax. For example, to create a java.lang.String object, type:
strObj = java.lang.String('hello');
Note Typically, you do not need to use javaObject. Use the default MATLAB syntax for instantiating a Java class instead. Use javaObject for the cases described above. |
The following example constructs and returns a Java object of class java.lang.String:
strObj = javaObject('java.lang.String','hello')
javaArray, javaMethod, import, methods, fieldnames, isjava, javaObjectEDT
![]() | javaMethodEDT | javaObjectEDT | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |