This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
..
public void and_and ()
System.out.println("case two");
System.out.println (b);
}
")")case two
b ..
..
: ()toString
Object
.Object
String
Sun toString
()toStringpublic String
a string that "textuallythe toString method returnsof the object.
In general,string representationReturns a
that is easy for a personconcise but informative representation.
The result should be arepresents" this object
to read. It is recommended that all subclasses override this
method.
:) (Exception handle
-
.throw the exception
- exception
.
-
catch the exception.
:
-Errors class and its subclasses
:
-Exception class and its subclasses
Checked exceptions
-Runtime exceptions and its subclasses
compiler Uncheck Exception
-* Checked exceptions :
-Try.. catch blocks
:
try
finally block try
.
- exception :in the method header
Throws ..
public Boolean check format (String fileName) throws EO
Exception
Color
)lowercase)orange
JDK 1.4 )uppercase)ORANGE
(Upper_Case .)
:
)class(Desktop )Method )browse
//get a Desktop object
try {
//open the default browser using the method browse which take an
URI
object representing the web page
desktop.browse(new URI("http://arabteam2000-forum.com/"
));
}
:
.
.Collectioninterface
Collection interface
interface:SetList.
Set .
Two MethodConCrete Class
.equalshashcode
List .
Map Interfaca Collection
.
SetList
new Listnew Setnew
()void remove
.
:collection interface
_ Informative Methods:
()Iterator Iterator
()boolean isEmpty
collection )true Or false) boolean
()int size
_ Object Based Methods:
)boolean equals(Object o
.
()int hashCode
.
_ Element Based Methods:
)boolean add(Object o
.
)boolean remove(Object o
.
)boolean contins(Object o
_ Output To Arrays Methods:
()Object[] toArray
.Arrays
)Object[] toArray(Object[] o
.
_ Collection Based Methods:
.AB
)boolean addAll(Collection c
.
)boolean containsAll(Collection c
)boolean removeAll(Collection c
.
()void clear
A .
)boolean retainAll(Collection c
:arrayListLinkedList
ArrayListLinkedList List
LinkedList
Queue , poll , peekArrayList)(
ArrayListarray
LinkedListsetget
setget
..arrayList ..
:LinkedList
List<String> staff = new LinkedList<>(); // LinkedList
implements
List
iter.next(); // visit second element iter.remove(); // remove
last
visited element
System.out.println("array1 before sorting:
" + Arrays.toString(array1));
:
compareTo
/
. comments
annotations
annotation processor :
..
annotations
JavaSE 5.
annotations
.
:
Override:@
override
.
compiler
)method signature(
.
:
override
toString
Object.
"S"
toStringlower caseupper case .
public class TestOverride {
:
TestOverride.java:2: method does not override or implement a method
from a supertype
@Override
^
error @Override
override
.
Deprecated:@
deprecated
compilation
)compiler warning.(
compilation
public class TestDeprecated {
}
}
:compiler
Note: TestDeprecated.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details .
-Xlint $ javac -Xlint TestDeprecated.java
d.someMethod()
warning
SuppressWarnings:@
.compiler
}
}
unchecked
java.util.List<String> list
= new java.util.ArrayList();
@SuppressWarnings compilation
:
}
}
Annotations
:
.
meta-annotations
meta-annotations
)annotating the annotation.(
)IntVarChar( .Hashtable
.SQL
import java.lang.reflect.Field;
import java.util.Hashtable;
//A Hashtable containing the name of the column, and its
type
Hashtable<String, String>();
StringBuilder query
= new StringBuilder();
annotation
*/
}
}
}
@Int private int age;
Class[] c = {Person.class};
}
}
.
Databases
: )access(
NetBeans
.…
DB Mouses
Control Panel
)Data Source (ODBC
add ODBC
NetBeans
add
-
)
(
ok
…………………………………………..
Source
SQL
Import java.sql*
)Method(
:
– con
- sql
– search
- rs
)
(
try – catch
-Class forName
- DB
–
- dtm
&
– dtm
ID
– DB
- – dtm
- – DB
Connect
JTextField3
Search
Update
BRAND
Graphics 2D
:
Swing .JPanel
paintComponent.
Graphics
.
) Graphics
drawRect(int x, int y, int width, int height)
.xy width
.
fillRect(int x, int y, int width, int height)
.xy width
.
drawOval(int x, int y, int width, int height)
.xy width
.
.xy width
.
.x1y1 x2y2
.
setColor(Color c)
.
Graphics
.Sun
JFrame frm = new JFrame();
- " ".
. .
. (CLS (
CLS C1 C2 C3 C4 C5 C6 C7
Paint P=new Paint();
{
public void BCircle(Graphics g, int xc, int yc, int r){
int x = 0, y = r, s = 3-(2*r);
while(x<=y){
g.drawLine(xc+x, yc-y, xc+x, yc-y);
g.drawLine(xc-x, yc+y, xc-x, yc+y);
g.drawLine(xc-x, yc-y, xc-x, yc-y);
* To change this license header, choose License Headers in
Project
Properties.
* and open the template in the editor.
*/
*/
f=new JFrame("capture image");
JOptionPane.showMessageDialog(null,"
"+File.pathSeparator);
} catch (IOException ex) {
}
}
-splash
// Splash.java
public static void main(String[] args) {
// Throw a nice little title page up on the screen first
showSplash(3000);
}
// A simple little method to show a title screen in the
// center of the screen for a given amount of time.
public static void showSplash(int duration) {
JWindow splash = new JWindow();
splash.setBounds(200,100,455,500);
JLabel copyrt = new JLabel
try { Thread.sleep(duration); } catch (Exception e) {}
splash.setVisible(false);
Desktop desktop= Desktop.getDesktop();
//open the default browser using the method browse which take
an URI object representing the web page
desktop.browse(new URI("http://google.com"));
-count letter
import javax.swing.JOptionPane;
class CountEachLetter {
/** Main method */
// Prompt the user to enter a string
String s = JOptionPane.showInputDialog("Enter a string:");
// Invoke the countLetters method to count each letter
int[] counts = countLetters(s.toLowerCase());
String output = "";
// Display results
if (counts[i] != 0)
output += (char)('a' + i) + " appears " +
}
static int[] countLetters(String s) {
for (int i = 0; i < s.length() ; i++) {
-draw time
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
{ public MaFenetre ()
{ setTitle ("PENDULE") ;
panControles.add (ok) ;
ok.addActionListener (this) ;
{ int h, m ; // pour les valeurs saisies
if (e.getSource() == ok)
saisieHeures.setText ("") ;
saisieMinutes.setText ("") ;
// si les valeurs obtenues sont valides, on les place dans
// les champs heures et minutes et on force le dessin
// sinon, on replace les anciennes valeurs dans les champs
texte
repaint() ;
{ heures = h ; minutes = m ;
}
{ super.paintComponent(g) ;
boolean panTropLarge = (largeur>hauteur) ;
int rayon ;
g.drawOval (xCentre-rayon, yCentre-rayon, 2*rayon, 2*rayon) ;
// dessin grande aiguille
int minutes = fen.getMinutes() ;
g.drawLine (xCentre, yCentre,
(int)(xCentre+rayon*Math.cos(angle)),
g.drawLine (xCentre, yCentre,
(int)(xCentre+rayon/2.*Math.cos(angle)),
{ MaFenetre fen = new MaFenetre() ;