Discover java programming language 4th edition, include the articles, news, trends, analysis and practical advice about java programming language 4th edition on alibabacloud.com
rods in different ways, then cut into two parts is a variable amount, bad control.According to the above ideas, we can use two methods to try to solve this problem:recursion (Key code):/** * Optimal cutting scheme for calculating steel bars of length n (recursive) * @author Aaron * August 3, 2015 * /private static int Getmax (int[] p, int n) { System.out.println (n); if (n Memory Search (Key code):private static int[] Getrecordarray (int n) {if (n full Source code d
table is not used at all. Compile with Javac, and then run it in Java. If you're using a different development environment than the JDK, learn how to compile and run it in your environment Public class javathinking { publicstaticvoid main (string[] args) { System.out.println ("Hello,world");} }Exercise 3: Find the code snippet that contains the atypename, rewrite it as a complete program, and then compile, runclass atypename{ pub
Create a class that contains an int field and a char field that are not initialized and print them out to verify that Java performs the default initialization.public class Domtest{int I;char c;public domtest () {System.out.println ("i=" +i+ "\nc=[" +c+ "]" + "\ n []");/** * Print result as follows I =0 c=[] []//only for comparison reference */}/** * @param args */public static void main (string[] args) {new domtest ();}}
Java programming ideas fourth edition Chapter 6 Personal exercisesExercise 1: (1) create a class in a package and create an instance of the class outside the package of the class.
Import mil. oms. main. test. test; public class MainTest {public static void main (String args []) {Test test = new Test ();}/** Test () instantiation of the running result ...... */}
its elements can be accessed efficiently and randomly, and the disadvantage is that the performance of inserting and removing elements at a specified location is slow. LinkedList is slower in random access, but it is more efficient to insert and remove elements at a specified location.
2. Set has three important implementations, respectively, Hashset,treeset,linkedhashset
all implementation classes of the set interface ensure that their elements are not duplicat
Third questionPackage net.mindview.interfaces;Abstract classbase{ PublicBase () {print (); } Abstract voidprint ();} Public classTest3 extends base{Private inti =5; @Overridevoidprint () {System. out. println (i); } Public Static voidMain (string[] args) {Test3 T=NewTest3 (); T.print (); }}Output Result:0 5When calling the base class construction method, it simply allocates a chunk of memory space to the member variable of the subclass and sets the value of the memory space to the defa
UnsupportedOperationException ). If the list is variable size, the programmer must override add(int, E) and remove(int) method differently.Class:arraylist Public class extends Implements ListArrayList is an array-based implementation of the variable size of the list interface. The bottom of the array is implemented in such a way that it has good random access, but it is not efficient for inserting, deleting and so on at the specified location.Each ArrayList instance has a capacity. This capacit
Exercise 1: (1) Create a class in a package that creates an instance of the class outside the package where the class is located.Import Mil.oms.main.test.Test; Public class maintest {public static void Main (String args[]) { Test test=new test (); } /** Run result test () instantiation ... Package Mil.oms.main.test;public class Test{public Test () {System.out.println ("Test () instantiation ...");}Exercise 2: (1) rewrite the code snippet in this section as a c
Programming
My notes.
Interfacesinner classes provides a more sophisticated way of organizing and controlling the objects in your system.
Interface is better than abstract class, because we can write a class that "can be upcasting to multiple base classes" to achieve multiple inheritance in C + +.
You can add the keyword public before the keyword interface (but only if the interface is defined as a file with the same name), otherwise it becomes "
Programming allows the change of things to be separated from the unchanging, so that the primary consideration of object-oriented design (OOD). Consider the version update of the library.
The concept of the component library (components library) and who is qualified to use the components such as Java is controlled by the keyword package and so on.
Use of the Import keyword, package keyword usage, default
==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
Programming encapsulation, inheritance and polymorphism are the three core essences of OOP.
Method-call (function Call) binding method:
If the binding action occurs before the program executes (completed by the compiler and the connector), it becomes the pre-binding (early binding)
The binding action is performed on an object-type Biell during the execution period, called a late-bound late binding, or the execution-time binding run-time binding, or dy
Programming | objects
This is a very simple plan: a fixed number of objects with known lifespan (objects).
You have to be able to produce any number of objects at any point in time. To do this, Java provides several ways to hold objects (or reference of objects). There is a built-in array, as well as a complete set of container classes in utilities or a cluster class (collection classes).
The diff
Exercise 3: (1) Create a class with a default constructor (that is, a parameterless constructor) to print a message in the constructor. Create an object for this class. P116public class Test{public Test () {System.out.println ("Hello Word");} public static void Main (string[] args) {new Test ();} /** * Run result Hello Word */}Exercise 4: (1) Add an overloaded constructor to the class in the previous exercise so that it accepts a character parameter and prints your own information and accepted p
Programming | Repeating Java has a lot of praise of the function, the application of code is one of them. But if you want revolutionary change, you have to go far beyond the old code of "Replicator code, then change": combination (composition) and inheritance ( Inheritance)
ToString (): Objects of each non-basic class have ToString (), which is called when the compiler expects a string and you have only th
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.