how to practice coding in java

Read about how to practice coding in java, The latest news, videos, and discussion topics about how to practice coding in java from alibabacloud.com

The principle and practice of Java Concurrent Programming 13: The principle and use of the atomic class provided by JDK

(!compareandset (prev, next)); return prev; }Public final Boolean compareandset (int expect, int update) { Return Unsafe.compareandswapint (this, valueoffset, expect, update);}Among them, Compareandswap is the abbreviation of CAs. Returns True if Prev and next are not equal. Otherwise, returns false. Finally, it is done through unsafe.The code above indicates that if Compareandset returns True, the while condition is false, exiting the loop and returning the Prev value. If Comparea

Java theory and Practice: blocking memory leaks with weak references---reprint

named, which expungeStaleEntries() Map is called in most operations, which removes all invalid references in the reference queue and deletes the associated mappings. expungeStaleEntries()a possible implementation is shown in Listing 7. The type used to store the key-value mappings is Entry extended WeakReference , so when the expungeStaleEntries() next invalid weak reference is requested, it gets one Entry . It is more efficient to use a reference queue instead of a regular scan of the content,

Java Theory and Practice: Make a good (event) listener

Observer mode is common in Swing development, and is useful for eliminating the coupling of components in scenarios other than GUI applications. However, there are still some common flaws in the registration and invocation of listeners. In this period of Java theory and practice, Java expert Brian Goetz offers some good advice on how to make a good listener and h

The theory and practice of Java processing interruptedexception anomaly _java

