Saturday, December 3, 2016
Basic things for coding
Main Method
class ClassName{
//Body
}
Class is the basic element of the Object Oriented Programming.
A JAVA program is a collection of classes.
A class body contains
Collection of fields or variables (Attributes/Fields)
Operations performed on those fields (Behavior/Methods)
NOTE: Each and Everything (Except “importing packages”) in
a JAVA program should be included within a class.
Driver Class
Driver class contains the main method.
class HelloWorld{
public static void main(String[] args){
//method body
}
}
Naming Conventions for classes
1.The class names begin with upper case letters.
class Student{
public static void main(String[] args){
//method body
}
}
2.When there are more than one word to be combined, the subsequent words start with upper case letters or combine them using underscores(_).
class StudentDetails{ class Student_Details{
//method body //method body
} }
Escape Sequences
\n→Newline –Positions the cursor at the beginning of the next line
\t→Horizontal tab –Move the screen cursor to the next tab position
\r→Carriage returns -Positions the beginning of the current line. Do not advance to the next line. Any characters output after the carriage return overwrites the previous characters.
\\→Backslash
\”→Double quote
\’→Single quote
Write the code given below using NotePad
\t→Horizontal tab –Move the screen cursor to the next tab position
\r→Carriage returns -Positions the beginning of the current line. Do not advance to the next line. Any characters output after the carriage return overwrites the previous characters.
\\→Backslash
\”→Double quote
\’→Single quote
Write the code given below using NotePad
Then compile and run it
Watch this videoFriday, December 2, 2016
Write your first Java program
Open the Notepad and type the following code
Save it as “ HelloWorld.java” inside j folder in your D:\ drive.(You can save anywhere you wish to save)
Make sure to use double quotes(“”) or change the save as type into All Files.
Otherwise file extension will be .txt
Compile :
1.Open Command Prompt.
2.Change your directory to “D:\j”
3.Execute the command : javac HelloWorld.java
4.If there is no error, HelloWorld.class file will be created in your folder
5.Finally execute the command:java HelloWorld
Otherwise you can use IDE(Integrated Development Environment) for java development
You can execute above Java program using Eclipse
Save it as “ HelloWorld.java” inside j folder in your D:\ drive.(You can save anywhere you wish to save)
Make sure to use double quotes(“”) or change the save as type into All Files.
Otherwise file extension will be .txt
Compile :
1.Open Command Prompt.
2.Change your directory to “D:\j”
3.Execute the command : javac HelloWorld.java
4.If there is no error, HelloWorld.class file will be created in your folder
5.Finally execute the command:java HelloWorld
Otherwise you can use IDE(Integrated Development Environment) for java development
You can execute above Java program using Eclipse
Introduction & Installing
Install Java Development Kit (JDK)
Download JDK 1.8
http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
You must select the correct software (32/64 bit) depending on your platform
After downloading the software, install it completely and set PATH.
Control panel→System→Advanced→Environment Variables
Set path to the bin folder where the java is installed
C:\Program Files\Java\jdk1.8.0_45\bin;
Download JDK 1.8
http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
You must select the correct software (32/64 bit) depending on your platform
After downloading the software, install it completely and set PATH.
Control panel→System→Advanced→Environment Variables
Set path to the bin folder where the java is installed
C:\Program Files\Java\jdk1.8.0_45\bin;
Subscribe to:
Posts (Atom)