Windows 7: Open Command Window Here

How can I add a Command Prompt option to the default Explorer right click context menu?

Method: Through the Registry
1. Navigate in your Registry to Microsoft Registry

HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell
and create a key called “Command Prompt” without the quotes.

2. Set the default string to whatever text you want to appear in the right-click menu.
open command window

3. Create a new key within your newly created command prompt named “command,” and set the default string to cmd.exe /k pushd %1
open command window1

4. You may need to add %SystemRoot%\system32\ before the cmd.exe if the executable can’t be found.

The changes should take place immediately. Right click a folder and your new menu item should appear.

open command window2

4.1. A Runnable Object-Oriented Program

Let’s look at an object-oriented program that runs and generates actual output. It features a class called BankAccount that models a checking account at a bank. The program creates an account with an opening balance, displays the balance, makes a deposit and a withdrawal, and then displays the new balance. Here’s the listing for bank.java:

The BankAccount Class
The only data field in the BankAccount class is the amount of money in the account,
called balance. There are three methods. The deposit() method adds an amount to
the balance, withdrawal() subtracts an amount, and display() displays the balance.

// bank.java
// demonstrates basic OOP syntax
// to run this program: C:\>java BankApp
import java.io.*; // for I/O
////////////////////////////////////////////////////////////////
class BankAccount
{
	private double balance; // account balance
	public BankAccount(double openingBalance) // constructor
	{
		balance = openingBalance;
	}
	public void deposit(double amount) // makes deposit
	{
		balance = balance + amount;
	}
	public void withdraw(double amount) // makes withdrawal
	{
		balance = balance - amount;
	}
	public void display() // displays balance
	{
		System.out.println("balance=" + balance);
	}
} // end class BankAccount
////////////////////////////////////////////////////////////////

Constructors
The BankAccount class also features a constructor. A constructor is a special method
that’s called automatically whenever a new object is created. A constructor always has
exactly the same name as the class, so this one is called BankAccount(). This
constructor has one argument, which is used to set the opening balance when the account is created.

class BankAccount
{
	private double balance; // account balance
	public BankAccount(double openingBalance) // constructor
	{
		balance = openingBalance;
	}
       //

} // end class BankAccount
////////////////////////////////////////////////////////////////

Public and Private
Notice the keywords publicand privatein the BankAccountclass. These keywords
are access modifiersand determine what methods can access a method or field. The
balancefield is preceded by private. A field or method that is private can only be
accessed by methods that are part of the same class. Thus, balancecannot be
accessed by statements in main(), because main()is not a method in BankAccount.
However, all the methods in BankAccounthave the access modifier public, so they
can be accessed by methods in other classes. That’s why statements in main()can call
deposit(), withdrawal(), and display().
Data fields in a class are typically made private and methods are made public. This
protects the data; it can’t be accidentally modified by methods of other classes. Any
outside entity that needs to access data in a class must do so using a method of the
same class. Data is like a queen bee, kept hidden in the middle of the hive, fed and cared
for by worker-bee methods.

The BankApp Class
Every Java application must have a main() method; execution of the program
starts at the beginning of main(), as you can see in the bank.java listing. (You don’t
need to worry yet about the String[] args argument in main().)

class BankApp
{
	public static void main(String[] args)
	{
		BankAccount ba1 = new BankAccount(100.00); // create acct
		System.out.print("Before transactions, ");
		ba1.display(); // display balance
		ba1.deposit(74.35); // make deposit
		ba1.withdraw(20.00); // make withdrawal
		System.out.print("After transactions, ");
		ba1.display(); // display balance
	} // end main()
} // end class BankApp
//output
//Before transactions, balance=100
//After transactions, balance=154.35

The main()method creates an object of class BankAccount, initialized to a value of
100.00, which is the opening balance, with this statement:

BankAccount ba1 = new BankAccount(100.00); // create acct

The System.out.print()method displays the string used as its argument, Before
transactions,, and the account displays its balance with the following statement:

ba1.display();

The program then makes a deposit to, and a withdrawal from, the account:

ba1.deposit(74.35);
ba1.withdraw(20.00);

Finally, the program displays the new account balance and terminates.
To execute the program from a DOS box, you type java BankApp

4. Objects and Classes

http://dictionary.cambridge.org/dictionary/american-english/furnace?q=Furnace

http://dictionary.cambridge.org/dictionary/american-english/thermostat?q=Thermostat

http://tratu.soha.vn/dict/en_vn/Furnace

http://tratu.soha.vn/dict/en_vn/Thermostat
Objects

Here’s the amazing breakthrough that is the key to OOP: An object contains both
functions and variables. A thermostat object, for example, would contain not only
furnace_on() and furnace_off() functions, but also currentTemp and desiredTemp. Incidentally, before going further we should note that in Java, functions are called methods and variables are called fields.