more high-level code on the call stack needs to process the interrupt after the irrevocable task ends. Listing 6 shows a method that waits for a blocking queue until an available item appears in the queue, regardless of whether it is interrupted or not. For the convenience of others, it restores the interrupt state in a finally block after it has ended, lest it deprive the caller of the interrupt request of the right. (It cannot restore the interrupt state at an earlier time, because that will

Java Collection Small practice supermarket inventory management system

("Please enter the name of the new fruit"); theString A =Sc.next (); theSystem.out.println ("Please enter the number of the new fruit"); the intb =sc.nextint (); -System.out.println ("Please enter the price of the new fruit"); in Doublec =sc.nextdouble (); theChaoshi ARR4 =NewChaoshi (); theArr4.name =A; AboutArr4.id =b; theArr4.price =C; the Arr.add (ARR4); the } + Public Static voidC (arraylistarr) { -System.out.println ("Please enter the number you want to delete");

Java Concurrent Programming Practice reading notes-the first part of the basic knowledge

which case the worker thread is not necessarily aware if the values in memory change. This means that the worker thread does not necessarily see changes in the in-memory variables. This is the problem of visibility. The solution to the visibility problem is the same as the way to solve the race condition: lock. Locking guarantees that only one thread at a time can handle the variable, and the value in the current thread's workspace is always the most recent valid value, and the latest value is

Java Practice Questions: now give two strings, compare them to see if they are equal

Import Java.io.BufferedReader;Import java.io.IOException;Import Java.io.InputStreamReader;Import Java.util.StringTokenizer;/*** Suppose the strings are similar to the ABA and AAB are equal, now give you the two sets of strings, please programmatically compare them to see if they are equal* */public class Equaldemo {public static void Main (string[] args) {First read to a string of charactersBufferedReader br = new BufferedReader (new InputStreamReader (system.in));String s = null;try {s = Br.rea

Java Edition typing practice game source

Frame1_jbutton2_actionadapter (this)); Jlabel2.settext ("First off: 10"); Jlabel2.setbounds (New Rectangle (414, 473, 171, 21)); Contentpane.add (JPANEL1); Contentpane.add (JButton2); Contentpane.add (JButton1); Contentpane.add (JSlider1); Contentpane.add (JLABEL1); Contentpane.add (JLABEL2); This.addkeylistener (New MyListener ()); Jbutton1.addkeylistener (Ne

Blue Bridge Cup: Basic practice letter Graphic "Java algorithm implementation"

Title DescriptionUsing letters to make some beautiful graphics, here's an example:ABCDEFGBabcdefCbabcdeDcbabcdEdcbabcThis is a 5 row 7-column graph, find out the pattern of the graph, and output an n-row m-column graph.Input formatEnter a row that contains two integers n and m, representing the number of columns of the number of rows of the graph you want to output.Output formatOutput n lines, each m characters, for your graphics.Sample input5 7Sample outputABCDEFGBabcdefCbabcdeDcbabcdEdcbabcDat

"Java Practice" 6-2.GPS data processing

). substring (string.valueof (b). Length ()-2);//the number of seconds is converted to a string containing the leading thes = ":" + string.valueof (b). substring (string.valueof (b). Length ()-4, string.valueof (b). Length ()-2) + s;//Convert fractions into strings *B/= 10000; $ if(B >= 24) {Panax NotoginsengB-= 24; - } the if(B >= 10) { +s = string.valueof (B) +s; A } the Else if(b ) { +s = "0" + string.valueof (B) +s; - } $ System.out.println (s)

Java-Inheritance-practice Highlights

hidden from the constraint. This means that only the overlay method will be dynamically bound, and the shadowing will not occur dynamically. In Java, all other methods, except the static method and the final method, are dynamically bound. As a result, the above output will appear.SummarizeThe constructor invocation of the parent class and the initialization process must precede the child classThe order of initialization is also in accordance with; Ob

Maximum same substring of Java practice

1 PackageString.demo;2 /*Requirement: Find the longest common substring of two strings3 * Ideas:4 * 1. See if the short string is in the long string, and if it exists, the short string is the largest common substring.5 * 2. If it does not exist, then the short substring is reduced in length to take the substring, to determine whether there is a long string, if6 * exist, find! 7 * 8 */9 Public classfindmostlargesubstringTen { One A /** - * @paramargs - */ the Public Static

Java Programming Ideas Fourth Edition fourth chapter personal practice

==N2) + "\ T" + "N1Exercise 4: (3) write a program that uses two nested for loops and the remainder operator (%) to detect and print a prime number (an integer that can be divisible only by itself and 1 and not by other numbers). public static void Main (string[] args) {test (33);} public static Boolean test (int num) {for (int i=2;iExercise 5: (4) Repeat Exercise 10 in chapter 3rd, instead of using the integer.tobinarystring () method, use the ternary and bitwise operators to display the

POJ 2305 Basic Remains (Java practice)

DescriptionGiven a base B and non-negative base b integers p and m, compute p mod m and print the result as a base b integer. P mod m is defined as the smallest non-negative an integer k such that p = a*m + K for some integer a.InputInput consists of a number of cases. Each case was represented by a line containing three unsigned integers. The first, B, is a decimal number between 2 and 10. The second, p, contains up to digits between 0 and b-1. The third, M, contains up to 9 digits between 0 an

Java Practice---15

1 PackageCn.lyh;2 3 Public classL {4 5 Public Static voidMain (string[] args) {6 int[]arr =New int[30]; 7Arr[0]=1;8Arr[1]=1;9 for(inti=2;i)TenArr[i]=arr[i-1]+arr[i-2]; One for(intI:arr) ASystem.out.print (i+ ","); - - } the -} PackageCn.lyh; Public classL { Public Static voidMain (string[] args) {liker ker[]=NewLiker[3]; ker[0]=NewLiker ("Mr, L", 11); ker[1]=NewLiker ("Mr, Y", 17); ker[2]=NewLiker ("Mr, H", 19); for(inti=0;i) Ker[i].getinfo (); } } c

[Java concurrent programming practice] -- synchronized, asynchronous ynchronized

[Java concurrent programming practice] -- synchronized, asynchronous ynchronized In our practical application, we may often encounter such a scenario: multiple threads read or write the same data, access the same file, and so on. If we do not control this situation, it is very easy to cause errors. In java, the concept of critical section is introduced to solve t

Java 9 is faster: JShell hands-on practice

Java 9 is faster: JShell hands-on practice HowIs it one of the coolest features of Java 9? Last week, I finally took the time to experience a preemptive version of Java 9. The first stop is JShell, which is also called the Kulla project. This is why at first I had the courage to try

Android Development Practice: Array Transfer of Java layer and JNI layer

, it is more efficient than the normal array transfer, but because the construction/destruction/maintenance of the shared memory cost is relatively large, so the small data of the array is recommended to use the same method, Direct The buffer mode is more suitable for long-term sharing of large chunks of memory with frequent access. The specific use method is described as follows:First look at the definition of Native.java:and see how native.c is implemented:As can be seen from the above code, i

The theory and practice of Java thread pool

main code as follows:Code 3public class Executorgroup {Executor[] group = new Executor[NUM];Thread boss = null;MapAtomicinteger cursor = new Atomicinteger ();volatile int cursor = 0;Public Executorgroup (String name) {//init Group for (int i = 0; i Registeredtables.put (Taskkey, Cursor.getandincrement ());Registeredtables.put (Taskkey, cursor++% NUM);}int index = Registeredtables.get (Taskkey);Logger.debug ("execute message {}, register index {}", Taskkey, index);try {Group[index].schedule (mes

Java Theory and Practice: using Volatile variables correctly

Original source: http://www.ibm.com/developerworks/cn/java/j-jtp06197.htmlGuidelines for using volatile variablesThe Java™ language contains two intrinsic synchronization mechanisms: synchronous blocks (or methods) and volatile variables. Both of these mechanisms are proposed to achieve the security of code threads. Where volatile variables are less synchronous (but sometimes simpler and less expensive), an

Total Pages: 15 1 .... 3 4 5 6 7 .... 15 Go to: Go

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.