The idea , is that a word must be readable , and understandable on first eye sight . So each word has a usable meaning on eye sight . For example , imagine that a voice recorder api , is being written :
import static java .lang .System .out;
import java .io .IOException;
import java .io .InputStream;
import java .nio .file .Files;
interface AV_Audio_Recorder{
public void record (InputStream inputStream );
public void stop ( ); };
interface Dictionary{ };
interface Url{ };
public class AudioRecorder{
boolean audioSession_active;
AV_Audio_Recorder audioCapture_recorder;
Dictionary audioCapture_settings;
boolean audioCapture_recording;
String callback_id;
Url app_tmpDirectory_URL;
public void audioCapture_Start( ){
try (InputStream inputStream =
Files .newInputStream ((Files
.createTempFile ("capture" , "m4a" ) ))){
audioCapture_recorder .record (inputStream ); }
catch (IOException ioException ){ }
out .println ("Recording Started" );}
public void audioCapture_Stop( ){
audioCapture_recorder .stop ( );
out .println ("Recording Stoped" ); }}
import static java.lang.System.out;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
interface AVAudioRecorder {
public void record(InputStream inputStream);
public void stop();
};
interface Dictionary {
};
interface Url {
};
public class AudioRecorder {
boolean audioSessionActive;
AVAudioRecorder audioCaptureRecorder;
Dictionary audioCaptureSettings;
boolean audioCaptureRecording;
String callbackId;
Url apptTmpDirectoryUrl;
public void audioCaptureStart() {
try (InputStream inputStream =
Files.newInputStream(Files.createTempFile("capture", "m4a"))) {
audioCaptureRecorder.record(inputStream);
} catch (IOException ioException) {
}
out.println("Recording Started");
}
public void audioCaptureStop() {
audioCaptureRecorder.stop();
out.println("Recording Stoped");
}
}
So the idea is to have a word readable and understandable code , this can be done as follows :
A variable , such as audioCapture_recorder , must be all lower case , its eyesight meaningful words , must be separated using _ .
A method , such as audioCapture_Start , has its first word , all lower case , its subsequent words , start with a capital letter , and its forming words , separated using _ .
Interfaces , and classes , such as AV_Audio_Recorder , must have each of their word first letter , being capital , and forming eyesight meaningful words , separated using _ .
Whitespace is very important to use . It is used to separated imports , and invocation of methods and fields . It is also used to separate the parameters list , from the method name .
Brackets and parenthesis , are accumulated into one place , to make the code look terser .
An android code , that illustrates , this concept , the original code can be found here .
package com .twiserandom .bitmap_canvas_paint;
import android .graphics .Bitmap;
import android .graphics .Canvas;
import android .graphics .Paint;
import android .support .annotation .ColorInt;
import android .support .v7 .app. AppCompatActivity; // AppCompat_Activity instead of AppCompatActivity
import android .os .Bundle;
import android .view .ViewGroup;
import android .widget .ImageView;
import android .widget .LinearLayout;
public class BitmapCanvas_PaintActivity extends AppCompatActivity {
/* Create a 32 bit int color .*/
@ColorInt
public static final int final_color_fuchsia = 0xFFFF00FF;
ImageView ivOne , ivTwo;
@Override
protected void onCreate (Bundle savedInstanceState ){
super .onCreate (savedInstanceState );
/* Create a linear layout with vertical orientation .*/
LinearLayout ll = new LinearLayout (this );
ll .setOrientation (LinearLayout .VERTICAL );
/* Create two imageViews .*/
ivOne = new ImageView (this );
ivTwo = new ImageView (this );
/* Set the layoutparam of the imageViews
* width : match parent
* height: wrap content
* weight : 1 .*/
ll .addView (ivOne ,
new LinearLayout
.LayoutParams
(ViewGroup .LayoutParams .MATCH_PARENT ,
ViewGroup .LayoutParams .WRAP_CONTENT ,
1 ) );
ll .addView (ivTwo ,
new LinearLayout
.LayoutParams(ViewGroup .LayoutParams .MATCH_PARENT ,
ViewGroup .LayoutParams .WRAP_CONTENT , 1 ) );
/* Create bitmap with 200px width , and height of 100px .*/
Bitmap bm = Bitmap .createBitmap (200 , 100 , Bitmap .Config .ARGB_8888 );
/* Create a canvas object .*/
Canvas cv = new Canvas (bm );
/* Create a paint object .*/
Paint paint = new Paint ( );
paint .setColor (final_color_fuchsia );
/* Draw a rectangle on the bitmap .*/
cv .drawRect (0 , 0 , 200 , 100 , paint );
/* Crete a copy of the bitmap
from x , y
with width and height .*/
Bitmap bmCopy = Bitmap .createBitmap (bm , 30 , 40 , 100 , 50 );
bmCopy .eraseColor (0xFF123456 );
/* Set scale type of the imageViews to center
No scaling is performed on the bitmap
bitmap is just centered .*/
ivOne .setScaleType (ImageView .ScaleType .CENTER );
ivTwo .setScaleType (ImageView .ScaleType .CENTER );
/* Set the bitmaps on the image views .*/
ivOne .setImageBitmap (bm );
ivTwo .setImageBitmap (bmCopy );
/* Set the activity content view
to ll : linearlayout
it will take the full width and height by default .*/
setContentView (ll ); }}
Another example , which original code , can be found here , near the bottom of the page .
package com .difyel .test ;
import java .io .IOException;
import java .io .PrintWriter;
import java .util .Enumeration;
import javax .servlet .annotation .WebServlet;
import javax .servlet .annotation .WebInitParam;
import javax .servlet .ServletException;
import javax .servlet .ServletConfig;
import javax .servlet .http .HttpServlet;
import javax .servlet .http .HttpServletRequest;
import javax .servlet .http .HttpServletResponse;
@WebServlet(
urlPatterns = "/servlet-get-init-parameters",
initParams = {
@WebInitParam (name="an-init-param-name" , value="an-init-param-value" ) })
public class ServletGetInitParameter extends HttpServlet{
protected void doGet (HttpServletRequest req , HttpServletResponse resp ) throws IOException , ServletException{
PrintWriter out = resp .getWriter();
out .println ("<html>" );
out .println ("<head>" );
out .println ("<title> Servlet page , Get init parameters</title>" );
out .println ("</head>" );
out .println ("<body>" );
out .println ("<ul>" );
ServletConfig config = this .getServletConfig ( );
/* Get the ServletConfig object .*/
out .println("<li>Servlet name : " + config .getServletName ( ) + "</li>" );
/* Print the servlet name .*/
Enumeration <String > init_parameters_name = config .getInitParameterNames ( );
/*Get the init parameter names .*/
if (init_parameters_name .hasMoreElements ( ) ){
out .println ("<li>" );
out .println ("<p>Init Parameter Names : Init Parameter values<p>" );
out .println ("<ul>" );
while (init_parameters_name .hasMoreElements ( ) ){
String init_parameter_name = init_parameters_name .nextElement ( );
String init_parameter_value = config .getInitParameter (init_parameter_name );
out .println ("<li>" + init_parameter_name + " : " + init_parameter_value + "</li>" ); }
out .println ("</ul>" );
out .println ("</li>" ); }
else{
out .println ("<li> No init parameters were passed to the servlet . </li>" ); }
out .println ("<li>Servlet context name : " + config .getServletContext ( ) .getServletContextName ( ) + "</li>" );
/*Print the servlet context name*/
out .println ("</body>" );
out .println ("</html>" ); }}
