P-Programming in Java - BSC - 3rd Sem - Unit-1
P-Programming in Java - BSC - 3rd Sem - Unit-1
Unit-1 (Practical)
Eclipse IDE
1. Downloading and Installing
● Go to http://www.oracle.com\technetwork\java\javase\downloads\index.html.
● Choose java platform standard edition link. [Latest JDK]
● Download the version that is appropriate for your OS.
● Follow the installation instructions.
● Set the PATH.
● The first thing that you must learn about java is that the name you give to a source file is
very important.
● source file: It is a text file that contains one or more class definitions. The java compiler
requires that a source file use the .java filename extension.
● In java all code must reside inside a class.
● By convention, the name of that class and capitalization[Java is case sensitive] should
match the name of the file that holds the program.
● File name convention makes it easier to maintain and organize your program.
● Filename must be followed by .java extension.
When source code is compiled , each individual class is put into its output file named
after the class and using the .class extension. when you write java filename.class , you
are actually specifying the name of the class that you want to execute. It will
automatically search for a file by that name that has the .class extension. If it finds the
file, It will execute the code contained in the specified class.
2.4. Rules
Example
class test
/* this is a first program */
{
public static void main (String ar[])
{
System.out.println(“welcome to the world of java”);
}
}
There are various ways to accept input from user in java program:
● Using Scanner Class
● Using Streams
● Scanner class belongs to java.util package and has following methods to accept data:
○ Public String next() -> Finds and returns the next complete token from this
scanner.
○ Public boolean nextBoolean() -> Scans the next token of the input into a
boolean value and returns that value.
○ Public byte nextByte() -> Scans the next token of the input as a byte.
○ Public double nextDouble() -> Scans the next token of the input as a double.
○ Public float nextFloat() -> Scans the next token of the input as a float.
○ Public int nextInt() -> Scans the next token of the input as an int.
○ Public String nextLine() -> Advances this scanner past the current line and
returns the input that was skipped.
○ Public long nextLong() -> Scans the next token of the input as a long.
○ Public short nextShort() -> Scans the next token of the input as a short.
● next() can read the input only till the space. It can't read two words separated by
space. Also, next() places the cursor in the same line after reading the input.
● nextLine() reads input including space between the words (that is, it reads till the
end of line \n). Once the input is read, nextLine() positions the cursor in the next
line.
5. Eclipse IDE
5.1. Steps:
Step 1: In the first step, Open your browser and navigate to this
https://www.eclipse.org/ .
Step 2: Then, click on the “Download” button to download Eclipse IDE.
Step 5: Now go to File Explorer and click on “Downloads” after that click on the
“eclipse-inst-jre-win64.exe” file to install Eclipse IDE.
Step 6: Then, click on “Eclipse IDE for Java Developers”.