Beginners Java Tutorial – Programming Part 1

November 20, 2008 at 12:12 pm Leave a comment

We also have some excellent Beginners Programming Java tutorials that use high quality narrated videos and practical working files to teach the fundamentals of programming in Java Beginners Java Tutorial Videos

.

Beginners Java Tutorial – Part 1

The Java language is currently one of the most widely used programming platforms, and can be used to build both desktop and Web applications. Java is used to develop with the Object Oriented technique, in which applications are characterised as a set of interacting ‘objects’, the objects being modules of code. This Java tutorial assumes no prior knowledge and aims to teach the basic fundamentals of Java Programming.

To start programming with Java, you will need:

Using an IDE will make your Java projects straightforward to manage and develop, and is therefore strongly recommended.

Java compilation

When you write code in a programming language, the compiler for the language generally translates your code into machine code for a particular system. This is code that can be run directly by the hardware of a computer with a specific operating system, architecture etc. The situation is slightly different with Java. When you create and compile your Java code, the end result is code that runs on the Java Virtual Machine, not code that runs directly on any actual machine. When the application is actually run, the JVM translates it into machine code for the specific computer it’s running on.

The process is as follows: when you write Java programs, your code is contained in .java files; when you compile and run these programs, .class files are generated – these contain bytecode, which runs on the JVM. The JVM code is then translated into machine code for the host machine. This means that when you create your Java applications, your compiled code can run on any operating system with Java installed, as it’s only translated into machine code when it’s actually run – this is one of the main advantages to using Java.

It isn’t necessary that you understand these concepts to get started with Java so don’t worry too much if it all seems confusing at this stage – it’ll begin to make more sense as you start to write programs.

Your first program

Once you’ve chosen and installed an IDE for Java, you’ll need to familiarise yourself with its interface; you may also need to perform setup tasks such as choosing a workspace location – see the instructions for your particular IDE. Within your chosen IDE, you’ll need to create a new project each time you want to start a new Java program. Each project will contain at least one package, with the package(s) containing your source .java files.

Different IDEs provide different levels of assistance, for example, when you create a new project/ class in Eclipse or Netbeans, the environment automatically creates a default package for your code.

Each .java file in the project will generally represent a ‘class’ in your application, grouping together related code. Each of these ‘class declarations’ provides a blueprint for a type of Object in your application. Again, the notion of Object will become clearer as your Java skills progress.

Every project will contain at least one class: the ‘Main’ class. When your Java application is compiled and run, the first code that is executed is the code inside the ‘main method’ – this code will be inside your Main class. Create a new Project in your IDE and name it MyFirstJava. If you’re using Netbeans choose Create Main class, entering myfirstjava.MyFirstJava as the name. If you’re using Eclipse create a new class inside your project and name it MyFirstJava. Select your MyFirstJava class and enter the following code (your IDE may have filled some of it in for you):

//class declaration
public class MyFirstJava
{
//main method
	public static void main(String[] args)
	{
//code to be executed at runtime
		System.out.println("Well Hello There");
	}
}

Note: If you’ve programmed with scripting languages before, you can think of methods as functions.

If you compile and run the program you should see the phrase written to the standard output console (this should be visible within your IDE interface). All that the code does is write a message out, as this is all that’s contained within the main method.

You really don’t need to understand all of what’s going on here, in fact it’s easier when you’re starting out to just treat it as a formula that works; you’ll understand the details later. Each time you create a new Java program just follow this pattern and enter your code within the main method to start with, and the rest will soon follow. Next Java tutorial – Objects and Classes .

Advertisement

Entry filed under: Java. Tags: , , .

Mac 10.5 Leopard Tutorials – Right Click Mouse Beginners Java Tutorial – Objects and Classes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed



%d bloggers like this: