Code :
// Hello world program in JAVA
class hello
{
public static void main(String args[]) // this is the main method
{
System.out.println("Hello World \n");
}
}
Preview :
2. JAVA Translation
Java Source Code -> (Java Compiler) -> Java Byte Code -> (Byte Code Interpreter) -> Machine Language -> output
Java Source Code : .java file
Java Byte Code : .class file
3. Comments & Conventions
// - Single line comment
/*...*/ - block comment ( multiple lines )
- Java is case sensitive
Code :
public class secondFile
{
public static void main(String[] args)
{
System.out.print(" Java is a very portable language ");
System.out.println(" and can run in different tpes of computers. ");
System.out.println(" this is next line!!!! ");
}
}
4. Keywords
abstract | continue | for | new | switch |
assert*** | default | goto* | package | synchronized |
boolean | do | if | private | this |
break | double | implements | protected | throw |
byte | else | import | public | throws |
case | enum**** | instanceof | return | transient |
catch | extends | int | short | try |
char | final | interface | static | void |
class | finally | long | strictfp** | volatile |
const* | float | native | super | while |
| * | not used | |
| ** | added in 1.2 | |
| *** | added in 1.4 | |
| **** | added in 5.0 |
source for the keywords : http://download.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
5. Identifiers
Identifiers are Case senstive.
Names given for variables , classes and methods
VALID : employeeName, Emp_number, $Emp_salary
INVALID : employee name, #emp, class
"employeeName" method is called the camel method.
6. Data Types
Primitive Data Types:
"employeeName" method is called the camel method.
6. Data Types
Primitive Data Types:
| Data Type | Default Value (for fields) |
|---|---|
| byte | 0 |
| short | 0 |
| int | 0 |
| long | 0L |
| float | 0.0f |
| double | 0.0d |
| char | '\u0000' |
| String (or any object) | null |
| boolean | false |
Refernce Data Types:
Array
Class
Code :
public class tempConv
{
public static void main(String[] args)
{
float celsius = 100;
float fahrenheit ;
//convert to Fahrenheit equivalent
fahrenheit = 32 + ((9 * celsius) / 5 );
System.out.println("celsius temprature");
System.out.println(" " + celsius);
System.out.println("Equivalent Fahrenheit Temperature ");
System.out.println(" " + fahrenheit);
}
}
Preview :
No comments:
Post a Comment