Reading:  

Quick introduction to Java Programming language - Part 1


Introduction to Java Syntax

The first java program to print “Hello Java” as shown below:

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

Now to save the above program, compile and run. The steps given:

  • The code is written in notepad as above.
  • The file need to save as: JavaProgram.java (program name should be the class name).
  • Go to command prompt and go to the directory where the class file saved. Assume it is C:\.
  • To compile the code type “javacJavaProgram.java”and click enter. If there are no errors in code, the command prompt will move to the next line.
  • To run the compiled code type “java JavaProgram”.
  • Now will see the output printed as “Hello Java”.
  • Case Sensitivity: Java is case sensitive, which means there is difference between uppercase and lowercase in java.
  • Class Name: Do not use any special characters, give a meaning fullname and everyfirst character of a word should be in uppercase.Eg: FirstProgram.java
  • Program File Name: The program file should be same as the class name.
  • Method Names: Method name first word should start with a Lower Case letter and second word should start with upper case. Eg: public void getArea()
  • Public static void main(String args[]):Java should have main() method which is a mandatory to start program execution.

Basic Java Standards/Syntax need to be followed:

  • Case Sensitivity: Java is case sensitive, which means there is difference between uppercase and lowercase in java.
  • Class Name: Do not use any special characters, give a meaning fullname and everyfirst character of a word should be in uppercase.Eg: FirstProgram.java
  • Program File Name: The program file should be same as the class name.
  • Method Names: Method name first word should start with a Lower Case letter and second word should start with upper case. Eg: public void getArea()
  • Public static void main(String args[]):Java should have main() method which is a mandatory to start program execution.

Identifiers of Java:

Names given by the users/developers to identify a component such as class, variable, method etc. are known as identifiers.

Eg: Class Name: class ShapeOfBox, Method Name: public void getArea(), Variable Name: intboxNumber, intanimal_age;

Points to remember about Identifiers:

  • No special characters are allowed.
  • Keyword cannot be used as identifiers.

Variables of Java:

It is a temporary space in a memory which is used to store the value. Types of variables are:

1. Variables declared within a method are known as Local variables. It must be initialized before using it.

2. Variables declared inside the class (not in-side the method) are known as Global variables/Class variables.

3. Variables declared at the creation of object instance are known as Instance variables. Literals of Java: Some user data are known as Literals. Eg. System.out.println (“Hello Java”); “Hello Java” is literals here.

Literals of Java:

Some user data are known as Literals. Eg. System.out.println ("Hello Java"); "Hello Java" is literals here.

Java Comments:

It is a non-executable statement. Eg: //Login details à(Single line comment operator), /*--------*/ à(Multiline comment operator)   

public class JavaProgram{

    /* This is a java program.
     * This will print 'Hello Java' as the output
* This is also an example multiline comment block */ public static void main(String[]args){ // This is a single line comment /* This is also a single line comment. */ System.out.println("Hello Java"); } }

 

Keywords of Java:

These are pre-defined words, each keyword has specific meaning. All keywords are in lower case.

The Java Keywords are:

Abstract

assert

boolean

break

Byte

case

catch

char

Class

const

continue

default

Do

double

else

enum

Extends

final

finally

float

For

goto

if

implements

Import

instanceof

int

interface

Long

native

new

package

Private

protected

public

return

Short

static

strictfp

super

Switch

synchronized

this

throw

Throws

transient

try

void

Volatile

while

 

 

Java Operators:        

Symbols used for some specific operations are called operators.

Eg: +, -, *, / etc

Java Modifiers:

It is used to modify classes, methods, etc.

Types of modifiers:

  • Access Modifiers: public, default, protected, private
  • Non-access Modifiers: final, abstract

Description

This tutorial is targetted for beginers seeking a quick get on with guide on Java programming language. 3 parts include 

  1. Java basics
  2. Object oriented programming
  3. Advance concepts

Each part is subdivided in multiple chapters.

Java basics has the following chapters

  1. Introduction
  2. Environment Setup
  3. Basic Syntax
  4. Objects and Classes
  5. Basic Data Types
  6. Variable Types
  7. Modifier Types
  8. Basic Operators
  9. Loops
  10. Decision Making
  11. Numbers Class
  12. Character and String Class
  13. Arrays
  14. Date and Time
  15. Regular Expression
  16. Methods
  17. Streams, Files and I/O
  18. Exceptions Handling

Thanks for reading and as always, your feedback is very important to us. Let us know how we can improve and if you found any issues with this write up, send us a correction.



Audience

Beginners or students seeking a refresher on Java language

Author: Subject Coach
Added on: 9th Mar 2015

You must be logged in as Student to ask a Question.

None just yet!