| Primitive | Wrapper Class | Constructor Arguments |
| boolean | Boolean | boolean or String |
| char | Character | char |
| byte | Byte | byte or String |
| short | Short | short or String |
| int | Integer | int or String |
| long | Long | long or String |
| float | Float | float, double, or String |
| double | Double | double or String |
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Saturday, April 16, 2011
Wrapper Classes and Their Constructor Arguments
Labels:
Java
Default Values for Primitives and Refrence Types in Java
| Variable Type | Default Value |
| Object reference | null (not referencing any object) |
| byte, short, int, long | 0 |
| float, double | 0.0 |
| boolean | false |
| char | '\u0000' |
Labels:
Java
Sunday, April 10, 2011
Compiler generated constractor code
class Foo {}
======>class Foo {
Foo() {
super();
}
}
class Foo {
Foo() {}
}
======>class Foo {
Foo() {
super();
}
}
public class Foo {}
======>public class Foo {
public Foo() {
super();
}
}
class Foo {
Foo(String s) {}
}
======>class Foo {
Foo(String s) {
super();
}
}
class Foo {
Foo(String s) {
super();
}
}
======>Nothing, compiler doesn't need to insert anything.
class Foo {
void Foo() {}
}
======>class Foo {
void Foo() {}
Foo() {
super();
}
}
(void Foo() is a method, not a constructor.)
Refrence: SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065)
Labels:
Java
Monday, April 5, 2010
Coding Guidelines - Java Programming Fundamentals
- Your Java programs should always end with the .java extension.
- Filenames should match the name of your public class. So for example, if the name of your public class is Hello, you should save it in a file called Hello.java.
- You should write comments in your code explaining what a certain class does, or what a certain method do.
- In creating blocks, you can place the opening curly brace in line with the statement, like for example,
public static void main(String[] args){
or you can place the curly brace on the next line, like, public static void main(String[] args)
{
public static void main(String[] args){
System.out.println("Hello ");
System.out.println("world");
}
- For names of classes, capitalize the first letter of the class name. For names of methods and variables, the first letter of the word should start with a small letter. For example: ThisIsAnExampleOfClassName thisIsAnExampleOfMethodName
- In case of multi-word identifiers, use capital letters to indicate the start of the word except the first word. For example, charArray, fileName,ClassName.
- Avoid using underscores at the start of the identifier such as _read or _write.
- In defining a long value, a lowercase L is not recommended because it is hard to distinguish from the digit 1.
- It always good to initialize your variables as you declare them.
- Use descriptive names for your variables. Like for example, if you want to have a variable that contains a grade for a student, name it as, grade and not just some random letters you choose.
- Declare one variable per line of code. For example, the variable declarations,
double exam = 0; double quiz = 10; double grade = 0;is preferred over the declaration,
double exam = 0, quiz = 10, grade = 0;
Labels:
Coding Guidelines,
Java
Thursday, March 18, 2010
Enum in Java
The basic using of Enum should be like following:
In addition, you may also using it as following:
so, you can have more information on it.
public enum SimpleColor {
RED,
GREEN,
BLUE
}
public static void main(String[] args) {
for (SimpleColor sc : SimpleColor.values()) {
System.out.println(sc);
}
}
In addition, you may also using it as following:
public enum ComplexColor {
RED ("Red", "0XFF0000"),
GREEN ("Green", "0X00FF00"),
BLUE ("Blue", "0X0000FF");
private String title;
private String rgb;
ComplexColor(String title, String rgb) {
this.title = title;
this.rgb = rgb;
}
public String title() {
return title;
}
public String rgb() {
return rgb;
}
}
public static void main(String[] args) {
for (ComplexColor cc : ComplexColor.values()) {
System.out.println(cc.title() + " - " + cc.rgb());
}
}
so, you can have more information on it.
Labels:
Java
Thursday, February 25, 2010
Best Practice of Java Array Declaration
To declare a array in Java, you have following options:
The conclusion is:
- dataType[] variableName;
- dataType variableName[];
- dataType []variableName;
The conclusion is:
- dataType[] variableName;
- dataType[][]...[] arrayName;
Labels:
Java
Saturday, January 23, 2010
Java Operators
. [] () ++ -- ! ~ * / % + - << >> >>> <<< < > <= >= == != & | ^ && || ?: =
Labels:
Java
Java Data Types
Primitive Data Types
- boolean (true, false)
- char (8 bits)
- byte (8 bits)
- short (16 bits)
- int (32 bits)
- long (64 bits)
- float (32 bits)
- double (64 bits)
- Primitive variables are variables with primitive data types. They store data in the actual memory location of the variable is.
- Reference variables are variables that stores the address in the memory location. It points to another memory location of the actual data is.
Labels:
Java
Tuesday, January 19, 2010
My First Java Program
public class Hello {
/**
* My first Java program
*/
public static void main(String[] args) {
//prints the string "Hello world!" on screen
System.out.println("Hello world!");
}
}
Error Types
- Syntax errors
- Run-time errors
- C++ Style Comments
- C-Style Comments
- Special Javadoc Comments
Labels:
Java
About Java
What is Java Technology?
- A programming language
- A development environment
- An application environment
- A deployment environment
- The Java Virtual Machine (JVM)
- Garbage Collection
- Code Security
Labels:
Java
Subscribe to:
Posts (Atom)
Java, JavaScript, HTML, XHTML, AJAX, CSS, etc.