Java Basic concept Homework Help
Java Basic concept:
When we look into java program it is basically using the concept of class and object. So now we concentrate on the class, object and method.
Class:
A class is a user defined blueprint which contains the entire set of similar data and functions that the object possess.
Object:
An object contains of state and behaviour. In the real world we may see many objects like house, car, dog etc. the object of class is known as instance.
Method:
A method is a logical operation written by programmer. A class may have many method that is depends on the all the actions are executed.
First Java program:
Now we consider simple code that will print first program.
Example:
{`public class MyFirstProgram { ; /* My first program. It will print “First Program” as the output */ public static void main(String []args) { ; System.out.println("First Program"); // prints First program } ; } ;`}
Steps for save, compile and run the java program:
- Using notepad type the code.
- Save this file as MyFirstProgram.Java.
- Using command prompt compile the program using following syntax “javac MyFirstProgram.Java”.
- If there is no error using this syntax for run your program “java MyFirstProgram.Java”.
- Now you can see your output as ‘First Program’.
Output:
C:\> javac MyFirstProgram.java
C:\> java MyFirstProgram
First Program
Key points must remember while creating your program
- Class Name – first letter of class and inner word must be Uppercase.
Ex: class MyFirstProgram
- Method Name - first letter of method must be lower case and inner word must be Uppercase.
Ex: public firstMethodname()
- File Name – file name and class name must be same. If more than one class used for your program means the main class name you have to use. If it is not match the compiler will not compile it. It also case sensitive.
Ex: if 'MyFirstProgram' is the class name means then the file should be saved as ‘MyFirstProgram.java’
- Main method () – Every program must have main method because the program execution start with main method.
Ex: public static void main(String []args)
o public
: public means that we can call the method from outside the class.
o static
: No need to create an object for static methods to run. It can run itself.
o void
: It cannot return anything.
o main
: It is the method name.
o String[] args
: it is used for argument passing as a string to command line argument.
Identifiers:
In java the name used for the methods, class and variables are known as identifiers.
Identifiers must start with a letter that is (A - Z or a – z),$,_(underscore).
It is case sensitive, keyword cannot be used.
Ex: name, $age, _name
Ex: 4age, #name ( wrong identifiers)
Java Tutorials
- Environment setup
- Basic concept
- Object Classes
- Constructors
- OOPS in java
- data abstraction
- Variable Types
- Modifiers
- Operators
- Loop Controls
- Decision Making
- Strings
- Arrays
- Date and Time
- Methods in java
Java sample assignments
Programming Topics
- Ada
- Assembly Language
- AutoCAD
- BASIC
- Computer virus
- C Programming
- Euphoria
- Fortran Homework Help
- Game programming language
- Java Assignment Help
- JavaScript
- Java Servlets Help
- Machine Language
- Matlab
- Pascal
- Perl
- PHP
- Python
- Ruby
- Servlet Life Cycle
- Smalltalk
- SOAP
- Visual Basic
- COBOL
- Lisp
- Logo Help
- Plankalkul Help
- Prolog
- REBOL
- Rexx
- Scheme Help
- TCL
- ToonTalk Help