Four example code for Java computing factorial

public class Factorial {public static int factorial (int x) {if (x throw new IllegalArgumentException ("x must be>=0");}int fact = 1;for (int i = 2; i Fact *= I;}return fact;}public static void Main (String args[]) {System.out.print (factorial (10));

Drag processing of Java text

Import javax.swing.*;Import java.awt.dnd.*;Import java.awt.datatransfer.*; public class Draglabel extends JLabel implements droptargetlistener{Public Draglabel (String str) {Super (STR); Calling the parent class constructor}public void DragEnter

Detailed explanation of Java variable scope (1/2)

The valid range for a variable is the area in which the program code can access the variable, and an error occurs at compile time if the range is exceeded. The effective range determines the life cycle of a variable, which is the start of declaring

Java bit Operations

The bit action designations in Java include:~ Bitwise NON (NOT)& Bitwise WITH (and)| bitwise OR (OR)^ Bitwise exclusive OR (XOR)>> Move Right>>> No sign right shiftThe first few are very simple, mainly the shift operation is more error prone.The

declarations and modifiers for Java classes

* Declaration of the class [Modifier] Class [extends parent class name] [Implements interface list]{} Modifiers: optional, for specifying access rights, the available values are public,abstract and finnal. Class name: In general, the first

Is the Java Interface the best place to store constants?

--> --> java Interface is the best place for constant storage? !--Black line separator--> The!--end HEADER area--> The!--start body area--> the!--Sidebar gutter-->!--START toc--> !--Introduction of reference-->!--end toc-->!--start Related

Java interface constant anti-pattern and definition of Java constants

Java beginners inadvertently define constants in interfaces. The only reason is that interfaces cannot be instantiated, and constants defined in interfaces do not need to be attached to instances. This is mainly because JDK itself has set many such

How to use the final keyword in Java

Final has the meaning of "unchangeable" and can modify non-abstract classes, non-abstract member methods, and variables.Classes modified with final cannot be inherited, and no subclass exists.The methods modified with final cannot be overwritten by

Full gc troubleshooting caused by HashMap in java concurrent environment

SymptomA requirement was launched recently, and the code was restructured during the requirement process. About half an hour after the application was released, an alarm was reported on a machine, and the load was too high. Log on to the machine to

Java obtains the code example of the current directory

Current Directory code The code is as follows:Copy code Import java. io .*;Public class Test {Public static void main (String [] args ){System. out. println ("Current Working Dir:" + new File (""). getAbsolutePath ());System. out. println

Cause analysis and optimization methods for high memory usage of JAVA processes

First, let's take a look at the jmap output of the next java process: The code is as follows:Copy code [Lex @ chou ~] USD jmap-heap 837Attaching to process ID 837, please wait...Debugger attached successfully.Server compiler detected.JVM version

An error occurred while displaying the localization method in Java.

Java displays errors in localization mode. When writing support programs, it always needs to display certain error information, programs that support internationalization and localization use the user's local character set to display the

Detailed explanation of multi-thread instances in java Work notes

I. Multithreading1. What is multithreading?It is easy to understand that multiple threads can execute multiple tasks at the same time. For example, downloading 10 URLs at the same time is much faster than downloading one URL at a time.If you are

Java Multithreading example study notes

Java wrote multi-thread crawlers in 2007. At that time, its understanding of multithreading was limited to concurrent tasks, and it had no understanding of scheduling among multiple threads. Therefore, the subsequent multi-threaded applications are

Java note (8) java array

This article is a reprinted aawanghuan article. For the original article, see the address.Http://blog.111cn.net/aawanghuan/archive/2008/03/24/2212403.aspxSummary is good, but I only copied the java array, and the subsequent processing of the string

Matcher. find () method in Java regular expressions

Today, when I was writing a program, I encountered a strange thing.I want to collect a URL link and extract the link text. To complete this step, I will take two steps:1. Content between and in advance. For example, extracted from "p id = km> &

Java obtains the current path and absolute path code

Current path1. Use the System. getProperty () function to obtain the current path: The code is as follows:Copy code System. out. println (System. getProperty ("user. dir"); // user. dir specifies the current path. 2. Use the function provided

Sharing tutorials on creating, deleting, and renaming Java directories and files

The code is as follows:Copy code Import java. awt .*;Import java. awt. event .*;Import java. io .*;Import javax. swing .*;// Create, delete, and rename directories and filesPublic class FileUseDemo extends JFrame {JTextField jtfPath;Public

Java indexOf () lastIndexOf () string lookup function

Use indexOf () to match a stringReturns the first occurrence of a substring in a String object.StrObj. indexOf (subString [, startIndex])ParametersStrObjRequired. String object or text.SubStringRequired. The substring to be searched in the String

Java connection to db2 data code

Java connection to db2 data codeFirst: at present, ibm has never provided a jdbc driver for type 1.Type 2 driver: com.ibm.db2.jdbc.app.db2driver. the driver is also in the package db2java.zip. jdk must be able to access db2's db2jdbc. dll and so

Total Pages: 6206 1 .... 2109 2110 2111 2112 2113 .... 6206 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.