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 ...... */}
Package mil. oms. main. test; public class T
1. What is a constructorWhen we create an object, Java always initializes some variables, methods, and calls an initialization function.And this initialization function can also be written by ourselves.2. Default constructorConstructors that do not accept any arguments are called the default constructors.3, the name of the constructorThe name of the constructor and the names of the classes are the same.Like what:Public class AA {int a;int b; AA () {
Title: Vampire numbers are numbers with an even number of digits that can be multiplied by a pair of numbers, which each contain a number of half-digits of the product, where the number selected from the initial number can be arbitrarily sorted. Numbers ending in two 0 are not allowed, for example, the following numbers are "vampire" numbers:1260=21*601827=21*872187=27*81Write a program to find out 4-digit numbers of all vampires./** * Java Programm
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
Creates a set of vowel letters. For Uniquewords.java operations, counts and displays the number of vowels in each input word and displays the sum of all the vowels in the input file. Public classVOWELS6 {Static voidVowelcounter (setSt) {SetNewTreeset(); Collections.addall (Vowels,' A ', ' e ', ' I ', ' o ', ' u ', ' a ', ' e ', ' I ', ' o ', ' u '); intAllvowels = 0; for(String s:st) {intCount = 0; for(Character V:s.tochararray ()) {if(Vowels.contains (v)) {count++; Allvowels++; }} System.out.
other keyword is explicitly specified, the default is the latter. The use and meaning of these keywords are fairly straightforward, and they determine who can use the following definitions.
"Public" means that any subsequent definition can be used by any person.
Private means that no one else can access the subsequent definition information except yourself, the creator of the type, and the internal function member of that type. Private has erected a wall between you and the client
Java programming ideas personal exercises
I hope you will be grateful for your criticism ......)Chapter 3 exercise 9 (1) show the maximum and minimum numbers represented by float and double indexes respectively
public class MaxMinFloatDouble { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub float fmax = Flo
Package Cn.com.commsoft.map;public class MyMap {myentry[] arr = new Myentry[100];int size;/** * Implement map with hash algorithm (each object has an address , * A hash code generated by the base site, because each object's address is different, so * generated hash code is unique) * @param key * @param value */public void put (object key, Object value {Myentry my = new Myentry (key, value);//corresponds to the address mapping function, but generates an address mapping conflict int a = (Key.hashc
method: for (int i = 0; list!=null i ) {...}3. Do not constantly create object references within the loopFor example: for (int i = 1; I ) { new Object (); }This practice causes memory to count as the object reference exists, and if count is large, it consumes memory and is recommended instead:NULL ; for (int i = 0; I ) { new Object ();}In this case, only one copy of the object object is referenced in memory, and each time new object () is used, the object reference points to a diff
reference type, when he is directly assigned to the value of the corresponding reference position is assigned to the string variable, so, two times the result is true. If you assign a value with the new String (), the result will be different.
Write a program that simulates the result of tossing a coinPackage Net.mindview.operators;import Java.util.random;importStaticnet.mindview.util.print.*; Public classThrowcron { Public Static voidMain (string[] args) {Random num=NewRandom (); intA = Num.
) LatPet | [pet] beauty [PT]N. a pet; an angry or spoiled person.Vt. LoveVI. Be angry or caressAdj. a favoriteN. (Pet) name; (Russian) Pate; (Cambodian) shellfishWelsh Cat (Cymric) [' Kimrik]Manx error English [MKS] BeautyManx CatEgyptian Mau error Egyptian Cat(Egyptian error English [' DP () n]Adj. of Egypt;N. Egyptian; Ancient Egyptian language)Pug Error English [PG] beauty [Pɡ]N. Pug; lion nose; mud; footprints.Vt. To chase, stir, or traceAdj. to be comfortable;Mutt error English [MT] beauty
written and compiled, a class object is created, which is actually saved in the. class file of the same name. The generation of this class object is actually a subsystem of the JVM (the Java Virtual machine) that uses the ClassLoader.All classes are dynamically loaded into the JVM when they are first used, and the class is loaded when the program creates the first reference to a static member of the class, so that the constructor is a static method o
First, the object-oriented five basic features:1. All things are objects. treats an object as a peculiar variable, he can store the data, and can require it to perform operations on itself.2. A program is a collection of objects that they tell each other to do by sending a message.3. Each object has its own storage that is composed of other objects. in other words, you can create a new type of object by creating a package that contains an existing object.4. No object has its type. The most impor
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
The random class contains two construction methods, which are described in turn:1. Public Random ()The construction method uses a number that corresponds to the relative time of the current system time as the seed number, and then constructs the random object using this seed number.2. Public Random (Long Seed)The construction method can be created by setting a seed number.Example code:Random r = new Random ();Random r1 = new Random (10);Random r2 = new random (10);It is emphasized that the numbe
Main (string[] args) {letter x = new Letter (); x.c = ' a '; System.out.println ("1:x.c:" + x.c); f (x); System.out.println ("2:x.c:" + x.c);} } /* 1:x.c:a 2:x.c:z*/Method F () appears to replicate a copy of its reference letter y within its scope. But actually we're passing a reference, so f () actually changes the object outside the scope.4. arithmetic operators, self-increment and decrement, relational operators, logical operators-Arithmetic operat
range.consider possible future changes, i.e. scalability This means that extensibility means that the application can easily add new functionality.Nine, to consider a reasonable re-useIt means to consider reuse as much as possible, but not to consider reuse, and not to throw away other design principles.10, to reasonably consider the use of interfaces and abstract classesThis means that the interface is preferred, and if you want to constrain the behavior of subclasses and provide the public fu
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
has the same method name, return type, and parameter table as a method in the parent class, the new method overwrites the original method.Scope of the classpublic>protected>friendly>protectedClass inside this Bun class outer packagePublic√√√√Protected√√√xDefault√√xxPrivate√xxxInheritance and Interfaces1. Inheritance: Single inheritance, we say that the inheritance of the class is generally inherited from the attribute is-a relationship of things, inheritance is to reduce the redundancy of the C
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.