{//produce an apple and put it in the box +box.buff[(++box.putpoint)% box.boxlength] = 1; Abox.boxcount++; theSystem.out.println ("Put in an apple"); +SYSTEM.OUT.PRINTLN ("Total apples:" +box.boxcount); - box.notify (); $ Try { $Thread.Sleep (1000); -}Catch(interruptedexception e) { - e.printstacktrace (); the } -}//ElseWuyi the } - } Wu - } About } $ - //consumption of apples, consumers - classCus
Scene:1. When passing the byte[] array through the socket to Java, Utf-8 's byte array is converted to string, Java does not encounter 0 stops ending, but has been using the capacity of byte[].So the string converted to Java needs to judge the byte value to be 0, and then intercept the array length.public static int Searchbyte (byte[] data, byte value) {int size
Path issues in JavaCode description, as follows: Packagecom.merlin.test;ImportJava.io.InputStream; Public classTest { Public Static voidMain (string[] args) {NewTest (). Testpath (); } Public voidTestpath () {//when using the getResourceAsStream () method, the root path refers to Classpath, which is the SRCInputStream In0 = This. GetClass (). getResourceAsStream ("/");//Note that the backslash is writtenSystem.out.println (IN0);//can read to the/
Package com.cn.test3; Java multithreaded simulation producer consumer issues//producerconsumer is the main class, producer producers, consumer consumers, product products//storage WarehouseComments: I wrote the output below the program, you can look at it, in fact very easy, you imagine the product from production, to take out a production line, we define two threads, producer threads, and consumer threads,
Java provides a set of APIs to support the interaction between threads. A set of APIs waiting to be notified in the object classWait ()Notify ()Notifyall ()It is important to note that you must never call the Wait () method outside of the loop. (Open a separate article to discuss) The following uses consumer and producer issues to demonstrate the use of the above API:Packagexiancheng;publicclasspc{publicsta
, String > MyMap = new HashMap IntegeR , String>();
Set MYCLaSS > set = new HashSet Myclass>(0);
No more examples, these examples are straightforward enough.
at the end of this article, let's go back to the procedure to clear a single, have not previously warned? If you are such a person who does not want to use type safety to eliminate the warning, and do not want to see that nasty Waining, you can add such a sentence before the Main method (if you use IDE can
) each time a 1 Revisedobjectinheap object is created, but it consumes 2M of out-of-heap memory. Such a heap of memory is sufficient (in which case garbage collection of heap memory is not performed), but the out-of-heap memory is insufficient, so OutOfMemoryError is not reported . Although the improved REVISEDOBJECTINHEAP does not have an out-of-heap memory leak, this workaround wastes heap memory unnecessarily. A simple look at the next Bytebuffer source, its internal allocation of external me
(Note: This article refers to the knowledge purely for technical exchange, without permission not reproduced privately)There is also a memory leak in Java, because the object is useless but can be reached.This subdivision is subdivided down to a total of three1. Not available ------> The GC will help us recycle it, and C + + will not2. not available up to ------> There is a memory leak in this situation3. usable up to ------> normal use1. Not a
achieve multiple inheritance effects: This is the indirect implementation of multiple inheritance through interfaces. Interface howeat{ Public abstract String howeat (); } Class Chenken implements howeat{ Public String howeat () { Return "Chicken:fry it"; } } Class Orange implements howeat{ Public String howeat () { Return "Orangr:make it Juice"; } } This is achieved through an internal class. Class father{ public void output () { System.out.println ("father"); } } Class mother{ public void out
, every interval, consume an apple106 Try {107Thread.Sleep (500);108}Catch(interruptedexception e) {109 e.printstacktrace (); the }111Apple Apple = Basket.removefirst ();//Take out an apple theSystem.out.println ("Eat:" +apple.tostring ());113Notify ();//inform producers to produce the the } the }117 118 //Apple class119 classApple { - Private intID;121 122 PublicApple (intID) {123 This. ID =ID;124 } the 126 @Override127 PublicString toString () {
, for example:mysql> ALTER TABLE ' tableName ' defaultcharacter SET UTF8 COLLATE utf8_general_ciThe character encoding of the table was changed to UTF-8, and it was also possible to insert Chinese into the table.I thought it was over here, but when we started Tomcat to test it, we found that the database was still garbled. Since mysqlclient can insert Chinese, why not use JDBC? It is very likely that JDBC does not use Character_set_client to encode client data.After flipping through countless do
The Equals method differs from = =
Overriding equals note Five features: 1 reflexivity: The return value of X,x.equals (x) for any reference value must be true;2 symmetry: For any reference value x, Y, the return value of X.equals (Y) must be true if and only if Y.equals (x) returns a value of true;3 transitivity: If X.equals (y) =true, y.equals (z) =true, then X.equals (z) =true;4 Consistency: If the object participating in the comparison does not change, then the result of the object
The first one:Java FTP uses Apache common-net, but FTP servers provided on the FTP service side only support SFTP, resultingJava.net.ConnectException:Connection refusedThe above error is on the company test server, the local running code error is as follows:org.apache.commons.net.MalformedServerReplyException:Could not parse response code. Server reply:ssh-2.0-openssh_5.3In summary: The use of Com.jcraft.jsch for SFTP is handledThe second one:SFTP with Com.jcraft.jsch treatment found local test
/*This example is an exception in the inheritance of the problem, when bexception inherit Aexception, the parent class throws Aexception, then the child class can only throw aexception or bexception, and not throw other exceptions, because the subclass can not be more than the parent class " There is a problem. " Here is an example:*/Java Learning notes--inheritance issues in exceptions
Sinkholes!!!Believe that this step of the students in front of the work has been done, and directly say the key!!!The main is to configure the path variable, here win10 and other differences on the out, win the path variable, to use the absolute path of the JDK, and can not use%java_home% this class, the computer can not recognize.Look at the picture:WIN10 Configuring Java Environment variables to resolve javac not internal or external command
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.