This new entity, the object, solves several problems simultaneously. Not only does a programming object correspond more accurately to objects in the real world, it also solves the problem engendered by global data in the procedural model. The
furnace_on() and furnace_off() methods can access currentTempand desiredTemp. These variables are hidden from methods that are not part of thermostat, however, so they are less likely to be accidentally changed by a rogue method.

Classes
You might think that the idea of an object would be enough for one programming
revolution, but there’s more. Early on, it was realized that you might want to make several objects of the same type. Maybe you’re writing a furnace control program for an entire apartment house, for example, and you need several dozen thermostat objects in your program. It seems a shame to go to the trouble of specifying each one separately. Thus, the idea of classes was born.
A classis a specification—a blueprint—for one or more objects. Here’s how a
thermostat class, for example, might look in Java:

/**
 *  @purpose: This program is to specify a thermostat class
 *  @author: hoiquanphanmem 
 *  @date: 12/13/2014 
 */

class thermostat
{
    private float currentTemp();
    private float desiredTemp();  
    public void furnace_on()
    {
    // method body goes here
    }   
    public void furnace_off()
    {
    // method body goes here
    }
} // end class thermostat

The Java keyword class introduces the class specification, followed by the name you want to give the class; here it’s thermostat. Enclosed in curly brackets are the fields and methods (variables and functions) that make up the class. We’ve left out the body of the methods; normally there would be many lines of program code for each one. C programmers will recognize this syntax as similar to a structure, while C++ programmers will notice that it’svery much like a class in C++, except that there’s no semicolon at the end. (Why did we need the semicolon in C++ anyway?)

Creating Objects
Specifying a class doesn’t create any objects of that class. (In the same way specifying a structure in C doesn’t create any variables.) To actually create objects in Java you must use the keyword new. At the same time an object is created, you need to store a reference to it in a variable of suitable type; that is, the same type as the class.

What’s a reference? We’ll discuss references in more detail later. In the meantime, think of it as a name for an object. (It’s actually the object’s address, but you don’t need to know that.)
Here’s how we would create two references to type thermostat, create two new
thermostat objects, and store references to them in these variables:


    thermostat therm1, therm2; // create two references
    therm1 = new thermostat(); // create two objects and
    therm2 = new thermostat(); // store references to them

Incidentally, creating an object is also called instantiating it, and an object is often
referred to as an instance of a class.

Accessing Object Methods

Once you’ve specified a class and created some objects of that class, other parts of your program need to interact with these objects. How do they do that?
Typically, other parts of the program interact with an object’s methods (functions), not with its data (fields). For example, to tell the therm2 object to turn on the furnace, we would say

    therm2.furnace_on();

The dot operator (.) associates an object with one of its methods (or occasionally with one of its fields).

To summarize:

• Objects contain both methods (functions) and fields (data).
• A class is a specification for any number of objects.
• To create an object, you use the keyword new in conjunction with the class name.
• To invoke a method for a particular object you use the dot operator.
These concepts are deep and far-reaching. It’s almost impossible to assimilate them the first time you see them, so don’t worry if you feel a bit confused. As you see more classes and what they do, the mist should start to clear.

3. Introduction to Java

1. Brief History. The Java language began as a language for programming electronic devices, though the original project was never completed. Its creator was James Gosling, of Sun Microsystems. The language was developed privately starting in 1991, and was made publicly available in 1994.

2. Interpreted Language. When you “compile” Java code, the result is not executable binary code, targeted to a particular machine; instead, the result is bytecode, having a portable intermediate code format. The bytecode is then executed by running an interpreter,called the Java Virtual Machine(JVM). This approach makes Java code highly portable; Java will run on any platform for which a JVM has been created.

3. JIT. Interpreters run much more slowly than native binary executable code. Java
performance is boosted considerably in modern-day JVMs because of the inclusion of a just-in-time compiler; this feature compiles frequently occurring bytecode
sequences into native binary code and caches the results, re-using the cache as
needed. The result is that Java runs almost as fast as C++ in typical cases.
4. No Pointers. Compared to C++, Java is a simple language, though some feel that Java is becoming too complicated with successive releases. One of the most significant features that simplifies use compared with C and C++ is that Java does not use “pointers” – which means that the programmer is not responsible for managing memory. Memory management is handled automatically in Java by means of a garbage collector.The garbage collector is run by the JVM at different times during program execution to return to memory all unusued object references.

5. Java Is An OOP Language. Java is an OO programming language, and succeeds in this better than C++, which (for the sake of backwards compatibility with C) supports a non-OO programming style (in C++, OO programming is “optional”).

6. Convenient Libraries. Java provides convenient libraries for handling files and
streams, networking, http, gui development, and database connection. Compared to languages like C and C++, the increased ease of use is significant.

