Skip to main content

Java Basic Knowledge - Part 1

public class Card{
// instance variables:
private String number;
//Contructor:
Card(...){}
//Accessor methods:
public STring getNumber(){return number;}
//Action methods:
public boolean isNumberCorrect(..){}
}

{  curly brace for the opening of the method body
} curly brace for the closing of the method body
In Java, any set of statements between braces "{" and "}" define a program block;

; semicolon indicating the end of the statement

Data of Java Objects are stored in instance variables(also called fields);

The operations that can act on data, expressing the "messages" objects respond to are called methods;
A method's name combined with the number and types of its parameters is called a method's signature, for it takes all these parts to determine the actual method to perform for a certain method call. The signature of a method does not include the type that the method returns;

the syntax for defining a method is as follows:
modifiers type name(type0 parameter0, .., typen-1 parametern-1){
//method body
}

The name of a class, method, or variable in Java is called identifier, which can be any string of characters as long as it begins with a letter and consists of letters, numbers, and underscore characters.

Class modifiers are optional keywords that precede the class keyword.

base type numbers are not themselves objects, to get around this obstacle, Java defines a wrapper class for each numeric base Type. We call these classes number classes.

A literal is any "constant" value that can be used in an assignment or other expression. e.g. null, true , false,  1.12 or String Literal like " you are good"

Java expressions involve composing literals and variables with operators. e.g. + , - , and etc
Logic Operator: <= , == , !== , > , < , ! and etc.
String Concatenation Operator(+)

Casting  is an operation that allows us to change the type of a variable. In essence, we can take a variable of one type and cast it into an equivalent variable of another type.
Ordinary Casting: when casting from a double to an int, we may lose precision. But we cast an int to a double without this worry.
There are cases where Java will perform an implicit cast to the type of the assignment variable, provided there is no loss of precision. int i =3 ; double result, d = 3.2; result = i/d; // i was cast to a double

Autoboxing(since java 5.0), will convert the base type to its corresonsidng Number object.

Integer i = new Integer(9);
Integer j = new Integer(13);
int k = 9 + 13;    // always OK
Integer l = i + j; // error in versions prior to 5.0!

Likewise, any time a base type is expected in an expression involving Number reference,  that Number object is changed to the corresponding base type, in an operation called unboxing.
int i = 4;
int j = 5;
Integer k = new Integer(i + j); // always OK
Integer l = i + j; // would have been an error, but okay now 






Comments

Popular posts from this blog

Stretch a row if data overflows in jasper reports

It is very common that some columns of the report need to stretch to show all the content in that column. But  if you just specify the property " stretch with overflow' to that column(we called text field in jasper report world) , it will just stretch that column and won't change other columns, so the row could be ridiculous. Haven't find the solution from internet yet. So I just review the properties in iReport one by one and find two useful properties(the bold highlighted in example below) which resolve the problems.   example:
<band height="20" splitType="Stretch"> <textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true"> <reportElement stretchType="RelativeToTallestObject" mode="Opaque" x="192" y="0" width="183" height="20"/> <box leftPadding="2"> <pen lineWidth="0.25"/> …

JasperReports - Configuration Reference

Spring - Operations with jdbcTemplate

This class manages all the database communication and exception handling using a java.sql.Connection that is obtained from the provided DataSource. JdbcTemplate is a stateless and threadsafe class and you can safely instantiate a single instance to be used for each DAO.


Use of Callback Methods
JdbcTemplate is based on a template style of programming common to many other parts of Spring. Some method calls are handled entirely by the JdbcTemplate, while others require the calling class to provide callback methods that contain the implementation for parts of the JDBC workflow. This is another form of Inversion of Control. Your application code hands over the responsibility of managing the database access to the template class. The template class in turn calls back to your application code when it needs some detail processing filled in. These callback methods are allowed to throw a java.sql.SQLException, since the framework will be able to catch this exception and use its built-in excepti…