Home >Java >javaTutorial >Summary of comprehensive basic explanations of J2ME program development (1)
1. Basic knowledge of Java required in J2ME
Most people now learn J2ME from scratch. When learning J2ME, they always start from the basics of Java, and now all the books on the basics of Java are Taking J2SE as the basis, this causes some unnecessary troubles in learning. Here is a brief explanation of the basic Java knowledge used and unnecessary in J2ME:
Basic Java knowledge used in J2ME:
1. Basics of Java syntax: including basic data types, keywords, operators, etc. 2. Object-oriented thinking: the concepts of classes and objects, inheritance and polymorphism, etc.
3. Exception handling
4. Multi-threading
Basic knowledge of Java not used in J2ME:
1. The use of javac and java commands in JDK
2. Many classes in the basics of Java are not available in J2ME, or in the classes The method has been greatly streamlined. Therefore, it is recommended to be familiar with class libraries in J2ME.
3. The knowledge of Applet, AWT, and Swing cannot be used in J2ME at all.
That’s all in a nutshell, I hope that friends who are learning J2ME can avoid some detours, and I hope that everyone will actively correct and add to the deficiencies.
2. Functions that cannot be completed in J2ME
List some functions that cannot be completed in J2ME. I hope everyone can actively add:
1. Transplantation without changing the code in mobile phones mainly refers to games.
2. Dynamically modify button text.
3. Accept Chinese input on Canvas.
4. Manipulate local resources, such as address book, received text messages, etc.
5. Create destructive mobile phone viruses.
6. Others are waiting for everyone to add.
3. The cross-platform nature of J2ME
J2ME technology originated from Java, so it also has the advantages of JVM and can be transplanted on platforms that support Java. However, the current J2ME technology does very poorly on cross-platforms. We Let’s take a brief look at the reasons:
1. The screen sizes of mobile phones are different:
This is mainly in the interface production.
If you are using an advanced user interface, for example, if you are doing application development or common functions such as user login and user registration, there is generally no problem.
If you are using a low-level user interface, for example, if you are making a game, then you need to consider this issue.
2. The extended APIs of manufacturers are not uniform:
For example, Nokia’s extended API class library UI series may not be implemented on other mobile phones, or the package names may be different, etc.
3. Bugs implemented on mobile phone platforms:
For example, Nokia's 7650 has a bug in implementing double buffering, so software running on this model cannot use double buffering. For some other bugs on NOKIA, please refer to: http://blog.csdn.net/Mailbomb/archive/2005/03/24/329123.aspx
4. Mobile phone performance issues.
Different mobile phones have requirements for available memory and maximum jar files. For example, most Nokia S40 mobile phones support a maximum jar file of 64K and a maximum available content of 210K.
So now mobile phone software, especially games, provide a list of supported models, and that’s why there are mobile game transplanters.
4. Types of jobs you can do after learning J2ME
Now J2ME technology can be said to be quite popular. Here are some types of jobs you can do after learning J2ME:
1. J2ME game developer
According to game planning or documentation Requirements are to develop game programs on a specific model (mostly Nokia S40 or S60).
This is the job that most J2ME programmers are engaged in now.
You need to be proficient in: high-level user interface, low-level user interface, threads, and if it is an online game, you also need to be proficient in network programming.
2. J2ME application developers
There are not many mobile applications now, but there are still some, especially content related to mobile positioning and mobile commerce.
Requires proficiency in: advanced user interface, threading and network programming.
3. J2ME game transplant personnel
Refer to the source code and transplant games that can run on one platform to other platforms. For example, port Nokia S40 games to S60, or Sony Ericsson's T618, etc.
Mainly control the screen coordinates, some may need to replace some APIs.
You need to be familiar with the differences between various platforms and related technical parameters, such as screen size, maximum jar file size, etc.
5. Several principles of J2ME programming
1. Use object-oriented programming.
Although using process-oriented programming can reduce the size of the file, for the convenience of future maintenance and expansion, object-oriented programming must still be used.
2. Use the MVC pattern
to separate the model, interface and control. Nowadays, many programs combine the three into one, but if the program you are working on is relatively large, it is still recommended that you separate it.
3. Automatically save user settings
Use RMS to store user information, such as the last user name and password entered by the user, user settings for the system, etc. This not only reduces user input, but is also user-friendly. Many programs even do automatic login and so on.
4. Some system settings allow users to close them. Such as background music, background light display, etc.
5. Put the low-level user interface drawing actions in a separate thread.
6. When doing work that takes a lot of time to complete, give the user a waiting interface.
6. From simulator to real machine testing
For J2ME developers, the simulator has brought us a lot of convenience, such as debugging the program in the simulator and conveniently viewing the effect of the program, but the simulator It also brought us some problems, such as bugs in the simulator implementation, etc., so real machine testing is necessary.
1. Why do we need to conduct real machine testing?
Since the simulator program may have bugs and the performance of the real machine is limited, real machine testing must be performed.
2. How to transfer the program to the machine?
There are the following ways to transfer the program to the machine:
a) OTA download
b) Use data cable transmission
c) Infrared transmission
d) Bluetooth
You can choose the appropriate method according to the conditions.
3. What does the real machine test mainly measure?
There is a lot of content in the real machine test, mainly testing the following aspects:
a) Function of the program
b) Operability of the program, whether it is easy to operate
c) Size of the program, for example, most Nokia S40 series mobile phones accept it The maximum file size is 64K
d) Program running speed, whether the speed is bearable.
7. From WTK to manufacturer SDK
For J2ME enthusiasts, basically everyone starts with SUN’s WTK (J2ME Wireless Toolkit), but for practical applications, just using WTK is far from enough. , so in the learning process, the leap from WTK to SDK must be completed.
1. What is the download address of the manufacturer’s SDK?
http://blog.csdn.net/Mailbomb/archive/2005/01/01/236606.aspx
2. What is the difference between manufacturer SDK and WTK?
The simplest understanding of the manufacturer's SDK is to add its own simulator and its own extension API on the basis of WTK.
That is to say, when you use the manufacturer's SDK, you can use the manufacturer's extended class library, such as Nokia's UI class library, and the manufacturer's own simulator.
Each manufacturer has a small number of extension APIs, and they are not the same.
3. How to use?
Some manufacturers’ SDKs are used the same as WTK, such as Samsung.
Nokia provides an independent interface for development, but this interface is rarely used in actual development.
4. Issues with the manufacturer's SDK
There are some bugs in the implementation process of the manufacturer's SDK, and they are inconsistent with the real machine implementation. For example, NOKIA's mix playback problem and so on.
8. How to get the IMEI of a mobile phone in J2ME
IMEI is the abbreviation of International mobile entity identification. Enter *#06# in the mobile phone to display the number. It is 15 digits in length. It is unique in the world and will never conflict, so Can be used as a sign to identify users.
The following is the method to obtain IMEI in J2ME:
1. MOTO series mobile phones can be obtained by reading the IMEI attribute of the system. The code is as follows:
String imei = System.getPRoperty("IMEI");
2. SIEMENS series mobile phones can be obtained by reading the com.siemens.IMEI property of the system. The code is as follows:
String imei = System.getProperty("com.siemens.IMEI");
9. Solving the display problem in J2ME network connection Method
In network programming, sometimes the interface will be displayed without receiving network data, causing the interface display to not meet the requirements (for example, in announcement display, the background image of the announcement will be displayed first and then the announcement information will be displayed). Here is a solution A simple solution for everyone:
The method to solve this situation is divided into three steps:
1. In the interface that needs to be displayed, call the method of sending network data. This constructor is called every time it is displayed, and the setCurrent method of Display is not called for display.
2. Display the waiting interface (such as progress bar, etc.) to prompt the user that the network connection is in progress.
3. After processing the network feedback data, call the setCurrent method of Display to display the current interface.
10. Enhance J2ME’s String capabilities - splitting strings
Since JDK1.4, the split method has been added to the String class to achieve string splitting, but there is no such method in J2ME (MIDP2.0 has not been implemented yet), but in actual use, sometimes this operation is indeed needed. Here is a piece of code I implemented before to share with you:
/**
* Split string, principle: detect the split string in the string, and then take the substring
* @param original The string that needs to be divided
* @paran regex Split string
* @return The characters generated after splitting String array
*/
private static String[] split(String original,String regex)
{
//Get the starting position of the substring
int startIndex = 0;
//Put the result data first Into Vector
Vector v = new Vector();
//The returned result string array
String[] str = null;
//Storage the starting position when fetching the substring
int index = 0 ;
//Get the position of the matching substring
startIndex = original.indexOf(regex);
//System.out.println("0" + startIndex);
//If the position of the starting string If it is less than the length of the string, it proves that the end of the string has not been reached.
//-1 means reaching the end
while(startIndex < original.length() && startIndex != -1)
{
The above is a summary of the comprehensive basic explanation of J2ME program development (1) For more related content, please pay attention to the PHP Chinese website (www.php.cn)!