7. Good Security Model. Java has a relatively good security model to support use over networks and distibuted environments. Though security holes are still found
sometimes, these are rare and quickly patched.

2. Using IDE Eclipse and Welcome.java

1. Using the Command-Line Tools to compile and launch a Java program from the command line.

/**
 *  @purpose: This program will print the Welcome message 
 *  @author: hoiquanphanmem 
 *  @date: 11/18/2014 
 */

public class Welcome
{
   public static void main(String[] args)
   {
      String[] greeting = new String[3];
      greeting[0] = "Welcome to Core Java";
      greeting[1] = "by hoi quan ngoai ngu giao tiep";
      greeting[2] = "va cong nghe phan mem";

      for (String g : greeting)
         System.out.println(g);
   }
}

2. Using IDE Eclipse IDE Eclipse for Java developer is an integrated development environment that is freely available from http://eclipse.org. a. This is how to install IDE Eclipse for Java Developer Step 1: Download the eclipse Step 2: Extract the zip file Step 3: Extract the zip file to C:\ b.This is how to compile  and run a program with IDE Eclipse Step 1: Start IDE Eclipse Step 2: Select a workspace Step 3: Close the welcome window Step 4: Select File -> New -> Java Project from the menu Step 5: Supply the project name “Welcome” and click the “Next” button Step 6: Click the “Finish” button. The Project is now created Step 7: right click on “source”, Select New -> File Step 8: Supply the file name “Welcome” and click the Finish button. The source file is now created Step 9: Edit the source code, type the Welcome.Java program in the editor Step 10: Click on the project name (Welcome) in the leftmost pane. Select Run -> Run As -> Java Application 3. The Welcome Java Program Let’s look more closely at about the Welcome Java program. Java Keywords

  • public Makes a class, method, or variable accessible from any other class.
  • class Keyword used to specify a class
  • new Used to instantiate an object by invoking the constructor.
  • static Makes a method or a variable belong to a class as opposed to an instance
  • for Used to perform a conditional loop for a block of code
  • void Indicates no return type for a method
  • main method

When you use java ClassName to run a compiled program, the Java virtual machine always starts execution with the code in the main method in the class you indicate. Thus, you must have a main method in the source file for your class for your code to execute. You can, of course, add your own methods to a class and call them from the main method. Notice the braces { }in the source code. In Java, as in C/C++, braces delineate the parts (usually called blocks) in your program. In Java, the code for any method must be started by an opening brace {and ended by a closing brace }

1. Working With The JDK and Hello.java

1. The JDK Distribution

java_jdk_distribution

bin: The compiler and tools
include: Files for compiling native methods (see Volume II)
jre: Java runtime environment files
lib: Library files
src: The library source (after expanding src.zip)

2. Create a hello world example by typing the following lines of code in WordPad (or Notepad), and save in a convenient location as Hello.java.

/**
 *  @purpose: This program will print the Hello message 
 *  @author: hoiquanphanmem 
 *  @date: 11/10/2014 
 */

public class Hello
{
   public static void main(String[] args)
   {
      System.out.println("Hello World");
   }
}

3. Then compile by typing the following command in the console javac Hello.java

javac_hello
Notice a new file Hello.class has been created.

4. Then run it with the command java Hello

java_hello

5. To create this program, you will

  • Create a source fileA source file contains code, written in the Java programming language, that you and other programmers can understand. You can use any text editor to create and edit source files.
  • Compile the source file into a .class fileThe Java programming language compiler (javac) takes your source file and translates its text into instructions that the Java virtual machine can understand. The instructions contained within this file are known as bytecodes.
  • Run the programThe Java application launcher tool (java) uses the Java virtual machine to run your application.

6. Useful link

0. STANDARDS FOR GOOD PROGRAMMING STYLE

A program that is written with careful attention to style is easier to read, easier to correct if it contains mistakes, and easier to change later on.
1. Every program should begin with a prologue describing its purpose, author and so on.
2. A program should be laid out so that elements which are naturally thought of as a group are made to look like a unit. One way of doing this is by indenting everything in that group by the same amount – by using tabs, not spaces. Another way is to skip a line between pieces that are logically thought of as separate. In both cases, it is often wise to precede the group of related statements by a comment which describes their purpose. A
corollary of this point is:
Whenever the purpose of a segment of code is not so clear as to be self-documenting,
precede those lines with comments to describe in plain English what is being accomplished.
3. All programs you write should LOOK neat and orderly.
4. Every method defined in a class should start with a line or two of comments in simple English to define/clarify its purpose.
5. All programmer defined identifiers should have meaningful, unambiguous names. That is, its name should clearly express to the reader its purpose.
6. A program should be “robust”. This means it will not crash when confronted with easily anticipated user errors.