You will find here a complete Java SE tutorial....
Tuesday, March 22, 2011
Monday, March 21, 2011
Tips for Beginners.....
This post is for the beginners.If you'v just started to learning java then try following tips and enjoy fast and easier java development........
1.Use sun's JavaSE JDK1.6 (available at: http://www.oracle.com/technetwork/java/javase/downloads/index.html)
2.Use Java6 documentation to explore java (available at: http://download.oracle.com/javase/6/docs/api/)
3.Use Netbeans6.9.1 IDE (available at: http://netbeans.org/downloads/index.html)
Now first download these.Then follow following steps......
1.Install JavaSe6 and set the path for javac.
To set path in windows first navigate to C:\Program Files\Java\jdk1.6.0_21\bin and find javac.exe and right click to javac and copy the path.Now go to desktop right click on My Computer then click Properties now click on advanced tab and the click on Environment Variable button the select path and edit then go to end of line and terminate with ";" and then paste the path now click Ok. To check the path write javac on cmd if no error found and list of commands appears means path is set successfully.
2.Install Netbeans and activate the java SE.To do so select new project from file and then select Java Project.
Now your java se in netbeans is activate.
Now to learn how to use netbeans IDE use following tips.......
To do any think in Netbeans we have to make a project.
1.So start working with netbeans.File|New Project.Select Java in categories and and java application in projects.
2.Now then File|New File.Then select Java in categories and Java Class in file type and specify the name.
Now you can make your application here to run use Shift+f6.
For more info to use Netbeans IDE log on to http://netbeans.org/kb/docs/java/quickstart.html.
Creating Executable jar in Java
Jar files are created using the
jar.exe
utility program from JDK. You can make your jar file executable by defining the main class. For thist, you need to create a manifest file. A manifest file is a one-line text file with a "Main-Class" directive. For example:Main-Class: <MainClassName>
This line must end with a newline.
For example---
Step to create executablr jar filr ---
- Create a new folder MyApp and put all the java files.
- Now navigate to this folder from cmd and compile all files.( javac *.java)
- Let we hava Main.java,Class1.java and Class2.java
- Write a manifest.txt file(write the statement ,Main-Class: Main)
- Now run the jar utility(jar cvfm myjar.jar manifest.txt *.class)
- Now test your jar(myjar.jar)
Friday, March 18, 2011
How to create GUI in Java
In last post we have created a GUI. The basic to crate a GUI is consist of following steps.......
1.Create a class that extends JFrame/Jpanel/JApplet.
2.Create a default constructor, and a method void initComp() .In this method in first line set the layout of frame to null.
3.Call the initComp method in constructor, and in next line set the title of main window(this.setTitle("Title");) , then in next line set bounds, then set default close operation to EXIT_ON_CLOSE , then in next line setResizable.
4.Now write main method and write..(new <classname>().setVisible(true);).
5.Now your code is ready to run but this will only show a blank window.
6.To add component on this window firstly declare the objects of components. Now create a method for each component like..void myCompnent(). In this method first create object then set text,set bounds, set visible and then add to this frame. Now if you want to handle any event with this component write the event handler for the componet.
7.Now call these methods in the initComp method.
8.Now the code is complete you can use it.
The main problem in this code is to write event handler which I publish in next post.
1.Create a class that extends JFrame/Jpanel/JApplet.
2.Create a default constructor, and a method void initComp() .In this method in first line set the layout of frame to null.
3.Call the initComp method in constructor, and in next line set the title of main window(this.setTitle("Title");) , then in next line set bounds, then set default close operation to EXIT_ON_CLOSE , then in next line setResizable.
4.Now write main method and write..(new <classname>().setVisible(true);).
5.Now your code is ready to run but this will only show a blank window.
6.To add component on this window firstly declare the objects of components. Now create a method for each component like..void myCompnent(). In this method first create object then set text,set bounds, set visible and then add to this frame. Now if you want to handle any event with this component write the event handler for the componet.
7.Now call these methods in the initComp method.
8.Now the code is complete you can use it.
The main problem in this code is to write event handler which I publish in next post.
Sample GUI class in Java
Java is specially designed for GUI programming. So we here start our chapter with making GUI........
To work with GUI we need a main window to work with. In Java we can use JFrame, JApplet, or JPanel to create GUI. The best practice is to use JFrame.
Here we have a sample class which make a GUI with JFrame....
To work with GUI we need a main window to work with. In Java we can use JFrame, JApplet, or JPanel to create GUI. The best practice is to use JFrame.
Here we have a sample class which make a GUI with JFrame....
Sample GUI class in Java :
// package
package mpc;
// imports
import java.awt.Color;
import javax.swing.*;
import java.awt.event.*;
// class extends jframe or jpanel
public class App extends JFrame{
// constructors
public App() {
initComp();
}
// main method
public static void main(String[] args) {
new App();
}
// initComp method
void initComp() {
this.myBtn();
this.myLbl();
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setBounds(10, 10, 300, 350);
this.setVisible(true);
}
// 1st component’s method
void myBtn() {
btn=new JButton();
btn.setText("Click");
btn.setBounds(5, 5, 100, 25);
btn.setVisible(true);
this.add(btn);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
myBtnActionPerformed(e);}
});
}
// 1st component’s event handler
void myBtnActionPerformed(ActionEvent e){
lbl.setText("Hello.");
}
// 2nd component’s method
void myLbl() {
lbl=new JLabel();
lbl.setText("");
lbl.setBounds(7, 30, 100, 35);
lbl.setVisible(true);
this.add(lbl);
}
// variable and component dec.
JLabel lbl;
JButton btn;
}
Thursday, March 03, 2011
Intro to Java
To start learning java we have to know what java is ----
The technologies that comes with Java can be classified in 5 categories :---
1.Desktop Technologies
2.Distributed TechnologiesThe technologies that comes with Java can be classified in 5 categories :---
1.Desktop Technologies
To work with Desktop Technologies, Java provides Core Java and Advance Java(Java6).The scope of Desktop Technologies are in - Desktop Applications and LAN.
To work with Distributed Technologies Java provides, RMI (Remote Method Invocation). The scope of Distributed Technologies are in - Distributed Storage and Distributed Processing.
To work with Web Technologies, Java Provides Servlets, Java Server Pages (JSP), Java Server Faces (JSF). The scope of Web Technologies are in - Intranet, Extranet, and Internet.
To work with Enterprise Technologies, Java Provides Enterprise Java Beans (EJB), Java Enterprise Edition (JEE). The scope of Enterprise Technologies is in Enterprise applications.
To work with Micro Technologies, Java Provides Java ME.The Scope of Micro Technologies are in - Mobile phones, Pagers, PDAs, Setup Boxes etc.
To work on these technologies Java provides 3 Editions --
1. Java Standard Edition (Java SE)
- For Desktop and Distributed Apps.
- For Web and Enterprise Apps.
- For Micro Technologies
Subscribe to:
Posts (Atom)